1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-31 06:32:39 +00:00
OpenMW/apps/openmw/mwmechanics/steering.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.4 KiB
C++
Raw Normal View History

2014-01-29 20:29:07 +01:00
#include "steering.hpp"
#include <components/misc/mathutil.hpp>
#include <components/settings/settings.hpp>
2014-01-29 20:29:07 +01:00
#include "../mwworld/class.hpp"
#include "../mwworld/ptr.hpp"
#include "../mwbase/environment.hpp"
#include "movement.hpp"
namespace MWMechanics
{
2015-06-03 19:41:19 +02:00
bool smoothTurn(const MWWorld::Ptr& actor, float targetAngleRadians, int axis, float epsilonRadians)
{
MWMechanics::Movement& movement = actor.getClass().getMovementSettings(actor);
float diff = Misc::normalizeAngle(targetAngleRadians - actor.getRefData().getPosition().rot[axis]);
2015-06-03 19:41:19 +02:00
float absDiff = std::abs(diff);
2022-09-22 21:26:05 +03:00
// The turning animation actually moves you slightly, so the angle will be wrong again.
// Use epsilon to prevent jerkiness.
2015-06-03 19:41:19 +02:00
if (absDiff < epsilonRadians)
return true;
2022-09-22 21:26:05 +03:00
float limit
= getAngularVelocity(actor.getClass().getMaxSpeed(actor)) * MWBase::Environment::get().getFrameDuration();
static const bool smoothMovement = Settings::Manager::getBool("smooth movement", "Game");
if (smoothMovement)
limit *= std::min(absDiff / osg::PI + 0.1, 0.5);
2022-09-22 21:26:05 +03:00
if (absDiff > limit)
2015-06-03 19:41:19 +02:00
diff = osg::sign(diff) * limit;
2022-09-22 21:26:05 +03:00
movement.mRotation[axis] = diff;
return false;
}
2022-09-22 21:26:05 +03:00
2015-06-03 19:41:19 +02:00
bool zTurn(const MWWorld::Ptr& actor, float targetAngleRadians, float epsilonRadians)
2014-01-29 20:29:07 +01:00
{
2015-06-03 19:41:19 +02:00
return smoothTurn(actor, targetAngleRadians, 2, epsilonRadians);
2014-01-29 20:29:07 +01:00
}
}