2016-03-14 04:04:11 +00:00
|
|
|
#ifndef OPENCS_VIEW_CAMERACONTROLLER_H
|
|
|
|
#define OPENCS_VIEW_CAMERACONTROLLER_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <osg/Vec3d>
|
|
|
|
|
|
|
|
class QKeyEvent;
|
|
|
|
|
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Camera;
|
2016-04-02 17:36:12 +00:00
|
|
|
class Group;
|
2016-03-14 04:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace CSVRender
|
|
|
|
{
|
|
|
|
class CameraController
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2016-03-18 17:57:48 +00:00
|
|
|
static const osg::Vec3d WorldUp;
|
|
|
|
|
2016-03-14 04:04:11 +00:00
|
|
|
static const osg::Vec3d LocalUp;
|
|
|
|
static const osg::Vec3d LocalLeft;
|
|
|
|
static const osg::Vec3d LocalForward;
|
|
|
|
|
|
|
|
CameraController();
|
|
|
|
virtual ~CameraController();
|
|
|
|
|
|
|
|
bool isActive() const;
|
|
|
|
|
|
|
|
osg::Camera* getCamera() const;
|
2016-03-26 00:47:18 +00:00
|
|
|
double getCameraSensitivity() const;
|
2016-04-04 22:42:57 +00:00
|
|
|
bool getInverted() const;
|
2016-03-26 00:47:18 +00:00
|
|
|
double getSecondaryMovementMultiplier() const;
|
|
|
|
double getWheelMovementMultiplier() const;
|
2016-03-14 04:04:11 +00:00
|
|
|
|
|
|
|
void setCamera(osg::Camera*);
|
2016-03-26 00:47:18 +00:00
|
|
|
void setCameraSensitivity(double value);
|
2016-04-04 22:42:57 +00:00
|
|
|
void setInverted(bool value);
|
2016-03-26 00:47:18 +00:00
|
|
|
void setSecondaryMovementMultiplier(double value);
|
|
|
|
void setWheelMovementMultiplier(double value);
|
2016-03-14 04:04:11 +00:00
|
|
|
|
2016-03-18 18:02:24 +00:00
|
|
|
// moves the camera to an intelligent position
|
2016-04-02 17:36:12 +00:00
|
|
|
void setup(osg::Group* root, unsigned int mask, const osg::Vec3d& up);
|
2016-03-18 18:02:24 +00:00
|
|
|
|
2016-03-14 04:04:11 +00:00
|
|
|
virtual bool handleKeyEvent(QKeyEvent* event, bool pressed) = 0;
|
|
|
|
virtual bool handleMouseMoveEvent(std::string mode, int x, int y) = 0;
|
|
|
|
|
|
|
|
virtual void update(double dt) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual void onActivate(){}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-04-04 22:42:57 +00:00
|
|
|
bool mActive, mInverted;
|
2016-03-26 00:47:18 +00:00
|
|
|
double mCameraSensitivity;
|
|
|
|
double mSecondaryMoveMult;
|
|
|
|
double mWheelMoveMult;
|
2016-03-14 04:04:11 +00:00
|
|
|
|
|
|
|
osg::Camera* mCamera;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FreeCameraController : public CameraController
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
FreeCameraController();
|
|
|
|
|
2016-03-26 00:47:18 +00:00
|
|
|
double getLinearSpeed() const;
|
|
|
|
double getRotationalSpeed() const;
|
|
|
|
double getSpeedMultiplier() const;
|
|
|
|
|
|
|
|
void setLinearSpeed(double value);
|
|
|
|
void setRotationalSpeed(double value);
|
|
|
|
void setSpeedMultiplier(double value);
|
|
|
|
|
2016-03-14 04:04:11 +00:00
|
|
|
void fixUpAxis(const osg::Vec3d& up);
|
|
|
|
void unfixUpAxis();
|
|
|
|
|
|
|
|
bool handleKeyEvent(QKeyEvent* event, bool pressed);
|
|
|
|
bool handleMouseMoveEvent(std::string mode, int x, int y);
|
|
|
|
|
|
|
|
void update(double dt);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void yaw(double value);
|
|
|
|
void pitch(double value);
|
|
|
|
void roll(double value);
|
|
|
|
void translate(const osg::Vec3d& offset);
|
|
|
|
|
|
|
|
void stabilize();
|
|
|
|
|
2016-04-03 21:26:34 +00:00
|
|
|
bool mLockUpright, mModified;
|
2016-03-14 04:04:11 +00:00
|
|
|
bool mFast, mLeft, mRight, mForward, mBackward, mRollLeft, mRollRight;
|
|
|
|
osg::Vec3d mUp;
|
2016-03-26 00:47:18 +00:00
|
|
|
|
|
|
|
double mLinSpeed;
|
|
|
|
double mRotSpeed;
|
|
|
|
double mSpeedMult;
|
2016-03-14 04:04:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class OrbitCameraController : public CameraController
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2016-03-18 20:06:35 +00:00
|
|
|
OrbitCameraController();
|
2016-03-14 04:04:11 +00:00
|
|
|
|
2016-04-03 20:30:50 +00:00
|
|
|
osg::Vec3d getCenter() const;
|
2016-03-26 00:47:18 +00:00
|
|
|
double getOrbitSpeed() const;
|
|
|
|
double getOrbitSpeedMultiplier() const;
|
2016-04-02 17:59:57 +00:00
|
|
|
unsigned int getPickingMask() const;
|
2016-03-26 00:47:18 +00:00
|
|
|
|
2016-04-03 20:30:50 +00:00
|
|
|
void setCenter(const osg::Vec3d& center);
|
2016-03-26 00:47:18 +00:00
|
|
|
void setOrbitSpeed(double value);
|
|
|
|
void setOrbitSpeedMultiplier(double value);
|
2016-04-02 17:59:57 +00:00
|
|
|
void setPickingMask(unsigned int value);
|
2016-03-26 00:47:18 +00:00
|
|
|
|
2016-03-14 04:04:11 +00:00
|
|
|
bool handleKeyEvent(QKeyEvent* event, bool pressed);
|
|
|
|
bool handleMouseMoveEvent(std::string mode, int x, int y);
|
|
|
|
|
|
|
|
void update(double dt);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void onActivate();
|
|
|
|
|
|
|
|
void initialize();
|
|
|
|
|
|
|
|
void rotateHorizontal(double value);
|
|
|
|
void rotateVertical(double value);
|
|
|
|
void roll(double value);
|
|
|
|
void translate(const osg::Vec3d& offset);
|
|
|
|
void zoom(double value);
|
|
|
|
|
|
|
|
bool mInitialized;
|
|
|
|
bool mFast, mLeft, mRight, mUp, mDown, mRollLeft, mRollRight;
|
2016-04-02 17:59:57 +00:00
|
|
|
unsigned int mPickingMask;
|
2016-03-14 04:04:11 +00:00
|
|
|
osg::Vec3d mCenter;
|
2016-03-18 20:56:40 +00:00
|
|
|
double mDistance;
|
2016-03-26 00:47:18 +00:00
|
|
|
|
|
|
|
double mOrbitSpeed;
|
|
|
|
double mOrbitSpeedMult;
|
2016-03-14 04:04:11 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|