aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSmallJoker <mk939@ymail.com>2017-11-26 15:37:55 +0100
committerparamat <mat.gregory@virginmedia.com>2017-12-01 05:36:49 +0000
commit089f594582862d041a5bf3fa0f41d637248e31de (patch)
tree794ab6360d48049e78f374daf85f683f14ff5a38 /src
parentf4fedfed070ffd85c3446bc5d38d2fbd577640d6 (diff)
downloadminetest-089f594582862d041a5bf3fa0f41d637248e31de.tar.gz
minetest-089f594582862d041a5bf3fa0f41d637248e31de.tar.bz2
minetest-089f594582862d041a5bf3fa0f41d637248e31de.zip
CAO/SAO: Nicer velocity-controlled, interpolated rotation property:
'automatic_face_movement_max_rotation_per_sec'. Rotate towards the smaller angle.
Diffstat (limited to 'src')
-rw-r--r--src/content_cao.cpp16
-rw-r--r--src/content_sao.cpp20
2 files changed, 18 insertions, 18 deletions
diff --git a/src/content_cao.cpp b/src/content_cao.cpp
index 861dc83e7..7b6570653 100644
--- a/src/content_cao.cpp
+++ b/src/content_cao.cpp
@@ -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();
}
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index e2bfdbef2..61384493a 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -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
- + m_prop.automatic_face_movement_dir_offset;
+ 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;
}
}
}