Advertisement Jump to content
Sign in to follow this  
Pyroclastic Flow

Bounding Box Help

This topic is 3335 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

    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);

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.

Share this post

Link to post
Share on other sites
Why are you creating the box inside your render function? Are you expecting the current OpenGL modelview transform to be applied to the box when you create it?

Share this post

Link to post
Share on other sites
Yes, I'm expecting for the transformation to be applied to the box. I'm fairly new to OpenGL programming so am not doing this correctly?
What I'm trying to accomplish is, basically to draw a box around the 3d model (this one is rotated by xAngle on the y-axis) .... then simply add some checks to see if my camera x,y,z position is within the min and max vectors of the box, if so, there is a collision. I'm going for some very simplistic collision detection.

Any ideas?

Share this post

Link to post
Share on other sites
As to why the box isn't rendering with the correct transform, I couldn't tell you, because I don't know what:
// then add box to array

As for collision detection, aside perhaps from a few esoteric GPU-based algorithms, that's completely unrelated to OpenGL.

The OpenGL transforms are only applied to geometry that goes through the OpenGL pipeline; they have no effect on any client-side geometry, or on any geometric data or bounding volumes you might have laying around.

In other words, you have to do the collision detection yourself (or use a third-party library of some sort). In this case, if you're just looking for a simple Boolean point-to-oriented-box test, here's how you'd do it:

1. Transform the camera position into the local space of the model using the inverse of the model transform.

2. Perform a point-to-axis-aligned-box test.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!