1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 15:23:58 +00:00
openmw/apps/opencs/view/render/cameracontroller.hpp

193 lines
4.9 KiB
C++
Raw Normal View History

2016-03-14 04:04:11 +00:00
#ifndef OPENCS_VIEW_CAMERACONTROLLER_H
#define OPENCS_VIEW_CAMERACONTROLLER_H
#include <vector>
2016-03-14 04:04:11 +00:00
#include <QObject>
2016-03-14 04:04:11 +00:00
#include <osg/Vec3d>
namespace osg
{
class Camera;
class Group;
2016-03-14 04:04:11 +00:00
}
namespace CSMPrefs
{
class Shortcut;
}
2016-03-14 04:04:11 +00:00
namespace CSVRender
{
class CameraController : public QObject
2016-03-14 04:04:11 +00:00
{
2022-09-22 18:26:05 +00:00
Q_OBJECT
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
public:
static const osg::Vec3d WorldUp;
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
static const osg::Vec3d LocalUp;
static const osg::Vec3d LocalLeft;
static const osg::Vec3d LocalForward;
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
CameraController(QObject* parent);
~CameraController() override = default;
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
bool isActive() const;
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
osg::Camera* getCamera() const;
double getCameraSensitivity() const;
bool getInverted() const;
double getSecondaryMovementMultiplier() const;
double getWheelMovementMultiplier() const;
2022-09-22 18:26:05 +00:00
void setCamera(osg::Camera*);
void setCameraSensitivity(double value);
void setInverted(bool value);
void setSecondaryMovementMultiplier(double value);
void setWheelMovementMultiplier(double value);
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
// moves the camera to an intelligent position
void setup(osg::Group* root, unsigned int mask, const osg::Vec3d& up);
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
virtual void handleMouseMoveEvent(int x, int y) = 0;
virtual void handleMouseScrollEvent(int x) = 0;
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
virtual void update(double dt) = 0;
2022-09-22 18:26:05 +00:00
protected:
void addShortcut(CSMPrefs::Shortcut* shortcut);
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
private:
bool mActive, mInverted;
double mCameraSensitivity;
double mSecondaryMoveMult;
double mWheelMoveMult;
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
osg::Camera* mCamera;
2022-09-22 18:26:05 +00:00
std::vector<CSMPrefs::Shortcut*> mShortcuts;
2016-03-14 04:04:11 +00:00
};
class FreeCameraController : public CameraController
{
2022-09-22 18:26:05 +00:00
Q_OBJECT
2022-09-22 18:26:05 +00:00
public:
FreeCameraController(QWidget* parent);
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
double getLinearSpeed() const;
double getRotationalSpeed() const;
double getSpeedMultiplier() const;
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
void setLinearSpeed(double value);
void setRotationalSpeed(double value);
void setSpeedMultiplier(double value);
2016-03-26 00:47:18 +00:00
2022-09-22 18:26:05 +00:00
void fixUpAxis(const osg::Vec3d& up);
void unfixUpAxis();
2016-03-26 00:47:18 +00:00
2022-09-22 18:26:05 +00:00
void handleMouseMoveEvent(int x, int y) override;
void handleMouseScrollEvent(int x) override;
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
void update(double dt) override;
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
private:
void yaw(double value);
void pitch(double value);
void roll(double value);
void translate(const osg::Vec3d& offset);
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
void stabilize();
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
bool mLockUpright, mModified;
bool mNaviPrimary, mNaviSecondary;
bool mFast, mFastAlternate;
bool mLeft, mRight, mForward, mBackward, mRollLeft, mRollRight;
osg::Vec3d mUp;
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
double mLinSpeed;
double mRotSpeed;
double mSpeedMult;
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
private slots:
2016-03-26 00:47:18 +00:00
2022-09-22 18:26:05 +00:00
void naviPrimary(bool active);
void naviSecondary(bool active);
void forward(bool active);
void left(bool active);
void backward(bool active);
void right(bool active);
void rollLeft(bool active);
void rollRight(bool active);
void alternateFast(bool active);
void swapSpeedMode();
2016-03-14 04:04:11 +00:00
};
class OrbitCameraController : public CameraController
{
2022-09-22 18:26:05 +00:00
Q_OBJECT
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
public:
OrbitCameraController(QWidget* parent);
2016-03-26 00:47:18 +00:00
2022-09-22 18:26:05 +00:00
osg::Vec3d getCenter() const;
double getOrbitSpeed() const;
double getOrbitSpeedMultiplier() const;
unsigned int getPickingMask() const;
2016-03-26 00:47:18 +00:00
2022-09-22 18:26:05 +00:00
void setCenter(const osg::Vec3d& center);
void setOrbitSpeed(double value);
void setOrbitSpeedMultiplier(double value);
void setPickingMask(unsigned int value);
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
void handleMouseMoveEvent(int x, int y) override;
void handleMouseScrollEvent(int x) override;
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
void update(double dt) override;
2022-09-22 18:26:05 +00:00
/// \brief Flag controller to be re-initialized.
void reset();
2022-09-22 18:26:05 +00:00
void setConstRoll(bool enable);
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
private:
void initialize();
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
void rotateHorizontal(double value);
void rotateVertical(double value);
void roll(double value);
void translate(const osg::Vec3d& offset);
void zoom(double value);
2016-03-14 04:04:11 +00:00
2022-09-22 18:26:05 +00:00
bool mInitialized;
bool mNaviPrimary, mNaviSecondary;
bool mFast, mFastAlternate;
bool mLeft, mRight, mUp, mDown, mRollLeft, mRollRight;
unsigned int mPickingMask;
osg::Vec3d mCenter;
double mDistance;
2016-03-26 00:47:18 +00:00
2022-09-22 18:26:05 +00:00
double mOrbitSpeed;
double mOrbitSpeedMult;
2022-09-22 18:26:05 +00:00
bool mConstRoll;
2022-09-22 18:26:05 +00:00
private slots:
2022-09-22 18:26:05 +00:00
void naviPrimary(bool active);
void naviSecondary(bool active);
void up(bool active);
void left(bool active);
void down(bool active);
void right(bool active);
void rollLeft(bool active);
void rollRight(bool active);
void alternateFast(bool active);
void swapSpeedMode();
2016-03-14 04:04:11 +00:00
};
}
#endif