diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2017-08-13 23:08:17 +0200 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2017-08-13 23:08:17 +0200 |
commit | 725a0f56db007d46000e6cd18e31824e5b60ee73 (patch) | |
tree | 38e515ae4282ecce1cd5e61e5538b9eaaa4e5565 | |
parent | d65d6160d83a47311ceb33738d2a5e249e76e4c0 (diff) | |
download | minetest-725a0f56db007d46000e6cd18e31824e5b60ee73.tar.gz minetest-725a0f56db007d46000e6cd18e31824e5b60ee73.tar.bz2 minetest-725a0f56db007d46000e6cd18e31824e5b60ee73.zip |
LocalPlayer::accelerateHorizontal: cleanups
* Properly use v3f default constructor
* v3f d_wanted = target_speed - m_speed; and d_wanted = target_speed * 0.1f - m_speed * 0.1f; can be factorized to d_wanted = (target_speed - m_speed) * 0.1f; => d_wanted *= 0.1f;
-rw-r--r-- | src/localplayer.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 517cefe6e..62066bb18 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -713,36 +713,36 @@ void LocalPlayer::accelerateHorizontal(const v3f &target_speed, v3f d_wanted = target_speed - m_speed; if (slippery) { - if (target_speed == v3f(0)) + if (target_speed == v3f()) d_wanted = -m_speed * 0.05f; else - d_wanted = target_speed * 0.1f - m_speed * 0.1f; + d_wanted *= 0.1f; } - d_wanted.Y = 0; - f32 dl = d_wanted.getLength(); - if (dl > max_increase) - dl = max_increase; + d_wanted.Y = 0.0f; + f32 dl = d_wanted.getLength(); + if (dl > max_increase) + dl = max_increase; - v3f d = d_wanted.normalize() * dl; + v3f d = d_wanted.normalize() * dl; - m_speed.X += d.X; - m_speed.Z += d.Z; + m_speed.X += d.X; + m_speed.Z += d.Z; } // Vertical acceleration (Y), X and Z directions are ignored void LocalPlayer::accelerateVertical(const v3f &target_speed, const f32 max_increase) { - if (max_increase == 0) - return; + if (max_increase == 0) + return; - f32 d_wanted = target_speed.Y - m_speed.Y; - if (d_wanted > max_increase) - d_wanted = max_increase; - else if (d_wanted < -max_increase) - d_wanted = -max_increase; + f32 d_wanted = target_speed.Y - m_speed.Y; + if (d_wanted > max_increase) + d_wanted = max_increase; + else if (d_wanted < -max_increase) + d_wanted = -max_increase; - m_speed.Y += d_wanted; + m_speed.Y += d_wanted; } // Temporary option for old move code |