Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Daniel Benmergui

Rectangle in 3D collision test

This topic is 6489 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

Does anyone know any good tutorials on how to compute if two rectangles in 3D (i mean, like a cube but with rectangular shape) intersects? It is enough with knowing if the collided, no need to compute the actual intersection... Thanks! Daniel.

Share this post


Link to post
Share on other sites
Advertisement
      
bool hit(all the arguments..)
{
if (
((x1-xs1<x2-xs2 && x1+xs1>x2-xs2) || (x1-xs1<x2+xs2 && x1+xs1>x2+xs2) || (x1-xs1>x2-xs2 && x1+xs1<x2+xs2)) &&
((y1-ys1<y2-ys2 && y1+ys1>y2-ys2) || (y1-ys1<y2+ys2 && y1+ys1>y2+ys2) || (y1-ys1>y2-ys2 && y1+ys1<y2+ys2)) &&
((z1-zs1<z2-zs2 && z1+zs1>z2-zs2) || (z1-zs1<z2+zs2 && z1+zs1>z2+zs2) || (z1-zs1>z2-zs2 && z1+zs1<z2+zs2)) &&
) return true;
return false;
}


y1=box 1, y coordinate to the center
ys1=box 1, "y size" (height)
x2=box 2, x coordinate to the center
etc.

Didn't try it and just wrote it.. So if it works might be a bit questionable . Of course the algo only works for axis-aligned "3d-rectangles" but I guess that's what your're looking for anyway.

Edited by - Hans on January 15, 2001 4:47:51 PM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!