1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 16:49:55 +00:00
openmw-tes3mp/apps/openmw/mwmechanics/steering.cpp

45 lines
1.3 KiB
C++
Raw Normal View History

2014-01-29 19:29:07 +00:00
#include "steering.hpp"
#include <components/misc/mathutil.hpp>
#include <components/settings/settings.hpp>
2014-01-29 19:29:07 +00:00
#include "../mwworld/class.hpp"
#include "../mwworld/ptr.hpp"
#include "../mwbase/environment.hpp"
#include "movement.hpp"
namespace MWMechanics
{
2015-06-03 17:41:19 +00: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 17:41:19 +00:00
float absDiff = std::abs(diff);
// The turning animation actually moves you slightly, so the angle will be wrong again.
// Use epsilon to prevent jerkiness.
2015-06-03 17:41:19 +00:00
if (absDiff < epsilonRadians)
return true;
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);
if (absDiff > limit)
2015-06-03 17:41:19 +00:00
diff = osg::sign(diff) * limit;
movement.mRotation[axis] = diff;
return false;
}
2015-06-03 17:41:19 +00:00
bool zTurn(const MWWorld::Ptr& actor, float targetAngleRadians, float epsilonRadians)
2014-01-29 19:29:07 +00:00
{
2015-06-03 17:41:19 +00:00
return smoothTurn(actor, targetAngleRadians, 2, epsilonRadians);
2014-01-29 19:29:07 +00:00
}
}