How to get bounding box?

Started by
9 comments, last by cptrnet 19 years ago
Is there a way besides having variables to keep track of where an object is, and how wide and high it is? I want to do this with basic shapes.
If you insist on saying "DUH", try to make a post that makes a little more sense
Advertisement
Do you use a DirectX mesh? People need more detail to help.
BASIC SHAPES, a rectangle, circle, triangle
If you insist on saying "DUH", try to make a post that makes a little more sense
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
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.
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.
If you insist on saying "DUH", try to make a post that makes a little more sense
What if the vertices change and it makes a longer rectangle. How could I find the positions of the vertices.
If you insist on saying "DUH", try to make a post that makes a little more sense
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.
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.
If you insist on saying "DUH", try to make a post that makes a little more sense
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

This topic is closed to new replies.

Advertisement