0
\$\begingroup\$

I have a short Question: I'm trying to add Collisions in my 3D DirectX9 game and my World is Stored in a LPDIRECT3DVERTEXBUFFER9 and LPDIRECT3DINDEXBUFFER9 and Rendered per DrawIndexedPrimitive. My Player is a LPD3DXMESH loaded from a .X file. Now I want to detect Collisions between the two! How can I do that? After some research I could only find Collisions between Bounding Boxes and/or Rays!

Apologise my bad English, I'm German! :-) Hope for fast reply!

\$\endgroup\$
  • \$\begingroup\$ If there's no additional structure to your world (ie. it's not a terrain heightmap, or decomposed into collision primitives like boxes, spheres, capsules...) then you're basically working with a triangle soup. All you can really do is check for collisions against each triangle individually, usually using some kind of spatial partitioning structure to help narrow down which triangles are close enough to consider. Obviously this gets expensive if you have many triangles, so it's highly recommended to have a collision representation that's lower-resolution than the one you use for rendering. \$\endgroup\$ – DMGregory Nov 16 '15 at 17:49
1
\$\begingroup\$

Fundamentally what you need to find is OBB-Triangle intersection. Some searches yield on answer here:

Moving OBB vs. triangle intersection test

The complexity of your case comes in to play in that your vertex data is stored in a D3D buffer - not an ideal format for collision detection. You will have to lock the vertex buffer each time you test. Depending on whether it is triangle strips or triangle lists you will need to pull out the vertices to test against them. Furthermore, to make collision detection against triangles fast enough you need a spatial data structure to wrap it. I wrote about that here: When would a mesh collider be better than primitive colliders

As for the player, you will need to lock the mesh buffer and find the bounding box. The problem you will have is that, if the player is being posed by animation, simply locking the player buffer may not give you the correct vertices as they are posed on the GPU. You'll need to do something more sophisticated to get a useful AABB.

To be performant, you might want to duplicate the triangle vertices in main ram in a format that is best suited for collision detection.

\$\endgroup\$
  • \$\begingroup\$ 1. Thanks for the fast Answer! 2. Wich data format would you suggest to use for the World (Heightmap)? \$\endgroup\$ – Anonymous Anonymous Nov 17 '15 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.