【发布时间】:2012-03-29 20:38:18
【问题描述】:
我要做的是设置可以执行全局和对象空间旋转的函数,但是在理解如何进行对象空间旋转时遇到问题,因为仅将一个点乘以旋转仅适用于全局空间,所以我的想法是在对象空间中建立旋转,然后将其乘以对象矩阵的倒数,据说可以消除对象和全局空间之间的所有多余旋转,所以仍然保持对象空间旋转,但是在全局值中,我这个逻辑是错误的,因为它不起作用,这是我的代码,如果你想检查它,它调用的所有函数都已经过测试:
// build object space rotation
sf::Vector3<float> XMatrix (MultiplyByMatrix(sf::Vector3<float> (cosz,sinz,0)));
sf::Vector3<float> YMatrix (MultiplyByMatrix(sf::Vector3<float> (-sinz,cosz,0)));
sf::Vector3<float> ZMatrix (MultiplyByMatrix(sf::Vector3<float> (0,0,1)));
// build cofactor matrix
sf::Vector3<float> InverseMatrix[3];
CoFactor(InverseMatrix);
// multiply by the transpose of the cofactor matrix(the adjoint), to bring the rotation to world space coordinates
sf::Vector3<float> RelativeXMatrix = MultiplyByTranspose(XMatrix, InverseMatrix[0], InverseMatrix[1], InverseMatrix[2]);
sf::Vector3<float> RelativeYMatrix = MultiplyByTranspose(YMatrix, InverseMatrix[0], InverseMatrix[1], InverseMatrix[2]);
sf::Vector3<float> RelativeZMatrix = MultiplyByTranspose(ZMatrix, InverseMatrix[0], InverseMatrix[1], InverseMatrix[2]);
// perform the rotation from world space
PointsPlusMatrix(RelativeXMatrix, RelativeYMatrix, RelativeZMatrix);
【问题讨论】:
-
您想围绕任意轴或坐标轴之一旋转对象吗?
-
一般3D问题的答案是here。