简体   繁体   中英

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!

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

动态AABB

The box stays aligned to the primary axes. If you rotate the box along with the object, you have an O bject A ligned B ounding B ox 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和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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM