2014-01-29 19:29:07 +00:00
|
|
|
#include "steering.hpp"
|
|
|
|
|
2020-08-29 08:33:57 +00:00
|
|
|
#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)
|
2014-04-25 20:20:55 +00:00
|
|
|
{
|
2020-08-29 08:33:57 +00:00
|
|
|
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);
|
2014-04-25 20:20:55 +00:00
|
|
|
|
|
|
|
// 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)
|
2014-04-25 20:20:55 +00:00
|
|
|
return true;
|
|
|
|
|
2020-08-27 11:48:59 +00:00
|
|
|
float limit = getAngularVelocity(actor.getClass().getMaxSpeed(actor)) * MWBase::Environment::get().getFrameDuration();
|
2020-08-29 08:33:57 +00:00
|
|
|
static const bool smoothMovement = Settings::Manager::getBool("smooth movement", "Game");
|
|
|
|
if (smoothMovement)
|
|
|
|
limit *= std::min(absDiff / osg::PI + 0.1, 0.5);
|
|
|
|
|
2014-04-25 20:20:55 +00:00
|
|
|
if (absDiff > limit)
|
2015-06-03 17:41:19 +00:00
|
|
|
diff = osg::sign(diff) * limit;
|
2014-04-25 20:20:55 +00:00
|
|
|
|
2020-08-29 08:33:57 +00:00
|
|
|
movement.mRotation[axis] = diff;
|
2014-04-25 20:20:55 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|