user3736638
user3736638

Reputation: 11

3D math rotating around an arbitrary axis

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!

Upvotes: 0

Views: 436

Answers (1)

Ani
Ani

Reputation: 10896

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

Upvotes: 1

Related Questions