Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: How to calculate camera roll...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2014

    How to calculate camera roll...


    I have hopefully a simple question regarding calculating the roll of a camera.

    I can calculate the yaw and pitch just fine using GLM:
    Code :
    CameraAxis = glm::cross(DirectionOfWhereCameraIsFacing, DirectionOfUpForPerson);
    CameraQuatPitch = glm::angleAxis(CurrentCameraViewingSettings.Pitch, CameraAxis);
    CameraQuatYaw = glm::angleAxis(CurrentCameraViewingSettings.Yaw, DirectionOfUpForPerson);

    The first problem is calculating the roll of the camera. I tried this but my math is off as this doesn't work:

    Code :
    CameraQuatRoll = glm::angleAxis(CurrentCameraViewingSettings.Roll, CameraAxis);

    This seems to me like another pitch calculation.

    The second piece is accuratly combining the changed roll to find out where the camera is finally facing.

    I do this for the yaw and pitch above by doing the following below:

    Code :
    CameraQuatBothPitchAndYaw = glm::cross(CameraQuatPitch, CameraQuatYaw);
    CameraQuatBothPitchAndYaw = glm::normalize(CameraQuatBothPitchAndYaw);
    DirectionOfWhereCameraIsFacing = glm::rotate(CameraQuatBothPitchAndYaw, DirectionOfWhereCameraIsFacing);

    How do I also incorporate roll into this?

    Thank you for your time.

  2. #2
    Member Regular Contributor
    Join Date
    Aug 2008
    Your 3 axes that you should be rotating around are DirectionOfWhereCameraIsFacing (roll), DirectionOfUpForPerson (yaw) & CameraAxis (pitch),so you need to change CameraAxis to DirectionOfWhereCameraIsFacing in your roll calculation.

    I believe to combine the 3 rotations you just multiply the quaternions:
    Code :
    CombinedRotation = CameraQuatYaw * (CameraQuatPitch* CameraQuatRoll);// or is it roll*(pitch*yaw)?

    Depending on what you're after, you might actually want to roll/pitch/yaw around (1,0,0), (0,1,0) & (0,0,1) axes instead.
    Last edited by Dan Bartlett; 08-12-2014 at 03:37 AM.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Apr 2014
    Thanks, I will give this a shot.

Posting Permissions

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