Thread: Bounding box problems with ID3DXSprite

  1. #1
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607

    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. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    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. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    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. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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;
     
    }
    Last edited by VirtualAce; 12-16-2004 at 01:51 PM.

  5. #5
    ---
    Join Date
    May 2004
    Posts
    1,379
    >>To answer Prelude's question

    Prelude asked a question?

  6. #6
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Yup, she visited him in a dream, wearing...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Collision Detection Problems
    By Dark_Phoenix in forum Game Programming
    Replies: 1
    Last Post: 12-17-2006, 03:25 PM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  3. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  4. List box horizontal bar
    By cfriend in forum Windows Programming
    Replies: 1
    Last Post: 09-12-2004, 03:52 PM
  5. Linking error!
    By m712 in forum C++ Programming
    Replies: 2
    Last Post: 12-08-2002, 11:24 PM