how to rotate all objects by their own centers and then translate them to the real position (it isn#39;t working)(如何按自己的中心旋转所有对象,然后将它们转换到真实位置(它不起作用))
问题描述
有什么办法让所有与原点中心(vector3(0.0f,0.0f,0.0f))不对齐的物体都绕着自己的中心轴旋转?
What is the way to make all the objects that are not aligned with the origin center (vector3(0.0f,0.0f,0.0f)) , rotate about its own central axis?
伪代码中的问题:
vector3 vector3 objectCenter = (10,5,0); // current object center
vector3 vector3 objectPosition = (40,5,0); // Place to translate the object
vector3 objectRotation; = 45.0f;
matrix.loadIdentity ();
matrix.translate (objectCenter);
//apply transformations
matrix.rotateX (objectRotation);
matrix.translate (-objectCenter);
//itś work correctly until here
//when i try to translate the object to the real position, the rotation is incorrect.
matrix.translate (objectPosition);
我使用 C++、glm(用于矩阵管理)和 OpenGL.
I use C++, glm (to matrix manage) and OpenGL.
推荐答案
如果你想将对象本地旋转到它自己的坐标系,那么这样做:
if you want to rotate object locally to its own coordinate system then do this:
M=inverse(inverse(M)*rotation_matrix);
M
是你的对象变换矩阵rotation_matrix
是任意旋转(glRotate()
)inverse
是计算逆矩阵的函数,您可以使用我的 逆矩阵计算 或这个围绕 C++ 中的 LCS x (lrotx) 实现旋转(在答案的底部)M
is your object transform matrixrotation_matrix
is any rotation (glRotate()
)inverse
is function that computes the inverse matrix you can use mine inverse matrix computation or this rotation around LCS x (lrotx) implementation in C++ (at the bottom of the answer)+z
轴为正向运动+x
为右,-x 为左+y
向上,-y 向下+z
axis as forward direction movement+x
as right, -x as left+y
as up and -y as down
[edit1] 更多关于 M 和它所代表的坐标系的对象之间的关系
看这里:变换矩阵解剖
M
原点通常是对象的中间(或旋转运动中心点).M
的轴通常与对象对齐,例如在飞机中,X
轴通常是飞行方向.我比较习惯:
M
origin is usually the middle of object (or point which is center of rotation movements). Axises of M
are usually aligned with object for example in airplanes the X
axis is usually the fly direction. I am more used to:
pith,yaw,roll
然后是围绕 x,y,z
这篇关于如何按自己的中心旋转所有对象,然后将它们转换到真实位置(它不起作用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何按自己的中心旋转所有对象,然后将它们转换到真实位置(它不起作用)
- 静态初始化顺序失败 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- C++ 协变模板 2021-01-01
- 近似搜索的工作原理 2021-01-01