How to limit the pitch of a camera         Useful snippet to clamp the camera pitch

This is just a code snippet taken from this post on the forums: Link to forum post. Example here uses Example Frame Listener in Ogre/Samples/Common/include

iCamera->yaw(iRotX);
Ogre::Radian originalPitch = iCamera->getOrientation().getPitch();
Ogre::Radian newPitch = Ogre::Math::Abs(iRotY + originalPitch);
 
if(newPitch < Ogre::Radian(Ogre::Math::PI/2 - Offset) || newPitch > Ogre::Radian(Ogre::Math::PI/2 + Offset))
{
     iCamera->pitch(iRotY);         
}


Note: A correct offset value must be around 0.2 - 0.5.


Alias: How_to_limit_the_pitch_of_a_camera