Index | FAQ | Search | Memberlist | Usergroups | Profile | Log in to check your private messages | Log in | Register

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

| Inside3d Forums Forum Index -> General Programming

View previous topic :: View next topic
Author | Message
--- | ---
boxrick Joined: 20 Jan 2009 Posts: 5 |

Posted: Tue Jan 20, 2009 12:19 pm Post subject: C++ Direct 3D bounding boxes! Need a lil help |

Im currently creating a 3d world using direct x. I am working on collisions, I use the D3D command

Quote:
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?

Back to top |

Willem Joined: 23 Jan 2008 Posts: 73 |

Posted: Tue Jan 20, 2009 12:27 pm Post subject: |

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...
_________________
www.wantonhubris.com

Back to top |

boxrick Joined: 20 Jan 2009 Posts: 5 |

Posted: Tue Jan 20, 2009 2:08 pm Post subject: |

cheers for the reply, very much appreciated!

Back to top |

mh Joined: 12 Jan 2008 Posts: 909 |

Posted: Tue Jan 20, 2009 4:37 pm Post subject: |

Yup, that's pretty much the way Quake does it. 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.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines

Back to top |

Display posts from previous:

| Inside3d Forums Forum Index -> General Programming | All times are GMT
Page 1 of 1

Jump to:

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2004 phpBB Group