Add more customization.

openmw-39
Aesylwinn 9 years ago
parent 3a676fc456
commit 3c83128abc

@ -19,14 +19,12 @@ namespace CSVRender
const osg::Vec3d CameraController::LocalLeft = osg::Vec3d(1, 0, 0); const osg::Vec3d CameraController::LocalLeft = osg::Vec3d(1, 0, 0);
const osg::Vec3d CameraController::LocalForward = osg::Vec3d(0, 0, 1); const osg::Vec3d CameraController::LocalForward = osg::Vec3d(0, 0, 1);
const double CameraController::LinearSpeed = 1000;
const double CameraController::RotationalSpeed = osg::PI / 2.f;
const double CameraController::SpeedMultiplier = 8;
CameraController::CameraController() CameraController::CameraController()
: mActive(false) : mActive(false)
, mModified(false) , mModified(false)
, mMouseScalar(-1/700.f) , mCameraSensitivity(-1/700.f)
, mSecondaryMoveMult(50)
, mWheelMoveMult(8)
, mCamera(NULL) , mCamera(NULL)
{ {
} }
@ -50,9 +48,19 @@ namespace CSVRender
return mCamera; return mCamera;
} }
double CameraController::getMouseScalar() const double CameraController::getCameraSensitivity() const
{
return mCameraSensitivity;
}
double CameraController::getSecondaryMovementMultiplier() const
{
return mSecondaryMoveMult;
}
double CameraController::getWheelMovementMultiplier() const
{ {
return mMouseScalar; return mWheelMoveMult;
} }
void CameraController::setCamera(osg::Camera* camera) void CameraController::setCamera(osg::Camera* camera)
@ -64,9 +72,19 @@ namespace CSVRender
onActivate(); onActivate();
} }
void CameraController::setMouseScalar(double value) void CameraController::setCameraSensitivity(double value)
{
mCameraSensitivity = value;
}
void CameraController::setSecondaryMovementMultiplier(double value)
{ {
mMouseScalar = value; mSecondaryMoveMult = value;
}
void CameraController::setWheelMovementMultiplier(double value)
{
mWheelMoveMult = value;
} }
void CameraController::setSceneBounds(const osg::BoundingBox& bounds, const osg::Vec3d& up) void CameraController::setSceneBounds(const osg::BoundingBox& bounds, const osg::Vec3d& up)
@ -101,7 +119,40 @@ namespace CSVRender
, mRollLeft(false) , mRollLeft(false)
, mRollRight(false) , mRollRight(false)
, mUp(LocalUp) , mUp(LocalUp)
, mLinSpeed(1000)
, mRotSpeed(osg::PI / 2)
, mSpeedMult(8)
{
}
double FreeCameraController::getLinearSpeed() const
{ {
return mLinSpeed;
}
double FreeCameraController::getRotationalSpeed() const
{
return mRotSpeed;
}
double FreeCameraController::getSpeedMultiplier() const
{
return mSpeedMult;
}
void FreeCameraController::setLinearSpeed(double value)
{
mLinSpeed = value;
}
void FreeCameraController::setRotationalSpeed(double value)
{
mRotSpeed = value;
}
void FreeCameraController::setSpeedMultiplier(double value)
{
mSpeedMult = value;
} }
void FreeCameraController::fixUpAxis(const osg::Vec3d& up) void FreeCameraController::fixUpAxis(const osg::Vec3d& up)
@ -171,18 +222,22 @@ namespace CSVRender
if (mode == "p-navi") if (mode == "p-navi")
{ {
yaw(x * getMouseScalar()); yaw(x * getCameraSensitivity());
pitch(y * getMouseScalar()); pitch(y * getCameraSensitivity());
setModified(); setModified();
} }
else if (mode == "s-navi") else if (mode == "s-navi")
{ {
translate(LocalLeft * x + LocalUp * -y); osg::Vec3d movement;
movement += LocalLeft * -x * getSecondaryMovementMultiplier();
movement += LocalUp * y * getSecondaryMovementMultiplier();
translate(movement);
setModified(); setModified();
} }
else if (mode == "t-navi") else if (mode == "t-navi")
{ {
translate(LocalForward * x * (mFast ? SpeedMultiplier : 1)); translate(LocalForward * x * (mFast ? getWheelMovementMultiplier() : 1));
} }
else else
{ {
@ -197,11 +252,11 @@ namespace CSVRender
if (!isActive()) if (!isActive())
return; return;
double linDist = LinearSpeed * dt; double linDist = mLinSpeed * dt;
double rotDist = RotationalSpeed * dt; double rotDist = mRotSpeed * dt;
if (mFast) if (mFast)
linDist *= SpeedMultiplier; linDist *= mSpeedMult;
if (mLeft) if (mLeft)
translate(LocalLeft * linDist); translate(LocalLeft * linDist);
@ -272,7 +327,29 @@ namespace CSVRender
, mRollRight(false) , mRollRight(false)
, mCenter(0,0,0) , mCenter(0,0,0)
, mDistance(0) , mDistance(0)
, mOrbitSpeed(osg::PI / 4)
, mOrbitSpeedMult(4)
{
}
double OrbitCameraController::getOrbitSpeed() const
{
return mOrbitSpeed;
}
double OrbitCameraController::getOrbitSpeedMultiplier() const
{ {
return mOrbitSpeedMult;
}
void OrbitCameraController::setOrbitSpeed(double value)
{
mOrbitSpeed = value;
}
void OrbitCameraController::setOrbitSpeedMultiplier(double value)
{
mOrbitSpeedMult = value;
} }
bool OrbitCameraController::handleKeyEvent(QKeyEvent* event, bool pressed) bool OrbitCameraController::handleKeyEvent(QKeyEvent* event, bool pressed)
@ -336,18 +413,22 @@ namespace CSVRender
if (mode == "p-navi") if (mode == "p-navi")
{ {
rotateHorizontal(x * getMouseScalar()); rotateHorizontal(x * getCameraSensitivity());
rotateVertical(-y * getMouseScalar()); rotateVertical(-y * getCameraSensitivity());
setModified(); setModified();
} }
else if (mode == "s-navi") else if (mode == "s-navi")
{ {
translate(LocalLeft * x + LocalUp * -y); osg::Vec3d movement;
movement += LocalLeft * x * getSecondaryMovementMultiplier();
movement += LocalUp * -y * getSecondaryMovementMultiplier();
translate(movement);
setModified(); setModified();
} }
else if (mode == "t-navi") else if (mode == "t-navi")
{ {
zoom(-x * (mFast ? SpeedMultiplier : 1)); zoom(-x * (mFast ? getWheelMovementMultiplier() : 1));
} }
else else
{ {
@ -365,10 +446,10 @@ namespace CSVRender
if (!mInitialized) if (!mInitialized)
initialize(); initialize();
double rotDist = RotationalSpeed * dt; double rotDist = mOrbitSpeed * dt;
if (mFast) if (mFast)
rotDist *= SpeedMultiplier; rotDist *= mOrbitSpeedMult;
if (mLeft) if (mLeft)
rotateHorizontal(-rotDist); rotateHorizontal(-rotDist);

@ -26,10 +26,6 @@ namespace CSVRender
static const osg::Vec3d LocalLeft; static const osg::Vec3d LocalLeft;
static const osg::Vec3d LocalForward; static const osg::Vec3d LocalForward;
static const double LinearSpeed;
static const double RotationalSpeed;
static const double SpeedMultiplier;
CameraController(); CameraController();
virtual ~CameraController(); virtual ~CameraController();
@ -37,10 +33,14 @@ namespace CSVRender
bool isModified() const; bool isModified() const;
osg::Camera* getCamera() const; osg::Camera* getCamera() const;
double getMouseScalar() const; double getCameraSensitivity() const;
double getSecondaryMovementMultiplier() const;
double getWheelMovementMultiplier() const;
void setCamera(osg::Camera*); void setCamera(osg::Camera*);
void setMouseScalar(double value); void setCameraSensitivity(double value);
void setSecondaryMovementMultiplier(double value);
void setWheelMovementMultiplier(double value);
// moves the camera to an intelligent position // moves the camera to an intelligent position
void setSceneBounds(const osg::BoundingBox& bounds, const osg::Vec3d& up); void setSceneBounds(const osg::BoundingBox& bounds, const osg::Vec3d& up);
@ -60,7 +60,9 @@ namespace CSVRender
private: private:
bool mActive, mModified; bool mActive, mModified;
double mMouseScalar; double mCameraSensitivity;
double mSecondaryMoveMult;
double mWheelMoveMult;
osg::Camera* mCamera; osg::Camera* mCamera;
}; };
@ -71,6 +73,14 @@ namespace CSVRender
FreeCameraController(); FreeCameraController();
double getLinearSpeed() const;
double getRotationalSpeed() const;
double getSpeedMultiplier() const;
void setLinearSpeed(double value);
void setRotationalSpeed(double value);
void setSpeedMultiplier(double value);
void fixUpAxis(const osg::Vec3d& up); void fixUpAxis(const osg::Vec3d& up);
void unfixUpAxis(); void unfixUpAxis();
@ -91,6 +101,10 @@ namespace CSVRender
bool mLockUpright; bool mLockUpright;
bool mFast, mLeft, mRight, mForward, mBackward, mRollLeft, mRollRight; bool mFast, mLeft, mRight, mForward, mBackward, mRollLeft, mRollRight;
osg::Vec3d mUp; osg::Vec3d mUp;
double mLinSpeed;
double mRotSpeed;
double mSpeedMult;
}; };
class OrbitCameraController : public CameraController class OrbitCameraController : public CameraController
@ -99,6 +113,12 @@ namespace CSVRender
OrbitCameraController(); OrbitCameraController();
double getOrbitSpeed() const;
double getOrbitSpeedMultiplier() const;
void setOrbitSpeed(double value);
void setOrbitSpeedMultiplier(double value);
bool handleKeyEvent(QKeyEvent* event, bool pressed); bool handleKeyEvent(QKeyEvent* event, bool pressed);
bool handleMouseMoveEvent(std::string mode, int x, int y); bool handleMouseMoveEvent(std::string mode, int x, int y);
@ -120,6 +140,9 @@ namespace CSVRender
bool mFast, mLeft, mRight, mUp, mDown, mRollLeft, mRollRight; bool mFast, mLeft, mRight, mUp, mDown, mRollLeft, mRollRight;
osg::Vec3d mCenter; osg::Vec3d mCenter;
double mDistance; double mDistance;
double mOrbitSpeed;
double mOrbitSpeedMult;
}; };
} }

Loading…
Cancel
Save