2013-04-29 12:50:40 +00:00
|
|
|
#ifndef GAME_MWRENDER_CAMERA_H
|
|
|
|
#define GAME_MWRENDER_CAMERA_H
|
2011-01-08 14:11:37 +00:00
|
|
|
|
2012-07-03 13:32:38 +00:00
|
|
|
#include <string>
|
2011-02-10 11:56:19 +00:00
|
|
|
|
2015-05-21 21:54:39 +00:00
|
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <osg/Vec3>
|
2015-06-01 13:34:46 +00:00
|
|
|
#include <osg/Vec3d>
|
2015-05-21 21:54:39 +00:00
|
|
|
|
2013-04-29 06:44:44 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
|
2015-05-21 21:54:39 +00:00
|
|
|
namespace osg
|
2012-08-12 14:35:35 +00:00
|
|
|
{
|
2011-01-08 14:11:37 +00:00
|
|
|
class Camera;
|
2015-05-21 21:54:39 +00:00
|
|
|
class NodeCallback;
|
|
|
|
class Node;
|
2011-01-08 14:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWRender
|
|
|
|
{
|
2012-08-14 16:33:29 +00:00
|
|
|
class NpcAnimation;
|
2013-04-29 06:44:44 +00:00
|
|
|
|
2013-04-29 12:50:40 +00:00
|
|
|
/// \brief Camera control
|
|
|
|
class Camera
|
2011-01-08 14:11:37 +00:00
|
|
|
{
|
2020-06-21 23:54:08 +00:00
|
|
|
private:
|
2012-08-13 22:36:18 +00:00
|
|
|
struct CamData {
|
|
|
|
float pitch, yaw, offset;
|
|
|
|
};
|
|
|
|
|
2013-04-29 06:44:44 +00:00
|
|
|
MWWorld::Ptr mTrackingPtr;
|
2015-05-21 21:54:39 +00:00
|
|
|
osg::ref_ptr<const osg::Node> mTrackingNode;
|
2015-11-09 16:30:11 +00:00
|
|
|
float mHeightScale;
|
2012-08-12 11:50:37 +00:00
|
|
|
|
2015-05-21 21:54:39 +00:00
|
|
|
osg::ref_ptr<osg::Camera> mCamera;
|
2011-01-08 14:11:37 +00:00
|
|
|
|
2012-08-14 16:33:29 +00:00
|
|
|
NpcAnimation *mAnimation;
|
|
|
|
|
2012-08-08 20:15:52 +00:00
|
|
|
bool mFirstPersonView;
|
2012-08-12 11:50:37 +00:00
|
|
|
bool mPreviewMode;
|
2013-07-29 14:43:16 +00:00
|
|
|
float mNearest;
|
|
|
|
float mFurthest;
|
|
|
|
bool mIsNearest;
|
2012-08-12 11:50:37 +00:00
|
|
|
|
2012-08-14 10:37:48 +00:00
|
|
|
struct {
|
2013-04-27 08:24:36 +00:00
|
|
|
bool enabled, allowed;
|
2012-08-14 10:37:48 +00:00
|
|
|
} mVanity;
|
|
|
|
|
2020-06-21 23:54:08 +00:00
|
|
|
float mHeight, mBaseCameraDistance;
|
2012-08-13 22:36:18 +00:00
|
|
|
CamData mMainCam, mPreviewCam;
|
2012-08-12 14:35:35 +00:00
|
|
|
|
2013-12-26 23:36:06 +00:00
|
|
|
bool mVanityToggleQueued;
|
2016-06-09 23:39:37 +00:00
|
|
|
bool mVanityToggleQueuedValue;
|
2013-12-26 23:36:06 +00:00
|
|
|
bool mViewModeToggleQueued;
|
|
|
|
|
2015-05-21 21:54:39 +00:00
|
|
|
float mCameraDistance;
|
|
|
|
|
2020-06-21 23:54:08 +00:00
|
|
|
osg::Vec3d mFocalPointAdjustment;
|
2020-06-19 20:03:11 +00:00
|
|
|
osg::Vec2d mFocalPointCurrentOffset;
|
2020-07-11 12:21:18 +00:00
|
|
|
osg::Vec2d mFocalPointTargetOffset;
|
2020-06-19 20:03:11 +00:00
|
|
|
float mFocalPointTransitionSpeed;
|
|
|
|
|
2020-06-22 17:26:37 +00:00
|
|
|
float mSmoothedSpeed;
|
2020-07-11 12:21:18 +00:00
|
|
|
bool mDynamicCameraDistanceEnabled;
|
|
|
|
bool mShowCrosshairInThirdPersonMode;
|
2020-06-22 17:26:37 +00:00
|
|
|
|
2020-06-19 20:03:11 +00:00
|
|
|
void updateFocalPointOffset(float duration);
|
2020-06-21 23:54:08 +00:00
|
|
|
float getCameraDistanceCorrection() const;
|
|
|
|
|
2015-05-21 21:54:39 +00:00
|
|
|
osg::ref_ptr<osg::NodeCallback> mUpdateCallback;
|
2014-10-01 16:55:35 +00:00
|
|
|
|
2012-08-08 20:15:52 +00:00
|
|
|
public:
|
2015-05-21 21:54:39 +00:00
|
|
|
Camera(osg::Camera* camera);
|
2013-04-29 12:50:40 +00:00
|
|
|
~Camera();
|
2012-08-08 20:15:52 +00:00
|
|
|
|
2015-05-21 21:54:39 +00:00
|
|
|
MWWorld::Ptr getTrackingPtr() const;
|
|
|
|
|
2020-07-11 12:21:18 +00:00
|
|
|
void setFocalPointTransitionSpeed(float v) { mFocalPointTransitionSpeed = v; }
|
|
|
|
void setFocalPointTargetOffset(osg::Vec2d v) { mFocalPointTargetOffset = v; }
|
|
|
|
void enableDynamicCameraDistance(bool v) { mDynamicCameraDistanceEnabled = v; }
|
|
|
|
void enableCrosshairInThirdPersonMode(bool v) { mShowCrosshairInThirdPersonMode = v; }
|
2020-06-19 20:03:11 +00:00
|
|
|
|
2015-05-21 21:54:39 +00:00
|
|
|
/// Update the view matrix of \a cam
|
|
|
|
void updateCamera(osg::Camera* cam);
|
|
|
|
|
2013-05-17 20:53:43 +00:00
|
|
|
/// Reset to defaults
|
|
|
|
void reset();
|
|
|
|
|
2013-04-29 12:50:40 +00:00
|
|
|
/// Set where the camera is looking at. Uses Morrowind (euler) angles
|
2012-08-11 09:23:54 +00:00
|
|
|
/// \param rot Rotation angles in radians
|
2015-05-21 21:54:39 +00:00
|
|
|
void rotateCamera(float pitch, float yaw, bool adjust);
|
2012-11-05 19:48:07 +00:00
|
|
|
|
2020-06-21 23:54:08 +00:00
|
|
|
float getYaw() const;
|
2012-11-05 19:48:07 +00:00
|
|
|
void setYaw(float angle);
|
2011-01-08 14:11:37 +00:00
|
|
|
|
2020-06-21 23:54:08 +00:00
|
|
|
float getPitch() const;
|
2012-11-05 19:48:07 +00:00
|
|
|
void setPitch(float angle);
|
|
|
|
|
2012-08-11 08:13:16 +00:00
|
|
|
/// Attach camera to object
|
2015-05-21 21:54:39 +00:00
|
|
|
void attachTo(const MWWorld::Ptr &);
|
2011-02-10 11:56:19 +00:00
|
|
|
|
2014-06-05 15:21:02 +00:00
|
|
|
/// @param Force view mode switch, even if currently not allowed by the animation.
|
|
|
|
void toggleViewMode(bool force=false);
|
2012-08-12 11:50:37 +00:00
|
|
|
|
2013-04-27 08:24:36 +00:00
|
|
|
bool toggleVanityMode(bool enable);
|
2012-08-14 10:37:48 +00:00
|
|
|
void allowVanityMode(bool allow);
|
2012-08-12 11:50:37 +00:00
|
|
|
|
2013-12-26 23:36:06 +00:00
|
|
|
/// @note this may be ignored if an important animation is currently playing
|
2012-08-13 22:36:18 +00:00
|
|
|
void togglePreviewMode(bool enable);
|
2012-05-30 13:52:39 +00:00
|
|
|
|
2013-10-02 09:16:52 +00:00
|
|
|
/// \brief Lowers the camera for sneak.
|
2014-01-10 21:39:01 +00:00
|
|
|
void setSneakOffset(float offset);
|
2013-10-02 09:16:52 +00:00
|
|
|
|
2013-04-29 11:40:28 +00:00
|
|
|
bool isFirstPerson() const
|
|
|
|
{ return !(mVanity.enabled || mPreviewMode || !mFirstPersonView); }
|
|
|
|
|
2013-07-13 23:12:38 +00:00
|
|
|
void processViewChange();
|
|
|
|
|
2013-07-30 21:24:18 +00:00
|
|
|
void update(float duration, bool paused=false);
|
2012-08-14 10:37:48 +00:00
|
|
|
|
2020-06-21 23:54:08 +00:00
|
|
|
/// Set base camera distance for current mode. Don't work on 1st person view.
|
|
|
|
/// \param adjust Indicates should distance be adjusted or set.
|
2020-06-23 18:05:22 +00:00
|
|
|
void updateBaseCameraDistance(float dist, bool adjust = false);
|
2020-06-21 23:54:08 +00:00
|
|
|
|
2012-08-16 09:15:38 +00:00
|
|
|
/// Set camera distance for current mode. Don't work on 1st person view.
|
|
|
|
/// \param adjust Indicates should distance be adjusted or set.
|
2020-06-21 23:54:08 +00:00
|
|
|
/// Default distance can be restored with setCameraDistance().
|
|
|
|
void setCameraDistance(float dist, bool adjust = false);
|
2012-08-16 09:15:38 +00:00
|
|
|
|
2020-06-21 23:54:08 +00:00
|
|
|
/// Restore default camera distance and offset for current mode.
|
2012-08-16 09:15:38 +00:00
|
|
|
void setCameraDistance();
|
2012-08-14 16:33:29 +00:00
|
|
|
|
2014-01-01 22:59:17 +00:00
|
|
|
float getCameraDistance() const;
|
|
|
|
|
2013-01-17 23:48:09 +00:00
|
|
|
void setAnimation(NpcAnimation *anim);
|
2012-08-14 16:33:29 +00:00
|
|
|
|
2020-06-21 23:54:08 +00:00
|
|
|
osg::Vec3d getFocalPoint() const;
|
|
|
|
osg::Vec3d getFocalPointOffset() const;
|
|
|
|
void adjustFocalPoint(osg::Vec3d adjustment) { mFocalPointAdjustment = adjustment; }
|
2015-06-01 13:34:46 +00:00
|
|
|
|
2013-07-23 08:37:41 +00:00
|
|
|
/// Stores focal and camera world positions in passed arguments
|
2020-06-21 23:54:08 +00:00
|
|
|
void getPosition(osg::Vec3d &focal, osg::Vec3d &camera) const;
|
2012-08-17 09:23:02 +00:00
|
|
|
|
2020-06-21 23:54:08 +00:00
|
|
|
bool isVanityOrPreviewModeEnabled() const;
|
2013-07-29 14:43:16 +00:00
|
|
|
|
2020-06-21 23:54:08 +00:00
|
|
|
bool isNearest() const;
|
2011-01-08 14:11:37 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|