1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-12-13 00:13:17 +00:00

Attempt at clarifying the code

This commit is contained in:
Mads Buvik Sandvei 2023-11-04 14:00:13 +01:00
parent 4886d31d89
commit 68fe1361f1

View file

@ -2386,26 +2386,26 @@ namespace MWMechanics
} }
} }
osg::Vec3f moved = mAnimation->runAnimation(mSkipAnim && !isScriptedAnimPlaying() ? 0.f : duration); osg::Vec3f movementFromAnimation = mAnimation->runAnimation(mSkipAnim && !isScriptedAnimPlaying() ? 0.f : duration);
if (mPtr.getClass().isActor() && isMovementAnimationControlled() && !isScriptedAnimPlaying()) if (mPtr.getClass().isActor() && isMovementAnimationControlled() && !isScriptedAnimPlaying())
{ {
if (duration > 0.0f) if (duration > 0.0f)
moved /= duration; movementFromAnimation /= duration;
else else
moved = osg::Vec3f(0.f, 0.f, 0.f); movementFromAnimation = osg::Vec3f(0.f, 0.f, 0.f);
moved.x() *= scale; movementFromAnimation.x() *= scale;
moved.y() *= scale; movementFromAnimation.y() *= scale;
if (speed > 0.f && moved != osg::Vec3f()) if (speed > 0.f && movementFromAnimation != osg::Vec3f())
{ {
// Ensure we're moving in generally the right direction // Ensure we're moving in the right general direction. In vanilla, all horizontal movement is taken from animations,
// This is necessary when the "turn to movement direction" feature is off, as animations // even when moving diagonally (which doesn't have a corresponding animation). So to acheive diagonal movement,
// will not be rotated to match diagonal movement. In this case we have to slide the // we have to rotate the movement taken from the animation to the intended direction.
// character diagonally. //
// Note that while a complete movement animation cycle will have a well defined direction, no individual frame will, and
// First decide the general direction expected from the current animation // therefore we have to determine the direction separately from the value of the movementFromAnimation variable.
float animMovementAngle = 0; float animMovementAngle = 0;
if (!Settings::game().mTurnToMovementDirection || isFirstPersonPlayer) if (!Settings::game().mTurnToMovementDirection || isFirstPersonPlayer)
{ {
@ -2426,12 +2426,12 @@ namespace MWMechanics
float diff = targetMovementAngle - animMovementAngle; float diff = targetMovementAngle - animMovementAngle;
if (std::abs(diff) > epsilon) if (std::abs(diff) > epsilon)
{ {
moved = osg::Quat(diff, osg::Vec3f(0, 0, 1)) * moved; movementFromAnimation = osg::Quat(diff, osg::Vec3f(0, 0, 1)) * movementFromAnimation;
} }
if (isPlayer && Settings::game().mPlayerMovementIgnoresAnimation) if (!(isPlayer && Settings::game().mPlayerMovementIgnoresAnimation))
{ {
moved = movement; movement = movementFromAnimation;
} }
} }
@ -2445,12 +2445,12 @@ namespace MWMechanics
.getModifier() .getModifier()
> 0)) > 0))
{ {
moved.z() = 1.0; movement.z() = 1.0;
} }
} }
// Update movement // Update movement
world->queueMovement(mPtr, moved); world->queueMovement(mPtr, movement);
} }
mSkipAnim = false; mSkipAnim = false;