|
|
@ -27,7 +27,6 @@ namespace CSVRender
|
|
|
|
|
|
|
|
|
|
|
|
CameraController::CameraController()
|
|
|
|
CameraController::CameraController()
|
|
|
|
: mActive(false)
|
|
|
|
: mActive(false)
|
|
|
|
, mModified(false)
|
|
|
|
|
|
|
|
, mCameraSensitivity(1/650.f)
|
|
|
|
, mCameraSensitivity(1/650.f)
|
|
|
|
, mSecondaryMoveMult(50)
|
|
|
|
, mSecondaryMoveMult(50)
|
|
|
|
, mWheelMoveMult(8)
|
|
|
|
, mWheelMoveMult(8)
|
|
|
@ -44,11 +43,6 @@ namespace CSVRender
|
|
|
|
return mActive;
|
|
|
|
return mActive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CameraController::isModified() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return mModified;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::Camera* CameraController::getCamera() const
|
|
|
|
osg::Camera* CameraController::getCamera() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return mCamera;
|
|
|
|
return mCamera;
|
|
|
@ -129,22 +123,13 @@ namespace CSVRender
|
|
|
|
getCamera()->setViewMatrixAsLookAt(eye, center, up);
|
|
|
|
getCamera()->setViewMatrixAsLookAt(eye, center, up);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CameraController::setModified()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mModified = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CameraController::resetModified()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mModified = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
Free Camera Controller
|
|
|
|
Free Camera Controller
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
FreeCameraController::FreeCameraController()
|
|
|
|
FreeCameraController::FreeCameraController()
|
|
|
|
: mLockUpright(false)
|
|
|
|
: mLockUpright(false)
|
|
|
|
|
|
|
|
, mModified(false)
|
|
|
|
, mFast(false)
|
|
|
|
, mFast(false)
|
|
|
|
, mLeft(false)
|
|
|
|
, mLeft(false)
|
|
|
|
, mRight(false)
|
|
|
|
, mRight(false)
|
|
|
@ -193,7 +178,7 @@ namespace CSVRender
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mLockUpright = true;
|
|
|
|
mLockUpright = true;
|
|
|
|
mUp = up;
|
|
|
|
mUp = up;
|
|
|
|
setModified();
|
|
|
|
mModified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FreeCameraController::unfixUpAxis()
|
|
|
|
void FreeCameraController::unfixUpAxis()
|
|
|
@ -209,37 +194,30 @@ namespace CSVRender
|
|
|
|
if (event->key() == Qt::Key_Q)
|
|
|
|
if (event->key() == Qt::Key_Q)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mRollLeft = pressed;
|
|
|
|
mRollLeft = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_E)
|
|
|
|
else if (event->key() == Qt::Key_E)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mRollRight = pressed;
|
|
|
|
mRollRight = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_A)
|
|
|
|
else if (event->key() == Qt::Key_A)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mLeft = pressed;
|
|
|
|
mLeft = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_D)
|
|
|
|
else if (event->key() == Qt::Key_D)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mRight = pressed;
|
|
|
|
mRight = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_W)
|
|
|
|
else if (event->key() == Qt::Key_W)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mForward = pressed;
|
|
|
|
mForward = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_S)
|
|
|
|
else if (event->key() == Qt::Key_S)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mBackward = pressed;
|
|
|
|
mBackward = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_Shift)
|
|
|
|
else if (event->key() == Qt::Key_Shift)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mFast = pressed;
|
|
|
|
mFast = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -258,7 +236,6 @@ namespace CSVRender
|
|
|
|
{
|
|
|
|
{
|
|
|
|
yaw(x * getCameraSensitivity());
|
|
|
|
yaw(x * getCameraSensitivity());
|
|
|
|
pitch(y * getCameraSensitivity());
|
|
|
|
pitch(y * getCameraSensitivity());
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == "s-navi")
|
|
|
|
else if (mode == "s-navi")
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -267,7 +244,6 @@ namespace CSVRender
|
|
|
|
movement += LocalUp * y * getSecondaryMovementMultiplier();
|
|
|
|
movement += LocalUp * y * getSecondaryMovementMultiplier();
|
|
|
|
|
|
|
|
|
|
|
|
translate(movement);
|
|
|
|
translate(movement);
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == "t-navi")
|
|
|
|
else if (mode == "t-navi")
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -308,35 +284,38 @@ namespace CSVRender
|
|
|
|
if (mRollRight)
|
|
|
|
if (mRollRight)
|
|
|
|
roll(rotDist);
|
|
|
|
roll(rotDist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(isModified())
|
|
|
|
else if(mModified)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
stabilize();
|
|
|
|
stabilize();
|
|
|
|
|
|
|
|
mModified = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Normalize the matrix to counter drift
|
|
|
|
// Normalize the matrix to counter drift
|
|
|
|
getCamera()->getViewMatrix().orthoNormal(getCamera()->getViewMatrix());
|
|
|
|
getCamera()->getViewMatrix().orthoNormal(getCamera()->getViewMatrix());
|
|
|
|
|
|
|
|
|
|
|
|
resetModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FreeCameraController::yaw(double value)
|
|
|
|
void FreeCameraController::yaw(double value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
getCamera()->getViewMatrix() *= osg::Matrixd::rotate(value, LocalUp);
|
|
|
|
getCamera()->getViewMatrix() *= osg::Matrixd::rotate(value, LocalUp);
|
|
|
|
|
|
|
|
mModified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FreeCameraController::pitch(double value)
|
|
|
|
void FreeCameraController::pitch(double value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
getCamera()->getViewMatrix() *= osg::Matrixd::rotate(value, LocalLeft);
|
|
|
|
getCamera()->getViewMatrix() *= osg::Matrixd::rotate(value, LocalLeft);
|
|
|
|
|
|
|
|
mModified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FreeCameraController::roll(double value)
|
|
|
|
void FreeCameraController::roll(double value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
getCamera()->getViewMatrix() *= osg::Matrixd::rotate(value, LocalForward);
|
|
|
|
getCamera()->getViewMatrix() *= osg::Matrixd::rotate(value, LocalForward);
|
|
|
|
|
|
|
|
mModified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FreeCameraController::translate(const osg::Vec3d& offset)
|
|
|
|
void FreeCameraController::translate(const osg::Vec3d& offset)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
getCamera()->getViewMatrix() *= osg::Matrixd::translate(offset);
|
|
|
|
getCamera()->getViewMatrix() *= osg::Matrixd::translate(offset);
|
|
|
|
|
|
|
|
mModified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FreeCameraController::stabilize()
|
|
|
|
void FreeCameraController::stabilize()
|
|
|
@ -426,37 +405,30 @@ namespace CSVRender
|
|
|
|
if (event->key() == Qt::Key_Q)
|
|
|
|
if (event->key() == Qt::Key_Q)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mRollLeft = pressed;
|
|
|
|
mRollLeft = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_E)
|
|
|
|
else if (event->key() == Qt::Key_E)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mRollRight = pressed;
|
|
|
|
mRollRight = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_A)
|
|
|
|
else if (event->key() == Qt::Key_A)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mLeft = pressed;
|
|
|
|
mLeft = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_D)
|
|
|
|
else if (event->key() == Qt::Key_D)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mRight = pressed;
|
|
|
|
mRight = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_W)
|
|
|
|
else if (event->key() == Qt::Key_W)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mUp = pressed;
|
|
|
|
mUp = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_S)
|
|
|
|
else if (event->key() == Qt::Key_S)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mDown = pressed;
|
|
|
|
mDown = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_Shift)
|
|
|
|
else if (event->key() == Qt::Key_Shift)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mFast = pressed;
|
|
|
|
mFast = pressed;
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -478,7 +450,6 @@ namespace CSVRender
|
|
|
|
{
|
|
|
|
{
|
|
|
|
rotateHorizontal(x * getCameraSensitivity());
|
|
|
|
rotateHorizontal(x * getCameraSensitivity());
|
|
|
|
rotateVertical(-y * getCameraSensitivity());
|
|
|
|
rotateVertical(-y * getCameraSensitivity());
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == "s-navi")
|
|
|
|
else if (mode == "s-navi")
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -487,7 +458,6 @@ namespace CSVRender
|
|
|
|
movement += LocalUp * -y * getSecondaryMovementMultiplier();
|
|
|
|
movement += LocalUp * -y * getSecondaryMovementMultiplier();
|
|
|
|
|
|
|
|
|
|
|
|
translate(movement);
|
|
|
|
translate(movement);
|
|
|
|
setModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == "t-navi")
|
|
|
|
else if (mode == "t-navi")
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -530,8 +500,6 @@ namespace CSVRender
|
|
|
|
|
|
|
|
|
|
|
|
// Normalize the matrix to counter drift
|
|
|
|
// Normalize the matrix to counter drift
|
|
|
|
getCamera()->getViewMatrix().orthoNormal(getCamera()->getViewMatrix());
|
|
|
|
getCamera()->getViewMatrix().orthoNormal(getCamera()->getViewMatrix());
|
|
|
|
|
|
|
|
|
|
|
|
resetModified();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OrbitCameraController::onActivate()
|
|
|
|
void OrbitCameraController::onActivate()
|
|
|
|