简体   繁体   English

绕任意轴旋转的3D数学

[英]3D math rotating around an arbitrary axis

I'm working with modern opengl and I need some help with rotating around an arbitrary axis. 我正在使用现代的opengl,我需要一些围绕任意轴旋转的帮助。 so basically when i rotate the 3D model I also need to rotate its collision box. 因此基本上,当我旋转3D模型时,我还需要旋转其碰撞盒。 glm handles all the rotation math for the model itself I just need to be able to rotate the collision box. glm处理模型本身的所有旋转数学,我只需要能够旋转碰撞盒即可。 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 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. 凹凸:将碰撞盒的8个点存储为vec3点,以便可以旋转它们。 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. 当你有谁边框的对象被定义为顶点的最小值和最大值,你有什么是A X是一个 ligned ounding盒。 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). 如果与对象一起旋转中,你有一个 bject ligned ounding牛BO,除非对象顶点修改你并不需要更新它的尺寸(或者它的缩放)。

Here's an example of an AABB vs an OOBB. 这是AABB与OOBB的示例。

AABB和OOBB

An AABB is more efficient to intersect, but OOBBs are easier to maintain for dynamic objects. AABB相交效率更高,但是OOBB对于动态对象更易于维护。 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 PS:感谢GIF,取材于此处的视频

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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