mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-15 23:42:20 +00:00
Refactoring in mwrender::Camera. enum for normal/preview/vanity mode.
This commit is contained in:
parent
8ac7ffc32b
commit
63cab4052d
@ -52,7 +52,8 @@ namespace MWRender
|
|||||||
mCamera(camera),
|
mCamera(camera),
|
||||||
mAnimation(nullptr),
|
mAnimation(nullptr),
|
||||||
mFirstPersonView(true),
|
mFirstPersonView(true),
|
||||||
mPreviewMode(false),
|
mMode(Mode::Normal),
|
||||||
|
mVanityAllowed(true),
|
||||||
mNearest(30.f),
|
mNearest(30.f),
|
||||||
mFurthest(800.f),
|
mFurthest(800.f),
|
||||||
mIsNearest(false),
|
mIsNearest(false),
|
||||||
@ -73,9 +74,6 @@ namespace MWRender
|
|||||||
mDynamicCameraDistanceEnabled(false),
|
mDynamicCameraDistanceEnabled(false),
|
||||||
mShowCrosshairInThirdPersonMode(false)
|
mShowCrosshairInThirdPersonMode(false)
|
||||||
{
|
{
|
||||||
mVanity.enabled = false;
|
|
||||||
mVanity.allowed = true;
|
|
||||||
|
|
||||||
mCameraDistance = mBaseCameraDistance;
|
mCameraDistance = mBaseCameraDistance;
|
||||||
|
|
||||||
mUpdateCallback = new UpdateRenderCameraCallback(this);
|
mUpdateCallback = new UpdateRenderCameraCallback(this);
|
||||||
@ -133,9 +131,6 @@ namespace MWRender
|
|||||||
|
|
||||||
void Camera::updateCamera(osg::Camera *cam)
|
void Camera::updateCamera(osg::Camera *cam)
|
||||||
{
|
{
|
||||||
if (mTrackingPtr.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
osg::Vec3d focal, position;
|
osg::Vec3d focal, position;
|
||||||
getPosition(focal, position);
|
getPosition(focal, position);
|
||||||
|
|
||||||
@ -165,11 +160,6 @@ namespace MWRender
|
|||||||
setPitch(pitch);
|
setPitch(pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::attachTo(const MWWorld::Ptr &ptr)
|
|
||||||
{
|
|
||||||
mTrackingPtr = ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Camera::update(float duration, bool paused)
|
void Camera::update(float duration, bool paused)
|
||||||
{
|
{
|
||||||
if (mAnimation->upperBodyReady())
|
if (mAnimation->upperBodyReady())
|
||||||
@ -193,13 +183,11 @@ namespace MWRender
|
|||||||
|
|
||||||
// only show the crosshair in game mode
|
// only show the crosshair in game mode
|
||||||
MWBase::WindowManager *wm = MWBase::Environment::get().getWindowManager();
|
MWBase::WindowManager *wm = MWBase::Environment::get().getWindowManager();
|
||||||
wm->showCrosshair(!wm->isGuiMode() && !mVanity.enabled && !mPreviewMode
|
wm->showCrosshair(!wm->isGuiMode() && mMode != Mode::Preview && mMode != Mode::Vanity
|
||||||
&& (mFirstPersonView || mShowCrosshairInThirdPersonMode));
|
&& (mFirstPersonView || mShowCrosshairInThirdPersonMode));
|
||||||
|
|
||||||
if(mVanity.enabled)
|
if(mMode == Mode::Vanity)
|
||||||
{
|
|
||||||
rotateCamera(0.f, osg::DegreesToRadians(3.f * duration), true);
|
rotateCamera(0.f, osg::DegreesToRadians(3.f * duration), true);
|
||||||
}
|
|
||||||
|
|
||||||
updateFocalPointOffset(duration);
|
updateFocalPointOffset(duration);
|
||||||
|
|
||||||
@ -280,9 +268,9 @@ namespace MWRender
|
|||||||
|
|
||||||
void Camera::allowVanityMode(bool allow)
|
void Camera::allowVanityMode(bool allow)
|
||||||
{
|
{
|
||||||
if (!allow && mVanity.enabled)
|
if (!allow && mMode == Mode::Vanity)
|
||||||
toggleVanityMode(false);
|
toggleVanityMode(false);
|
||||||
mVanity.allowed = allow;
|
mVanityAllowed = allow;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Camera::toggleVanityMode(bool enable)
|
bool Camera::toggleVanityMode(bool enable)
|
||||||
@ -296,12 +284,12 @@ namespace MWRender
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mVanity.allowed && enable)
|
if (!mVanityAllowed && enable)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(mVanity.enabled == enable)
|
if ((mMode == Mode::Vanity) == enable)
|
||||||
return true;
|
return true;
|
||||||
mVanity.enabled = enable;
|
mMode = enable ? Mode::Vanity : Mode::Normal;
|
||||||
|
|
||||||
processViewChange();
|
processViewChange();
|
||||||
return true;
|
return true;
|
||||||
@ -312,10 +300,10 @@ namespace MWRender
|
|||||||
if (mFirstPersonView && !mAnimation->upperBodyReady())
|
if (mFirstPersonView && !mAnimation->upperBodyReady())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(mPreviewMode == enable)
|
if((mMode == Mode::Preview) == enable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mPreviewMode = enable;
|
mMode = enable ? Mode::Preview : Mode::Normal;
|
||||||
processViewChange();
|
processViewChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,26 +338,21 @@ namespace MWRender
|
|||||||
|
|
||||||
void Camera::updateBaseCameraDistance(float dist, bool adjust)
|
void Camera::updateBaseCameraDistance(float dist, bool adjust)
|
||||||
{
|
{
|
||||||
if(mFirstPersonView && !mPreviewMode && !mVanity.enabled)
|
if (isFirstPerson())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (adjust)
|
if (adjust)
|
||||||
dist += std::min(mCameraDistance - getCameraDistanceCorrection(), mBaseCameraDistance);
|
dist += std::min(mCameraDistance - getCameraDistanceCorrection(), mBaseCameraDistance);
|
||||||
|
|
||||||
mIsNearest = dist <= mNearest;
|
mIsNearest = dist <= mNearest;
|
||||||
dist = osg::clampBetween(dist, mNearest, mFurthest);
|
mBaseCameraDistance = osg::clampBetween(dist, mNearest, mFurthest);
|
||||||
|
Settings::Manager::setFloat("third person camera distance", "Camera", mBaseCameraDistance);
|
||||||
if (!mFirstPersonView)
|
|
||||||
{
|
|
||||||
mBaseCameraDistance = dist;
|
|
||||||
Settings::Manager::setFloat("third person camera distance", "Camera", dist);
|
|
||||||
}
|
|
||||||
setCameraDistance();
|
setCameraDistance();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::setCameraDistance(float dist, bool adjust)
|
void Camera::setCameraDistance(float dist, bool adjust)
|
||||||
{
|
{
|
||||||
if(mFirstPersonView && !mPreviewMode && !mVanity.enabled)
|
if (isFirstPerson())
|
||||||
return;
|
return;
|
||||||
if (adjust)
|
if (adjust)
|
||||||
dist += mCameraDistance;
|
dist += mCameraDistance;
|
||||||
@ -392,7 +375,7 @@ namespace MWRender
|
|||||||
void Camera::setCameraDistance()
|
void Camera::setCameraDistance()
|
||||||
{
|
{
|
||||||
mFocalPointAdjustment = osg::Vec3d();
|
mFocalPointAdjustment = osg::Vec3d();
|
||||||
if (mFirstPersonView)
|
if (isFirstPerson())
|
||||||
return;
|
return;
|
||||||
mCameraDistance = mBaseCameraDistance + getCameraDistanceCorrection();
|
mCameraDistance = mBaseCameraDistance + getCameraDistanceCorrection();
|
||||||
if (mDynamicCameraDistanceEnabled)
|
if (mDynamicCameraDistanceEnabled)
|
||||||
|
@ -23,6 +23,9 @@ namespace MWRender
|
|||||||
/// \brief Camera control
|
/// \brief Camera control
|
||||||
class Camera
|
class Camera
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
enum class Mode { Normal, Vanity, Preview };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MWWorld::Ptr mTrackingPtr;
|
MWWorld::Ptr mTrackingPtr;
|
||||||
osg::ref_ptr<const osg::Node> mTrackingNode;
|
osg::ref_ptr<const osg::Node> mTrackingNode;
|
||||||
@ -33,15 +36,13 @@ namespace MWRender
|
|||||||
NpcAnimation *mAnimation;
|
NpcAnimation *mAnimation;
|
||||||
|
|
||||||
bool mFirstPersonView;
|
bool mFirstPersonView;
|
||||||
bool mPreviewMode;
|
Mode mMode;
|
||||||
|
bool mVanityAllowed;
|
||||||
|
|
||||||
float mNearest;
|
float mNearest;
|
||||||
float mFurthest;
|
float mFurthest;
|
||||||
bool mIsNearest;
|
bool mIsNearest;
|
||||||
|
|
||||||
struct {
|
|
||||||
bool enabled, allowed;
|
|
||||||
} mVanity;
|
|
||||||
|
|
||||||
float mHeight, mBaseCameraDistance;
|
float mHeight, mBaseCameraDistance;
|
||||||
float mPitch, mYaw;
|
float mPitch, mYaw;
|
||||||
|
|
||||||
@ -78,6 +79,8 @@ namespace MWRender
|
|||||||
Camera(osg::Camera* camera);
|
Camera(osg::Camera* camera);
|
||||||
~Camera();
|
~Camera();
|
||||||
|
|
||||||
|
/// Attach camera to object
|
||||||
|
void attachTo(const MWWorld::Ptr &ptr) { mTrackingPtr = ptr; }
|
||||||
MWWorld::Ptr getTrackingPtr() const { return mTrackingPtr; }
|
MWWorld::Ptr getTrackingPtr() const { return mTrackingPtr; }
|
||||||
|
|
||||||
void setFocalPointTransitionSpeed(float v) { mFocalPointTransitionSpeedCoef = v; }
|
void setFocalPointTransitionSpeed(float v) { mFocalPointTransitionSpeedCoef = v; }
|
||||||
@ -102,9 +105,6 @@ namespace MWRender
|
|||||||
float getPitch() const { return mPitch; }
|
float getPitch() const { return mPitch; }
|
||||||
void setPitch(float angle);
|
void setPitch(float angle);
|
||||||
|
|
||||||
/// Attach camera to object
|
|
||||||
void attachTo(const MWWorld::Ptr &);
|
|
||||||
|
|
||||||
/// @param Force view mode switch, even if currently not allowed by the animation.
|
/// @param Force view mode switch, even if currently not allowed by the animation.
|
||||||
void toggleViewMode(bool force=false);
|
void toggleViewMode(bool force=false);
|
||||||
|
|
||||||
@ -117,8 +117,7 @@ namespace MWRender
|
|||||||
/// \brief Lowers the camera for sneak.
|
/// \brief Lowers the camera for sneak.
|
||||||
void setSneakOffset(float offset);
|
void setSneakOffset(float offset);
|
||||||
|
|
||||||
bool isFirstPerson() const
|
bool isFirstPerson() const { return mFirstPersonView && mMode == Mode::Normal; }
|
||||||
{ return !(mVanity.enabled || mPreviewMode || !mFirstPersonView); }
|
|
||||||
|
|
||||||
void processViewChange();
|
void processViewChange();
|
||||||
|
|
||||||
@ -147,8 +146,8 @@ namespace MWRender
|
|||||||
/// Stores focal and camera world positions in passed arguments
|
/// Stores focal and camera world positions in passed arguments
|
||||||
void getPosition(osg::Vec3d &focal, osg::Vec3d &camera) const;
|
void getPosition(osg::Vec3d &focal, osg::Vec3d &camera) const;
|
||||||
|
|
||||||
bool isVanityOrPreviewModeEnabled() const { return mPreviewMode || mVanity.enabled; }
|
bool isVanityOrPreviewModeEnabled() const { return mMode != Mode::Normal; }
|
||||||
bool isVanityModeEnabled() const { return mVanity.enabled; }
|
Mode getMode() const { return mMode; }
|
||||||
|
|
||||||
bool isNearest() const { return mIsNearest; }
|
bool isNearest() const { return mIsNearest; }
|
||||||
};
|
};
|
||||||
|
@ -51,12 +51,14 @@ namespace MWRender
|
|||||||
if (oldMode == mMode)
|
if (oldMode == mMode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (mCamera->isVanityOrPreviewModeEnabled())
|
if (mCamera->getMode() == Camera::Mode::Vanity)
|
||||||
mCamera->setFocalPointTransitionSpeed(mCamera->isVanityModeEnabled() ? 0.2 : 1);
|
// Player doesn't touch controls for a long time. Transition should be very slow.
|
||||||
else if (oldMode == Mode::Combat || mMode == Mode::Combat)
|
mCamera->setFocalPointTransitionSpeed(0.2f);
|
||||||
|
else if ((oldMode == Mode::Combat || mMode == Mode::Combat) && mCamera->getMode() == Camera::Mode::Normal)
|
||||||
|
// Transition to/from combat mode and we are not it preview mode. Should be fast.
|
||||||
mCamera->setFocalPointTransitionSpeed(5.f);
|
mCamera->setFocalPointTransitionSpeed(5.f);
|
||||||
else
|
else
|
||||||
mCamera->setFocalPointTransitionSpeed(1.f);
|
mCamera->setFocalPointTransitionSpeed(1.f); // Default transition speed.
|
||||||
|
|
||||||
switch (mMode)
|
switch (mMode)
|
||||||
{
|
{
|
||||||
@ -98,4 +100,4 @@ namespace MWRender
|
|||||||
mMode = mDefaultShoulderIsRight ? Mode::RightShoulder : Mode::LeftShoulder;
|
mMode = mDefaultShoulderIsRight ? Mode::RightShoulder : Mode::LeftShoulder;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user