0

I have recently been experimenting with quaternion rotations, and I have made a class that stores the rotation as a quaternion. And I then want to take this quaternion and simply add rotation in the eulerY axis. This is what I came up with:

glm::vec3 tmp = glm::degrees(glm::eulerAngles(GetTransform()->rotation));
tmp.y += rotY;
GetTransform()->rotation = glm::quat(glm::radians(tmp));

And everything is working, however when the eulerY axis gets to 90 degrees, and I want to go above that, it does not let me. the X and Z axis keep changing from 0 to 180 or -180 and then back very quickly. And sometimes, when I then change rotY to a negative number (I try to lower the eulerY axis) then it does the exact oposite (the eulerY axis gets increased), suddenly ignoring the 90 degrees barrier. Any ideas what might be happening ?

I have tried different ways of how to do this, tried to add/remove the glm::radians or glm::degrees functions, but still nothing. I do not even know where this is even caused, it makes me so confused that I literally left my projects for a month out of frustration

JacobDev
  • 65
  • 6
  • Have you heard of [gimbal lock](https://en.wikipedia.org/wiki/Gimbal_lock)? I would recommend not using euler angles at all, and instead making a rotation quaternion like [this](https://stackoverflow.com/questions/4436764/rotating-a-quaternion-on-1-axis). – Nelfeal Jul 15 '23 at 15:03
  • For the Euler angles to be well-defined the intermediate one (about Y in your case) has to lie in a range of length PI, usually [-Pi/2,Pi/2]. It looks like you are sending it outside that range. If it is exactly +-Pi/2 you will have ambiguity in the other two angles (gimbal lock), although I don't think that is your main problem here. I'd stick with either quaternions or the rotation matrix alone, without trying to cross-convert to Euler angles. – lastchance Jul 15 '23 at 17:13
  • @Nelfeal if you read the post, you would know I am using a quaternion. – JacobDev Jul 17 '23 at 13:25
  • @JacobDev Not sure what you mean with the condescending tone. You are clearly going from quaternion to euler angles and then back to quaternions. I suggested not doing that. – Nelfeal Jul 17 '23 at 13:46

0 Answers0