Results 1 to 3 of 3

Thread: Bounding Box Help

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2009
    Posts
    5

    Bounding Box Help

    So I need to add Bounding Boxes to the 3D models that I imported into my game. Is there an easy way to do this without manually having to manually add my coordinates?

    So far I have:

    Code :
     
    struct Box {
        Vector3 min;
        Vector3 max;
    }
     
    ...
     
    void CreateBox (float minx, float miny, float minz, float maxx, float maxy, float maxz) {
        Box b;
        b.min.x = minx;
        b.min.y = miny;
        b.min.z = minz;
     
        b.max.x = maxx;
        b.max.y = maxy;
        b.max.z = maxz;
     
        // then add box to array
    }
     
    void drawScene()
    // ... render my scene
     
    glPushMatrix()
        glTransformf(200, 200, 200);
        glScalef(5.0, 5,0, 5.0);
        glRotate(xAngle, 0.0, 1.0, 0.0);
        drawModel(model); // draws the 3d model
        CreateBox(200, 0, 200, 400, 300, 400);
    glPopMatrix();

    Reason I ask is, even after creating the box as mentioned above, the box isn't rotated by xAngle like the 3D model. So I cant really add collision detection, as the box does not fit around the 3d model (which is also a square).

    Hope that makes sense.

    Thanks guys.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,655

    Re: Bounding Box Help

    Quote Originally Posted by Pyroclastic Flow
    So I need to add Bounding Boxes to the 3D models that I imported into my game. Is there an easy way to do this without manually having to manually add my coordinates?
    Huh? Add your coordinates? That doesn't make any sense.

    I don't understand what it is you're doing that you don't want to have to do, ...and why.

    Reason I ask is, even after creating the box as mentioned above, the box isn't rotated by xAngle like the 3D model. So I cant really add collision detection, as the box does not fit around the 3d model (which is also a square).
    You're talking apples and oranges here. In the first paragraph, you're talking about rendering the box. In this latter paragraph you're talking about doing collision detection with the box.

    There are a number of ways to do collision detection. But assuming you're doing it on the CPU, a bounding box you compute (in whatever space, object space, or world space, or whatever) is perfectly valid to use for collision detection.

    In the case of an object-space bounding box, you just need to transform your collision vector into object space before you intersection-test against the box.

    In the case of a world-space bounding box, you just use the collision vector in world space.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    9

    Re: Bounding Box Help


    It sounds like what you are trying to do is create a box that encompasses the object, but whose coordinates are expressed in the inertial (not rotated/translated/etc.) frame.

    While this makes collision detection easy, (since all your boxes are in inertial frame and comparing coordinates is easy), calculating the inertial coordinates from a rotated/translated frame requires some math. (This Math that is done for us by OpenGL in rendering.)

    Google Euler angles or Rotation matrix for (basic) info about these issues.
    Any decent graduate text in rigid body dynamics should also talk extensively to these topics.

    David

Similar Threads

  1. bounding box , how?
    By burrows111 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-09-2010, 02:36 PM
  2. How to creat the bounding box ?
    By HaVyThoai in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-03-2008, 11:38 AM
  3. how to get the bounding box...
    By jyoung77 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-06-2007, 02:30 AM
  4. Bounding box
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-17-2003, 01:40 PM
  5. How do I determinate bounding box???
    By vladxky in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 11-23-2001, 10:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean