1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-07-06 09:11:35 +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), mDefaultShoulderIsRight(true),
mThirdPersionOffsetType(ThirdPersonOffsetType::RightShoulder), mThirdPersionOffsetType(ThirdPersonOffsetType::RightShoulder),
mFocalPointCurrentOffset(osg::Vec2d()), mFocalPointCurrentOffset(osg::Vec2d()),
mFocalPointTransitionSpeed(1.f) mFocalPointTransitionSpeed(1.f),
mSmoothedSpeed(0.f)
{ {
mVanity.enabled = false; mVanity.enabled = false;
mVanity.allowed = true; mVanity.allowed = true;
@ -216,6 +217,10 @@ namespace MWRender
} }
updateFocalPointOffset(duration); 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) void Camera::setOverShoulderOffset(float horizontal, float vertical)
@ -482,7 +487,17 @@ namespace MWRender
float Camera::getCameraDistanceCorrection() const 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() void Camera::setCameraDistance()

View file

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