为什么resultA不等于resultB?我不知道我在做什么错。你能给我一个解释吗?

float alpha = glm::radians(45.0f);

glm::mat4 xRot(glm::vec4(1, 0, 0, 0),
               glm::vec4(0, glm::cos(alpha), glm::sin(alpha), 0),
               glm::vec4(0, -glm::sin(alpha), glm::cos(alpha), 0),
               glm::vec4(0, 0, 0, 1));

glm::mat4 yRot(glm::vec4(glm::cos(alpha), 0, -glm::sin(alpha), 0),
               glm::vec4(0, 1, 0, 0),
               glm::vec4(glm::sin(alpha), 0, glm::cos(alpha), 0),
               glm::vec4(0, 0, 0, 1));

glm::vec4 vec(0, 0, -100, 1);

glm::vec4 resultA(0.0f);
glm::vec4 resultB(0.0f);

resultA = xRot  * yRot * vec; //(-70.7107, 50, -50, 1)
resultB = yRot  * xRot * vec; //(-50, 70.7107, -50, 1)

最佳答案

除了非常特殊的情况外,3D旋转通常不会上下类。从而:

xRot * yRot != yRot * xRot

从本质上讲,您正在做的事情就是证明了这一点:)

看到这里:http://en.wikipedia.org/wiki/Commutative_property

关于c++ - 偏航和俯仰结合在一起,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10075201/

10-17 01:33