@ -21,6 +21,7 @@
# include <iostream>
# include <iostream>
# include <components/misc/mathutil.hpp>
# include <components/misc/rng.hpp>
# include <components/misc/rng.hpp>
# include <components/settings/settings.hpp>
# include <components/settings/settings.hpp>
@ -51,15 +52,6 @@
namespace
namespace
{
{
// Wraps a value to (-PI, PI]
void wrap ( float & rad )
{
if ( rad > 0 )
rad = std : : fmod ( rad + osg : : PI , 2.0f * osg : : PI ) - osg : : PI ;
else
rad = std : : fmod ( rad - osg : : PI , 2.0f * osg : : PI ) + osg : : PI ;
}
std : : string getBestAttack ( const ESM : : Weapon * weapon )
std : : string getBestAttack ( const ESM : : Weapon * weapon )
{
{
int slash = ( weapon - > mData . mSlash [ 0 ] + weapon - > mData . mSlash [ 1 ] ) / 2 ;
int slash = ( weapon - > mData . mSlash [ 0 ] + weapon - > mData . mSlash [ 1 ] ) / 2 ;
@ -1958,23 +1950,19 @@ void CharacterController::update(float duration, bool animationOnly)
osg : : Vec3f rot = cls . getRotationVector ( mPtr ) ;
osg : : Vec3f rot = cls . getRotationVector ( mPtr ) ;
osg : : Vec3f vec ( movementSettings . asVec3 ( ) ) ;
osg : : Vec3f vec ( movementSettings . asVec3 ( ) ) ;
vec . normalize ( ) ;
float analogueMult = 1.0f ;
if ( isPlayer )
if ( isPlayer )
{
{
// TODO: Move this code to mwinput.
// TODO: Move this code to mwinput.
// Joystick analogue movement.
// Joystick analogue movement.
float xAxis = std : : abs ( movementSettings . mPosition [ 0 ] ) ;
movementSettings . mSpeedFactor = std : : max ( std : : abs ( vec . x ( ) ) , std : : abs ( vec . y ( ) ) ) ;
float yAxis = std : : abs ( movementSettings . mPosition [ 1 ] ) ;
analogueMult = std : : max ( xAxis , yAxis ) ;
// Due to the half way split between walking/running, we multiply speed by 2 while walking, unless a keyboard was used.
// Due to the half way split between walking/running, we multiply speed by 2 while walking, unless a keyboard was used.
if ( ! isrunning & & ! sneak & & ! flying & & analogueMult < = 0.5f )
if ( ! isrunning & & ! sneak & & ! flying & & movementSettings. mSpeedFactor < = 0.5f )
analogueMult * = 2.f ;
movementSettings. mSpeedFactor * = 2.f ;
} else
movementSettings . mSpeedFactor = analogueMult ;
movementSettings . mSpeedFactor = std: : min ( vec . length ( ) , 1.f ) ;
}
vec . normalize ( ) ;
float effectiveRotation = rot . z ( ) ;
float effectiveRotation = rot . z ( ) ;
static const bool turnToMovementDirection = Settings : : Manager : : getBool ( " turn to movement direction " , " Game " ) ;
static const bool turnToMovementDirection = Settings : : Manager : : getBool ( " turn to movement direction " , " Game " ) ;
@ -2007,7 +1995,7 @@ void CharacterController::update(float duration, bool animationOnly)
else
else
mAnimation - > setUpperBodyYawRadians ( stats . getSideMovementAngle ( ) / 4 ) ;
mAnimation - > setUpperBodyYawRadians ( stats . getSideMovementAngle ( ) / 4 ) ;
speed = cls . get Speed( mPtr ) ;
speed = cls . get Current Speed( mPtr ) ;
vec . x ( ) * = speed ;
vec . x ( ) * = speed ;
vec . y ( ) * = speed ;
vec . y ( ) * = speed ;
@ -2077,7 +2065,7 @@ void CharacterController::update(float duration, bool animationOnly)
}
}
}
}
fatigueLoss * = duration ;
fatigueLoss * = duration ;
fatigueLoss * = analogueMult ;
fatigueLoss * = movementSettings. mSpeedFactor ;
DynamicStat < float > fatigue = cls . getCreatureStats ( mPtr ) . getFatigue ( ) ;
DynamicStat < float > fatigue = cls . getCreatureStats ( mPtr ) . getFatigue ( ) ;
if ( ! godmode )
if ( ! godmode )
@ -2908,13 +2896,10 @@ void CharacterController::updateHeadTracking(float duration)
zAngleRadians = std : : atan2 ( direction . x ( ) , direction . y ( ) ) - std : : atan2 ( actorDirection . x ( ) , actorDirection . y ( ) ) ;
zAngleRadians = std : : atan2 ( direction . x ( ) , direction . y ( ) ) - std : : atan2 ( actorDirection . x ( ) , actorDirection . y ( ) ) ;
xAngleRadians = - std : : asin ( direction . z ( ) ) ;
xAngleRadians = - std : : asin ( direction . z ( ) ) ;
wrap ( zAngleRadians ) ;
const double xLimit = osg : : DegreesToRadians ( 40.0 ) ;
wrap ( xAngleRadians ) ;
const double zLimit = osg : : DegreesToRadians ( 30.0 ) ;
zAngleRadians = osg : : clampBetween ( Misc : : normalizeAngle ( zAngleRadians ) , - xLimit , xLimit ) ;
xAngleRadians = std : : min ( xAngleRadians , osg : : DegreesToRadians ( 40.f ) ) ;
xAngleRadians = osg : : clampBetween ( Misc : : normalizeAngle ( xAngleRadians ) , - zLimit , zLimit ) ;
xAngleRadians = std : : max ( xAngleRadians , osg : : DegreesToRadians ( - 40.f ) ) ;
zAngleRadians = std : : min ( zAngleRadians , osg : : DegreesToRadians ( 30.f ) ) ;
zAngleRadians = std : : max ( zAngleRadians , osg : : DegreesToRadians ( - 30.f ) ) ;
}
}
float factor = duration * 5 ;
float factor = duration * 5 ;