CAO/SAO: Nicer velocity-controlled, interpolated rotation property:

'automatic_face_movement_max_rotation_per_sec'.
Rotate towards the smaller angle.
This commit is contained in:
SmallJoker 2017-11-26 15:37:55 +01:00 committed by paramat
parent f4fedfed07
commit 089f594582
2 changed files with 18 additions and 18 deletions

@ -904,19 +904,19 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
}
if (!getParent() && m_prop.automatic_face_movement_dir &&
(fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001))
{
float optimal_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI
(fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)) {
float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI
+ m_prop.automatic_face_movement_dir_offset;
float max_rotation_delta =
dtime * m_prop.automatic_face_movement_max_rotation_per_sec;
float delta = wrapDegrees_0_360(target_yaw - m_yaw);
if ((m_prop.automatic_face_movement_max_rotation_per_sec > 0) &&
(fabs(m_yaw - optimal_yaw) > max_rotation_delta)) {
m_yaw = optimal_yaw < m_yaw ? m_yaw - max_rotation_delta : m_yaw + max_rotation_delta;
if (delta > max_rotation_delta && 360 - delta > max_rotation_delta) {
m_yaw += (delta < 180) ? max_rotation_delta : -max_rotation_delta;
m_yaw = wrapDegrees_0_360(m_yaw);
} else {
m_yaw = optimal_yaw;
m_yaw = target_yaw;
}
updateNodePos();
}

@ -372,20 +372,20 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
m_velocity += dtime * m_acceleration;
}
if((m_prop.automatic_face_movement_dir) &&
(fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001))
{
float optimal_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI
if (m_prop.automatic_face_movement_dir &&
(fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)) {
float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI
+ m_prop.automatic_face_movement_dir_offset;
float max_rotation_delta =
dtime * m_prop.automatic_face_movement_max_rotation_per_sec;
float delta = wrapDegrees_0_360(target_yaw - m_yaw);
if ((m_prop.automatic_face_movement_max_rotation_per_sec > 0) &&
(fabs(m_yaw - optimal_yaw) > max_rotation_delta)) {
m_yaw = optimal_yaw < m_yaw ? m_yaw - max_rotation_delta : m_yaw + max_rotation_delta;
if (delta > max_rotation_delta && 360 - delta > max_rotation_delta) {
m_yaw += (delta < 180) ? max_rotation_delta : -max_rotation_delta;
m_yaw = wrapDegrees_0_360(m_yaw);
} else {
m_yaw = optimal_yaw;
m_yaw = target_yaw;
}
}
}