Sign in to follow this  
cptrnet

How to get bounding box?

Recommended Posts

I use managed code, but look in the methods of ID3DXMesh for ComputeBoundingBox (maybe?), or you could do it manually with other shapes by simply finding the minimum and maximum extents of the vertices.
Hope that helps

Share this post


Link to post
Share on other sites
Ah - you're here, I assume 2D since you said rectangle as opposed to cuboid, so you would be getting the bounding rectangle. Still, it is all similar in 3D:

If your rectangle is axis-aligned then it is the bounding rectangle, else find the minimum and maximum x and y of its corners and that's your bounding rect. Do the same for a triangle.

Bounding rect of circle has the height and width of the circle's diameter.

Share this post


Link to post
Share on other sites
Thanks for the help. How would I find the min and max. Is there a function or would I have to find out where the vertices are. Sorry for all the questions but I am confused.

Share this post


Link to post
Share on other sites
Firstly tell me how you store your objects, then I'll be able to explain more clearly. Paste your class definitions maybe or describe the variables you hold them in.

Share this post


Link to post
Share on other sites
Well im tryin to plan a class, the base class of Object for rendering. And each subclass. For example the rectangle would be a quad so I would need 4 verts. Then I pass into the constructor four structures of my vertex structure

struct Vertex
{
float x,y,z;
D3DCOLOR color; //OR
float u,v;
};




Then i would create the vertex buffer from those four verts.

1---------2
|---------|
|---------|
|---------|
|---------|
4---------3

I could see getting the x and y pos from the first vertex, oh and by the way im using an orthographic view. and the width would be 1st + 2nd, and the height would be 1st + 4th.

Share this post


Link to post
Share on other sites
So it is 3D, ok. Some psuedo code 4u:

float minX, minY, minZ, maxX, maxY, maxZ
foreach vert in vertices
if (vert.X < minX) minX = vert.X
if (vert.X > maxX) maxX = vert.X
same for y and z
next vert

Hope that helps now

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this