Jump to content
  • Advertisement
Sign in to follow this  
Anddos

Calculate bounding box with DrawIndexPrimitive

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

i know how to calculate the bounding box for a mesh but what if i am parsing and rendering the model my self and using DrawIndexPrimitive, how do you get the bounding volume?

Share this post


Link to post
Share on other sites
Advertisement

You don't save what kind of a bounding volume you want to determine. Box? Sphere?

 

For a simple axis-aligned box (world transform == identity), you'll need  6 variables, a min and max for each axis. Examine each vertex and compare the three axis components of the position to the current mins and maxes for each axis. Update them when larger/smaller values found.

 

The bounding box will then be comprised of eight points:

 

(minx, miny, minz)

(minx, miny, maxz)

(minx, maxy, minz)

(minx, maxy, maxz)

(maxx, miny, minz)

(maxx, miny, maxz)

(maxx, maxy, minz)

(maxx, maxy, maxz)

 

For a more accurate approach for an axis-aligned box, you'll have to multiply each vertex position by the current world matrix (if world matrix <> identity) before you search for mins and maxes.

 

For an object-aligned box, calculate the box corners as for a "simple" box. Then multiply each corner position by the world matrix.

Edited by Buckeye

Share this post


Link to post
Share on other sites

You don't save what kind of a bounding volume you want to determine. Box? Sphere?

 

For a simple axis-aligned box (world transform == identity), you'll need  6 variables, a min and max for each axis. Examine each vertex and compare the three axis components of the position to the current mins and maxes for each axis. Update them when larger/smaller values found.

 

The bounding box will then be comprised of eight points:

 

(minx, miny, minz)

(minx, miny, maxz)

(minx, maxy, minz)

(minx, maxy, maxz)

(maxx, miny, minz)

(maxx, miny, maxz)

(maxx, maxy, minz)

(maxx, maxy, maxz)

 

For a more accurate approach for an axis-aligned box, you'll have to multiply each vertex position by the current world matrix (if world matrix <> identity) before you search for mins and maxes.

 

For an object-aligned box, calculate the box corners as for a "simple" box. Then multiply each corner position by the world matrix.

 

So this requires locking the vertexbufer and accessing the x,y,z cords of the vertices,i am not sure how todo that 

Share this post


Link to post
Share on other sites

If you've created a vertexbuffer then you should already know how to lock it and access it through a void*. Cast a pointer to your vertex type (CUSTOMVERTEX or similar) using the void* you get from the Lock, and use something like: for(size_t v=0; v < numVertices; v++) { D3DXVECTOR3 pos = myPointer[v].position; ... }

 

Also, if you've created a vertexbuffer with data, why not use the load data itself to do the bounding calcs? Once you have the "simple" bounding box, that info won't change unless you modify the actual vertex positions.

Edited by Buckeye

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!