1
\$\begingroup\$

I'm adding basic ray casting and collision detection for my game, and also adding bounding volumes and collision meshes.

The ray is cast in world space and each mesh's node can track its world transformation. Considering I want to test for intersection between a ray and bounding volume and also bounding volume with other bounding volume, in what space should I perform the intersection test?

Scenarios that I have in mind:

  • Transform ray into object's local space, perform test, then inverse transform the resulted point.
  • Transform bounding volume into world space and perform it there, or should I always keep bounding volumes in world space?
  • Perform bounding/bounding test in world space or one of the objects?

Do things change much between static and dynamic collision regarding used spaces?

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

It's generally both easier and faster to convert rays into the object's local space and do the test. It's either 1 tranformation on the ray or N transformations of N vertices into world space, and for even a single triangle 1 will be less than N. For objects like OBBs it's also much easier to just treat it like an AABB in object space when doing ray collisions.

For object-object intersections it's still easier and faster generally to convert into one of the object's spaces. For OBB-OBB tests, it turns into an AABB-OBB test. For arbitrary meshes, it means you only need to transform one set of vertices instead of both.

For physics resolution after collisions, it doesn't matter much which space you're in since you should be computing relative values. e.g. if A collides into B, the collision will determine the resulting impulse (or penetration fixup or bounce velocity or whatever you're computing) in some vector relative to B. Just reverse the transformation on the impulse vector after calculating it if you need it in world space.

\$\endgroup\$
3
  • \$\begingroup\$ I think it's a very good answer that totally makes sense... on a separate issue are bounding volumes for physics usually the same for visibility determination or it just depends on the type of game world and the complexity/accuracy of the collision detection ? \$\endgroup\$
    – concept3d
    Commented Oct 11, 2013 at 20:32
  • 1
    \$\begingroup\$ Yeah, it depends, but they're usually separate in my experience once you go past the indie/hobby level. Graphics is usually dealing with very specialized culling structures (like portals or heightmaps with occlusion volumes or so on) while physics is often handed over to a middlware library like Havok that has its own opaque, internal structures you couldn't access or make use of for graphics even if you wanted to. \$\endgroup\$ Commented Oct 11, 2013 at 22:03
  • \$\begingroup\$ really thanks that was very useful. I hope one day I will go past the hobby level :) \$\endgroup\$
    – concept3d
    Commented Oct 11, 2013 at 22:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .