Thread: Bounding box problems with ID3DXSprite

1. Bounding box problems with ID3DXSprite

I know how to create bounding boxes both in 2D and 3D so thats not my problem.

Problem is that since you do not have any access to or any way to retrieve the actual vertex data inside of ID3DXSprite, it's impossible to make your bounding box fit the new orientation of your object.

Let's say you have a long thin vertical sprite. When it rotates 90 degrees it is obviously larger horizontally than vertically. Yet if you computed the bounding box simply using the width and height of the surface - when it is rotated that bounding box is way off. The ideal way would be to rotate, scale, and translate and re-compute the bounding box. The box will still be axially aligned but it will shrink/warp to fit the new orientation of your object.

Is there any way to do this save for re-computing the vertexes inside of the class manually? These vertexes would not be used for drawing but rather for computation of the new AABB or axially aligned bounding box.

2. Two ideas:
1) it seems like you're worried about doing all of this math all the time, so you might want to do some LOD collision detection. I'm not sure if you have some ideas on how to go about that, but I can give some further suggestions if prompted.

2) Pre compute some of the orientations at different angles...say 0 - 180 at incriments of 10? And of course 180 - 270 can use the same table.

3. cant you just calculate the box based on the sprites dimesions then apply the same scaling and rotations the sprite has to the box?

/me knows nothing of DX

4. No, you can't. It seems like if you translate, rotate the object by certain amounts that you can do that to the bounding box as well and it will work....but it fails miserably. The bounding box ideally should change size to fit the new orientation and the only way to do this correctly is:

1. Translate, rotate, etc., the bounding box by the same values as the object.
2. Re-compute the bounding box based on the new position data.

If you don't recompute it is possible that the bounding box will be much larger or much smaller than the object after the transformation is done.

The only way to understand it is to try it. Create a square and create another square to act as an AABB. Rotate the square and rotate the AABB. Draw both of them - you will soon see what happens. The AABB is no longer an AABB and is now aligned with some other axes. If you want to maintain an AABB but just change its shape and size to fit the object's new orientation - you must recompute left,top,right, and bottom after each transformation.

This is not hard but none of this helps me.

Point I'm making here is that I do not have access to any vertex data. It's all internal to ID3DXSprite so I cannot compute any bounding box once it is translated because I cannot access the new vertex positions.

I can create an initial bounding box by retrieving the width and height from the surface description but that's about it. I guess I will have to store position data for the bounding box and use the D3DX math functions to transform the coords and then re-compute the box after the transformation.

Code:
```struct fRECT
{
float left;
float top;
float right;
float bottom;
};
...
...
...

void CStaticSpriteContainer::Update(float _fTimeDelta)
{
...

fRECT tempRect;

tempRect.right=(float)AABB.left;
tempRect.left=(float)AABB.right;
tempRect.top=(float)AABB.bottom;
tempRect.bottom=(float)AABB.top;

for (int i=0;i<4;i++)
{
float x=Vertexes[i].x;
float y=Vertexes[i].y;
if (x<tempRect.left) tempRect.left=x;
if (y<tempRect.top) tempRect.top=y;
if (x>tempRect.right) tempRect.right=x;
if (y>tempRect.bottom) tempRect.bottom=y;
}
AABB=tempRect;

}```