Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Yaw control causes unwanted rolling while camera is pitched up/down - Quaternions

  1. #1
    Newbie Newbie
    Join Date
    Oct 2018
    Posts
    2

    Yaw control causes unwanted rolling while camera is pitched up/down - Quaternions

    My issue is that when the camera pitches above the horizon line, the camera will roll right when turning/yawing right and roll left when turning left. Below the horizon line, the camera will roll left when turning right and right when turning left.

    The overall effect is the camera following a cosine wave like pattern when the mouse is moving left or right. The amplitude of the wave pattern increases the further above/below the horizon the camera is pointing.

    I'm trying to simulate a plane so I need local control of Roll, Yaw, and Pitch and without gimbal lock so I can't use some other workaround I've found online.

    Is there a simple issue I'm overseeing in my code or this there a bigger problem with my implementation? Any help would be greatly appreciated! I've spent literally half the day on this stinking issue!

    -----

    My code is as follows:

    Pitch and Yaw and Roll are just a flat increment/decrement adjusted for delta time while Orientation is a quaternion that holds the current camera orientation.

    Code :
    	void updateCameraVectors()
    	{
    		glm::quat rotation = glm::quat(glm::vec3(Pitch, Yaw, Roll));
     
    		Orientation = rotation * Orientation;
    		Orientation = glm::normalize(Orientation);
    		glm::mat4 OrientMat = glm::mat4_cast(Orientation);
     
    		glm::mat4 viewMatrix = OrientMat;
    		viewMatrix = glm::transpose(viewMatrix);
     
    		Front = glm::vec3(viewMatrix[2]);
    		Up = glm::vec3(viewMatrix[1]);
    		Right = glm::vec3(viewMatrix[0]);
     
    		Pitch = Yaw = Roll = 0;
    	}
    Last edited by FlamedAce; 10-13-2018 at 12:37 PM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,956
    Quote Originally Posted by FlamedAce View Post
    My issue is that when the camera pitches above the horizon line, the camera will roll right when turning/yawing right and roll left when turning left. Below the horizon line, the camera will roll left when turning right and right when turning left.
    So the yaw is about the local vertical axis, after pitch has been applied.

    If you want them in a different order, you can either change the order in the quat() constructor then apply a suitable 90-degree rotation afterwards, or construct a separate quaternion for each rotation then compose them.

  3. #3
    Newbie Newbie
    Join Date
    Oct 2018
    Posts
    2
    Quote Originally Posted by GClements View Post
    So the yaw is about the local vertical axis, after pitch has been applied.

    If you want them in a different order, you can either change the order in the quat() constructor then apply a suitable 90-degree rotation afterwards, or construct a separate quaternion for each rotation then compose them.
    Hey, that works much better! Thank you!
    Last edited by FlamedAce; 10-13-2018 at 01:17 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •