# How to calculate camera roll...

This topic is 1258 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,

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

I can calculate the yaw and pitch just fine using GLM:

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:

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:

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


How do I also incorporate roll into this?

##### Share on other sites

Build qpitch, qyaw, combine for qPitchYaw which now holds the new camera forward after pitch and yawing, build qroll from this new forward direction, combine qroll with qpitchYaw for qPitchYawRoll the new orientation.

Edited by NumberXaero

##### Share on other sites

Build qpitch, qyaw, combine for qPitchYaw which now holds the new camera forward after pitch and yawing, build qroll from this new forward direction, combine qroll with qpitchYaw for qPitchYawRoll the new orientation.

Thanks, will try this out and report back.