1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-28 19:21:04 +00:00

Slightly pulls camera away when the character moves

This commit is contained in:
Petr Mikheev 2020-06-22 19:26:37 +02:00
parent ef03f2c033
commit 5bdf61a886
2 changed files with 19 additions and 2 deletions

View File

@ -68,7 +68,8 @@ namespace MWRender
mDefaultShoulderIsRight(true),
mThirdPersionOffsetType(ThirdPersonOffsetType::RightShoulder),
mFocalPointCurrentOffset(osg::Vec2d()),
mFocalPointTransitionSpeed(1.f)
mFocalPointTransitionSpeed(1.f),
mSmoothedSpeed(0.f)
{
mVanity.enabled = false;
mVanity.allowed = true;
@ -216,6 +217,10 @@ namespace MWRender
}
updateFocalPointOffset(duration);
float speed = mTrackingPtr.getClass().getSpeed(mTrackingPtr);
float maxDelta = 300.f * duration;
mSmoothedSpeed += osg::clampBetween(speed - mSmoothedSpeed, -maxDelta, maxDelta);
}
void Camera::setOverShoulderOffset(float horizontal, float vertical)
@ -482,7 +487,17 @@ namespace MWRender
float Camera::getCameraDistanceCorrection() const
{
return mThirdPersonMode != ThirdPersonViewMode::Standard ? std::max(-getPitch(), 0.f) * 50.f : 0;
if (mThirdPersonMode == ThirdPersonViewMode::Standard)
return 0;
else
{
float pitchCorrection = std::max(-getPitch(), 0.f) * 50.f;
float smoothedSpeedSqr = mSmoothedSpeed * mSmoothedSpeed;
float speedCorrection = smoothedSpeedSqr / (smoothedSpeedSqr + 300.f*300.f) * 20.0f;
return pitchCorrection + speedCorrection;
}
}
void Camera::setCameraDistance()

View File

@ -70,6 +70,8 @@ namespace MWRender
osg::Vec2d mFocalPointCurrentOffset;
float mFocalPointTransitionSpeed;
float mSmoothedSpeed;
void updateFocalPointOffset(float duration);
float getCameraDistanceCorrection() const;