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:



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.

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.

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