I do know its previous, however perhaps any individual else is going through this painful challange:
So a digicam represented solely by:
glm::quat mRotation;
glm::vec3 mPosition;
wants additionally preserve monitor the Pitch and Yaw individually, and apply it one after the other to the primary mRotation quaternion. I have never discovered some other option to restrict a quaternion in any other case.
So all in all of the Camera class should have these members initialized to 0.0f:
glm::quat mRotation;
glm::vec3 mPosition;
float mPitch, mYaw;
During the body by body name, the place you cross within the delta mouse motion values, the Pitch retains monitor the cumulated mouse motion, and thats what you’ll be able to clamp, then cross it into the quaternion as angel axis, right here is how:
void Camera::rotate(const float horizontalMouseMove, const float verticalMouseMove)
{
mPitch -= verticalMouseMove;
mYaw -= horizontalMouseMove;
//TODO: clamp Yaw?
mRotation = glm::angleAxis(mYaw, axis::positiveY);
//clamp Pitch
constexpr float PITCH_LIMIT = 1.4f;//magic quantity, 1.0f is simply too flat to my style
if (mPitch < -PITCH_LIMIT)
{
mPitch = -PITCH_LIMIT;
}
else
if (mPitch > PITCH_LIMIT)
{
mPitch = PITCH_LIMIT;
}
//quaternion multiplication will not be commutative, and we've got YAW rotation already utilized mRotation
mRotation = mRotation * glm::angleAxis(mPitch, getRight());
}