Combining yaw and pitch together

Why is the result not equal to the equal result? I have no idea what I am doing wrong. Can you give me an explanation?

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)

      

+3


source to share


1 answer


3D rotations do not commute at all except in special cases. Thus:

xRot * yRot != yRot * xRot

      



Essentially, what you do with the above proves the point :)

See it here: http://en.wikipedia.org/wiki/Commutative_property

+3


source







All Articles