C++ Direct 3D bounding boxes! Need a lil help

Discuss programming topics for any language, any source base. If it is programming related but doesn't fit in one of the below categories, it goes here.
Post Reply
boxrick
Posts: 5
Joined: Tue Jan 20, 2009 12:15 pm

C++ Direct 3D bounding boxes! Need a lil help

Post by boxrick »

Im currently creating a 3d world using direct x. I am working on collisions, I use the D3D command
D3DXComputeBoundingBox()
Then input all the vertices etc to calculate my bounding box, and put them into multiple D3DXVECTOR3 to hold all the values of the corners of my bounding box.

I then simplify it to make collision handling less CPU intensive by making it so the bounding boxes are all on the same axis.... ( This step is pretty irrelevant to my question )

So now i have my bounding box with a number of x y and z co ordinates.

This is where im struggling, i need to convert my bounding box into world space so it knows where it is in the world. Currently i do this by each entity holding its own position in the world, it knows where it is and when it comes to render it is rendered at that specific position. Each time a specific entity moves the bounding box is updated with the object. So if it is resized the bounding box is resized the same amount, if the object moves the position of the bounding box is also moved the same amount.

Am i doing this the correct way, i feel my process is awefully ineffecient. Because with every object movement i have to update a box. Can someone point me in a more sensible direction or am i doing this the correct way?
Willem
Posts: 73
Joined: Wed Jan 23, 2008 10:58 am
Contact:

Post by Willem »

You're basically doing it correctly but you could do it more efficiently if you wanted to. For example:

1) Don't store all the corners of the bounding box. You really only need to know the extent of the box on each axis. Combine that with the entities location and you can reconstruct a box without much trouble.

2) Don't bother updating the box's location each time the entity moves - only update it when you actually need to reference it. When you go to collide with it, quickly grab the entity location and the bounding box extents and whip up a bounding box object. This will be quick since it's just going to be a bunch of add operations.

Just a few ideas...
boxrick
Posts: 5
Joined: Tue Jan 20, 2009 12:15 pm

Post by boxrick »

cheers for the reply, very much appreciated!
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Post by mh »

Yup, that's pretty much the way Quake does it. :D

Bounding spheres can be more efficient, all you need is the center point and the radius, then compute a distance and see if it's less than the radius (you can avoid a sqrt if you store radius squared). They might not be as good a fit as a box for some objects, but if you can get away with them they should be fine.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
Post Reply