   [MDX] Bounding Box Collision C#
  I'm making a very simpler game engine in managed DirectX.I've done rendering, and moving the camera, now i need to implement a collision sytem.I'm making a Fps shooter, and need a fast, collision system. I've been surfing the web, but even though I've seen a lot of tutorials, but I'we stil not got it all.First, how do I searchg trough all the verticles I a model, so I can store the max and min values. Secondly, how do I make a OBB boundingbox? (one that's aligned to the rotation of the model)   
  In my opinion a good idea would be to use a physics library and let it worry about the collisions etc.There are C# wrappers out there for most (if not all) the common physics libraries. I have personally used this one in the past and been quite content [smile]If you download the PhysX SDK you can look at the source code provided with the samples and it is quite easy to convert them into MDX.With regards to getting the min and max from a model, that should be a case of simply iterating through all the vertices and updating your max and min if the current vertex is greater than you max or smaller than your min. For a bounding box it would probably be easiest to calculate an AABB and then transform it as you move the camera.All the best,ViLiO   ;  Take a look at ODE.NET. I have extensively used it and it's great.   ;  Is this what you were looking for?class BoundingBoxInformation{    Vector3 lowerLeft;    Vector3 upperRight;    float width, height, depth;    public BoundingBoxInformation(Mesh mesh)    {   int strideSize = VertexInformation.GetFormatSize(mesh.VertexFormat);   GraphicsStream data = null;   try {  // Lock the vertex buffer  data = mesh.LockVertexBuffer(LockFlags.ReadOnly);  // Now compute the bounding box  Geometry.ComputeBoundingBox( data, mesh.NumberVertices, strideSize, out lowerLeft, out upperRight);   } finally {  // Make sure to unlock the vertex buffer  if (data != null) { mesh.UnlockVertexBuffer();  }   }   width = upperRight.X - lowerLeft.X;   height = upperRight.Y - lowerLeft.Y;   depth = upperRight.Z - lowerLeft.Z;    }    public float Width    {   get { return width; }    }    public float Height    {   get { return height; }    }    public float Depth    {   get { return depth; }    }}Then, you could just make a Mesh.Box which takes the width, height and depth and then transform it using the same matrix as on your model to get "one that's aligned to the rotation of the model". Not sure if this is what you wanted.   ;Quote:Original post by shrtIs this what you were looking for?Yes, thank you, i've been boggeled by this question in many days, thanks!The next thing n my list now, is to detect collision between OOB boxes, that sounds realy hard, since i cant go for the normal method:if (box1.x < box2.xmax && box1.x > box2.min){return true;}Any tips, or hints?;if (box1.max.x < box2.min.x)return false;if (box1.max.y < box2.min.y)return false;if (box1.max.z < box2.min.z)return false;if (box1.min.x > box2.max.x)return false;if (box1.min.y > box2.max.y)return false;if (box1.min.z > box2.max.z)return false;return true;This will return true if 2 boxes are intersecting, false if not.[Edited by - CadeF on June 8, 2006 11:43:28 PM];  No because of this:http://img125.imageshack.us/img125/5429/kllision4pf.jpgOne of the verticles on the red box is inside al the max and min values og the pink box, it would trigger a collision, though the two boxes clearly aren't intersecting.   ;  Sorry, I thought you meant normal bounding boxes. Look into the seperation axis theorem, it works for convex objects only.   