Add pitch constraint for first person camera.

openmw-39
Aesylwinn 9 years ago
parent e07687ee01
commit b111febfc9

@ -1,5 +1,7 @@
#include "cameracontroller.hpp"
#include <cmath>
#include <QKeyEvent>
#include <osg/BoundingBox>
@ -314,6 +316,24 @@ namespace CSVRender
void FreeCameraController::pitch(double value)
{
const double Constraint = osg::PI / 2 - 0.1;
if (mLockUpright)
{
osg::Vec3d eye, center, up;
getCamera()->getViewMatrixAsLookAt(eye, center, up);
osg::Vec3d forward = center - eye;
osg::Vec3d left = up ^ forward;
double pitchAngle = std::acos(up * mUp);
if ((mUp ^ up) * left < 0)
pitchAngle *= -1;
if (std::abs(pitchAngle + value) > Constraint)
value = (pitchAngle > 0 ? 1 : -1) * Constraint - pitchAngle;
}
getCamera()->getViewMatrix() *= osg::Matrixd::rotate(value, LocalLeft);
mModified = true;
}

Loading…
Cancel
Save