Jump to content
  • Advertisement
Sign in to follow this  
billythekid844

collision detection/mesh transform/etc

This topic is 5410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok before I begin I want to say that I have already looked all over the place on this forum, Google, DirectX docs, and a couple books and have not found an answer. That doesnt mean I havent missed it, just that I am sick of looking. Anyway... I am doing collision detection using the bounding box method. Now what I do is load my level which is a mesh with 180 objects in it. And I traverse through the frame hierarchy and extract all the object meshs, and calculate each transformation matrix. And that part is fine. Also my actual collision detection calculations seem to be fine. But computing the bounding box is the problem. Now I do have the code correct for computing the bounding box itself, but the min and max I get back are wrong. I think the reason my min and max are wrong is because I need to transform the entire object mesh into world coordinates before I compute the bounding box. But Im having trouble figuring out how to do that. And Im using DX9 C#, but a C++ example would work too. And I can provide all sorts of code if needed.

Share this post


Link to post
Share on other sites
Advertisement
What kind of collsion detection are you looking for
100% efficeient or more a rought draft one.

If you are making a 3D engine. I suggest you to start with the rought one. After its done go with the BB one. It will save computing time.

At the start of your app, you can use the ComputeBoundingSphere Method on all your mesh. Store the radius and center of each models.

on each frame test (im not including quandtree like optimisation)

for each model
if distance from center <= modela.radius + modelb.radius then
perform deeper collsion testing
end if
end each

here is my guess for the deeper collison detection.

you take an arbitary model. modelA ( is the player for example).

for each vertex of modelA BB
find if it collide a BB on modelB
//here you need to know where the normal point at
calculate the dot from the pt to the 6 plane of the BB if all the result are < 0 then its inside the there is an accurate intersection
end for each

Share this post


Link to post
Share on other sites
Yes this is for a 3D engine and I just want basic collision detection for now. But I think you missed my question, so I will try to explain better.

I am not asking how to do the math for bounding box collision detection or any other method, I already have that done and working I think. This is my function for that:

private bool IsColliding(Vector3 minA, Vector3 maxA, Vector3 minB, Vector3 maxB)
{
if(maxA.X < minB.X) return false;
if(minA.X > maxB.X) return false;
if(maxA.Y < minB.Y) return false;
if(minA.Y > maxB.Y) return false;
if(maxA.Z < minB.Z) return false;
if(minA.Z > maxB.Z) return false;

return true;
}

I am asking how do you convert the object mesh's coordinates into world coordinates? As in how do I physically change all the vertices in the mesh to be in world coordinates? Because I think thats the reason I am getting incorrect values back from ComputeBoundingBox().

Share this post


Link to post
Share on other sites
You don't, instead you convert the bounding shape into world co-ordinates. So you could work out a axis aligned bounding box in model space at load time. Then when testing transform the corners of the box by the world matrix. This then gives you an oriented bounding box in world space. Collisions between them can be painful so you can take a further step and convert the OOBB into an ABB simply by taking min max values. This process is explained on my Internet site (under collisions) and I am sure in other places.

Share this post


Link to post
Share on other sites
Cant you put more code im intresting too look deeper.

[Edited by - thoue on September 23, 2004 1:48:06 PM]

Share this post


Link to post
Share on other sites
Thanks a lot, that helped though I still have a bug somewhere. Maybe its with my transformation function which is:

private Vector3 ObjectToWorldCoord(Matrix world, Matrix transform, Vector3 vector)
{
Matrix matrix = Matrix.Identity;
matrix.M41 = vector.X;
matrix.M42 = vector.Y;
matrix.M43 = vector.Z;
matrix = matrix * world;
matrix = matrix * transform;
return new Vector3(matrix.M41, matrix.M42, matrix.M43);
}

world = world matrix
transform = frame transformation matrix

So I use this function instead of D3DXVec3TransformCoord() because I need to also use the frame.TransformationMatrix to help position each mesh within the larger level mesh. Does that look right or am I missing something?

P.S. Thats an excellent site!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!