2013-04-29 05:50:40 -07:00
|
|
|
#ifndef GAME_MWRENDER_CAMERA_H
|
|
|
|
#define GAME_MWRENDER_CAMERA_H
|
2011-01-08 15:11:37 +01:00
|
|
|
|
2012-07-03 15:32:38 +02:00
|
|
|
#include <string>
|
2011-02-10 12:56:19 +01:00
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <osg/Vec3>
|
2015-06-01 15:34:46 +02:00
|
|
|
#include <osg/Vec3d>
|
2015-05-21 23:54:39 +02:00
|
|
|
|
2013-04-28 23:44:44 -07:00
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
namespace osg
|
2012-08-12 18:35:35 +04:00
|
|
|
{
|
2011-01-08 15:11:37 +01:00
|
|
|
class Camera;
|
2015-05-21 23:54:39 +02:00
|
|
|
class NodeCallback;
|
|
|
|
class Node;
|
2011-01-08 15:11:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWRender
|
|
|
|
{
|
2012-08-14 20:33:29 +04:00
|
|
|
class NpcAnimation;
|
2013-04-28 23:44:44 -07:00
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
/// \brief Camera control
|
|
|
|
class Camera
|
2011-01-08 15:11:37 +01:00
|
|
|
{
|
2020-07-18 10:27:13 +02:00
|
|
|
public:
|
2020-07-18 13:27:53 +02:00
|
|
|
enum class Mode { Normal, Vanity, Preview, StandingPreview };
|
2020-07-18 10:27:13 +02:00
|
|
|
|
2020-06-22 01:54:08 +02:00
|
|
|
private:
|
2013-04-28 23:44:44 -07:00
|
|
|
MWWorld::Ptr mTrackingPtr;
|
2015-05-21 23:54:39 +02:00
|
|
|
osg::ref_ptr<const osg::Node> mTrackingNode;
|
2015-11-09 17:30:11 +01:00
|
|
|
float mHeightScale;
|
2012-08-12 15:50:37 +04:00
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
osg::ref_ptr<osg::Camera> mCamera;
|
2011-01-08 15:11:37 +01:00
|
|
|
|
2012-08-14 20:33:29 +04:00
|
|
|
NpcAnimation *mAnimation;
|
|
|
|
|
2012-08-09 00:15:52 +04:00
|
|
|
bool mFirstPersonView;
|
2020-07-18 10:27:13 +02:00
|
|
|
Mode mMode;
|
|
|
|
bool mVanityAllowed;
|
2020-07-18 13:27:53 +02:00
|
|
|
bool mStandingPreviewAllowed;
|
|
|
|
bool mDeferredRotationAllowed;
|
2020-07-18 10:27:13 +02:00
|
|
|
|
2013-07-29 16:43:16 +02:00
|
|
|
float mNearest;
|
|
|
|
float mFurthest;
|
|
|
|
bool mIsNearest;
|
2012-08-12 15:50:37 +04:00
|
|
|
|
2020-06-22 01:54:08 +02:00
|
|
|
float mHeight, mBaseCameraDistance;
|
2020-10-04 20:12:45 +02:00
|
|
|
float mPitch, mYaw, mRoll;
|
2012-08-12 18:35:35 +04:00
|
|
|
|
2013-12-27 00:36:06 +01:00
|
|
|
bool mVanityToggleQueued;
|
2016-06-10 01:39:37 +02:00
|
|
|
bool mVanityToggleQueuedValue;
|
2013-12-27 00:36:06 +01:00
|
|
|
bool mViewModeToggleQueued;
|
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
float mCameraDistance;
|
2020-07-16 23:32:59 +02:00
|
|
|
float mMaxNextCameraDistance;
|
2015-05-21 23:54:39 +02:00
|
|
|
|
2020-06-22 01:54:08 +02:00
|
|
|
osg::Vec3d mFocalPointAdjustment;
|
2020-06-19 22:03:11 +02:00
|
|
|
osg::Vec2d mFocalPointCurrentOffset;
|
2020-07-11 14:21:18 +02:00
|
|
|
osg::Vec2d mFocalPointTargetOffset;
|
2020-07-12 01:55:20 +02:00
|
|
|
float mFocalPointTransitionSpeedCoef;
|
2020-07-16 22:21:50 +02:00
|
|
|
bool mSkipFocalPointTransition;
|
2020-07-12 01:55:20 +02:00
|
|
|
|
|
|
|
// This fields are used to make focal point transition smooth if previous transition was not finished.
|
|
|
|
float mPreviousTransitionInfluence;
|
|
|
|
osg::Vec2d mFocalPointTransitionSpeed;
|
|
|
|
osg::Vec2d mPreviousTransitionSpeed;
|
|
|
|
osg::Vec2d mPreviousExtraOffset;
|
2020-06-19 22:03:11 +02:00
|
|
|
|
2020-06-22 19:26:37 +02:00
|
|
|
float mSmoothedSpeed;
|
2020-07-12 21:03:18 +02:00
|
|
|
float mZoomOutWhenMoveCoef;
|
2020-07-11 14:21:18 +02:00
|
|
|
bool mDynamicCameraDistanceEnabled;
|
|
|
|
bool mShowCrosshairInThirdPersonMode;
|
2020-06-22 19:26:37 +02:00
|
|
|
|
2020-10-04 20:12:45 +02:00
|
|
|
bool mHeadBobbingEnabled;
|
|
|
|
float mHeadBobbingOffset;
|
2020-10-28 18:02:31 +04:00
|
|
|
float mHeadBobbingWeight; // Value from 0 to 1 for smooth enabling/disabling.
|
|
|
|
float mTotalMovement; // Needed for head bobbing.
|
2020-10-04 20:12:45 +02:00
|
|
|
void updateHeadBobbing(float duration);
|
|
|
|
|
2020-06-19 22:03:11 +02:00
|
|
|
void updateFocalPointOffset(float duration);
|
2020-07-25 21:12:50 +02:00
|
|
|
void updatePosition();
|
2020-06-22 01:54:08 +02:00
|
|
|
float getCameraDistanceCorrection() const;
|
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
osg::ref_ptr<osg::NodeCallback> mUpdateCallback;
|
2014-10-01 18:55:35 +02:00
|
|
|
|
2020-07-18 11:48:46 +02:00
|
|
|
// Used to rotate player to the direction of view after exiting preview or vanity mode.
|
|
|
|
osg::Vec3f mDeferredRotation;
|
|
|
|
bool mDeferredRotationDisabled;
|
|
|
|
void calculateDeferredRotation();
|
2020-07-18 13:27:53 +02:00
|
|
|
void updateStandingPreviewMode();
|
2020-07-18 11:48:46 +02:00
|
|
|
|
2012-08-09 00:15:52 +04:00
|
|
|
public:
|
2015-05-21 23:54:39 +02:00
|
|
|
Camera(osg::Camera* camera);
|
2013-04-29 05:50:40 -07:00
|
|
|
~Camera();
|
2012-08-09 00:15:52 +04:00
|
|
|
|
2020-07-18 10:27:13 +02:00
|
|
|
/// Attach camera to object
|
|
|
|
void attachTo(const MWWorld::Ptr &ptr) { mTrackingPtr = ptr; }
|
2020-07-17 01:11:09 +02:00
|
|
|
MWWorld::Ptr getTrackingPtr() const { return mTrackingPtr; }
|
2015-05-21 23:54:39 +02:00
|
|
|
|
2020-07-12 01:55:20 +02:00
|
|
|
void setFocalPointTransitionSpeed(float v) { mFocalPointTransitionSpeedCoef = v; }
|
|
|
|
void setFocalPointTargetOffset(osg::Vec2d v);
|
2020-07-18 13:27:53 +02:00
|
|
|
void instantTransition();
|
2020-07-11 14:21:18 +02:00
|
|
|
void enableDynamicCameraDistance(bool v) { mDynamicCameraDistanceEnabled = v; }
|
|
|
|
void enableCrosshairInThirdPersonMode(bool v) { mShowCrosshairInThirdPersonMode = v; }
|
2020-06-19 22:03:11 +02:00
|
|
|
|
2015-05-21 23:54:39 +02:00
|
|
|
/// Update the view matrix of \a cam
|
|
|
|
void updateCamera(osg::Camera* cam);
|
|
|
|
|
2013-05-17 22:53:43 +02:00
|
|
|
/// Reset to defaults
|
|
|
|
void reset();
|
|
|
|
|
2013-04-29 05:50:40 -07:00
|
|
|
/// Set where the camera is looking at. Uses Morrowind (euler) angles
|
2012-08-11 13:23:54 +04:00
|
|
|
/// \param rot Rotation angles in radians
|
2015-05-21 23:54:39 +02:00
|
|
|
void rotateCamera(float pitch, float yaw, bool adjust);
|
2020-07-18 11:48:46 +02:00
|
|
|
void rotateCameraToTrackingPtr();
|
2012-11-05 19:48:07 +00:00
|
|
|
|
2020-07-17 01:11:09 +02:00
|
|
|
float getYaw() const { return mYaw; }
|
2012-11-05 19:48:07 +00:00
|
|
|
void setYaw(float angle);
|
2011-01-08 15:11:37 +01:00
|
|
|
|
2020-07-17 01:11:09 +02:00
|
|
|
float getPitch() const { return mPitch; }
|
2012-11-05 19:48:07 +00:00
|
|
|
void setPitch(float angle);
|
|
|
|
|
2014-06-05 17:21:02 +02:00
|
|
|
/// @param Force view mode switch, even if currently not allowed by the animation.
|
|
|
|
void toggleViewMode(bool force=false);
|
2012-08-12 15:50:37 +04:00
|
|
|
|
2013-04-27 01:24:36 -07:00
|
|
|
bool toggleVanityMode(bool enable);
|
2012-08-14 14:37:48 +04:00
|
|
|
void allowVanityMode(bool allow);
|
2012-08-12 15:50:37 +04:00
|
|
|
|
2013-12-27 00:36:06 +01:00
|
|
|
/// @note this may be ignored if an important animation is currently playing
|
2012-08-14 02:36:18 +04:00
|
|
|
void togglePreviewMode(bool enable);
|
2012-05-30 15:52:39 +02:00
|
|
|
|
2020-07-18 11:48:46 +02:00
|
|
|
void applyDeferredPreviewRotationToPlayer(float dt);
|
|
|
|
void disableDeferredPreviewRotation() { mDeferredRotationDisabled = true; }
|
|
|
|
|
2013-10-02 05:16:52 -04:00
|
|
|
/// \brief Lowers the camera for sneak.
|
2014-01-10 22:39:01 +01:00
|
|
|
void setSneakOffset(float offset);
|
2013-10-02 05:16:52 -04:00
|
|
|
|
2020-07-18 10:27:13 +02:00
|
|
|
bool isFirstPerson() const { return mFirstPersonView && mMode == Mode::Normal; }
|
2013-04-29 04:40:28 -07:00
|
|
|
|
2013-07-13 16:12:38 -07:00
|
|
|
void processViewChange();
|
|
|
|
|
2013-07-30 23:24:18 +02:00
|
|
|
void update(float duration, bool paused=false);
|
2012-08-14 14:37:48 +04:00
|
|
|
|
2020-07-25 22:42:58 +02:00
|
|
|
/// Adds distDelta to the camera distance. Switches 3rd/1st person view if distance is less than limit.
|
|
|
|
void adjustCameraDistance(float distDelta);
|
2012-08-16 13:15:38 +04:00
|
|
|
|
2014-01-01 23:59:17 +01:00
|
|
|
float getCameraDistance() const;
|
|
|
|
|
2013-01-17 15:48:09 -08:00
|
|
|
void setAnimation(NpcAnimation *anim);
|
2012-08-14 20:33:29 +04:00
|
|
|
|
2020-06-22 01:54:08 +02:00
|
|
|
osg::Vec3d getFocalPoint() const;
|
|
|
|
osg::Vec3d getFocalPointOffset() const;
|
2015-06-01 15:34:46 +02:00
|
|
|
|
2013-07-23 01:37:41 -07:00
|
|
|
/// Stores focal and camera world positions in passed arguments
|
2020-06-22 01:54:08 +02:00
|
|
|
void getPosition(osg::Vec3d &focal, osg::Vec3d &camera) const;
|
2012-08-17 13:23:02 +04:00
|
|
|
|
2020-07-18 10:27:13 +02:00
|
|
|
bool isVanityOrPreviewModeEnabled() const { return mMode != Mode::Normal; }
|
|
|
|
Mode getMode() const { return mMode; }
|
2013-07-29 16:43:16 +02:00
|
|
|
|
2020-07-17 01:11:09 +02:00
|
|
|
bool isNearest() const { return mIsNearest; }
|
2011-01-08 15:11:37 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|