0
votes

I'm working with modern opengl and I need some help with rotating around an arbitrary axis. so basically when i rotate the 3D model I also need to rotate its collision box. glm handles all the rotation math for the model itself I just need to be able to rotate the collision box. I tried learning that, but i'm having trouble, can anyone help with this? https://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm

if (model->collision_box->aX.x >= this->collision_box->ax.x && this->collision_box->aX.x > model->collision_box->ax.x){
    if (model->collision_box->aY.y >= this->collision_box->ay.y && this->collision_box->aY.y > model->collision_box->ay.y){
        if (model->collision_box->aZ.z >= this->collision_box->az.z && this->collision_box->aZ.z > model->collision_box->az.z){
            mx = 0;//stop movement
            my = 0;
            mz = 0;
        }
    }
}            

bump: btw the 8 points of the collision box are stored as vec3 points so they can be rotated. It's not just min/max. Also if I used convex collision boxes I still need to rotate around an arbitrary axis!

1
If you are using an AABB as a collision box, then it doesn't rotate by definition, you need to use OBB or sacrifice some precision and use a bounding sphere - concept3d
@concept3d why wouldnt the collision box be able to rotate. its defined by Ax ax aY ay aZ az. if i applied a rotation to it it would change the location of those points. For example if i rotated a rectangle model by 90 i would need to rotate the collision box 90 degrees aswell or they would not match up - user3736638
can you show the code for your bounding box ? - concept3d
@concept3d added, it checks that its between the maximum and minimum of each axis of the object - user3736638
given what you described you don't need to rotate. - concept3d

1 Answers

1
votes

When you have an object who's bounding box is defined as the min and max of its vertices, what you have is an Axis Aligned Bounding Box. When this updates as the object moves or rotates like so:

Dynamic AABB

The box stays aligned to the primary axes. If you rotate the box along with the object, you have an Object Aligned Bounding Box and you don't need to update its dimension unless the objects vertices are modified (or it's scaled).

Here's an example of an AABB vs an OOBB.

AABB vs OOBB

An AABB is more efficient to intersect, but OOBBs are easier to maintain for dynamic objects. For first-order tests, you can also use spherical bounding volumes (which are rotation invariant).

PS: Credit for the GIF, taken from the video here