diff options
author | sfan5 <sfan5@live.de> | 2016-06-20 18:11:05 +0200 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2016-07-05 20:36:05 +0200 |
commit | 7a532056e29d00006382caad9ccde66e54ca8aa5 (patch) | |
tree | 8f2f32729ee5f0ff07b5e9b5657ba1a734487ef8 /src | |
parent | 6014e7257e1052b8a4b3e29793aaf296b94b80d7 (diff) | |
download | minetest-7a532056e29d00006382caad9ccde66e54ca8aa5.tar.gz minetest-7a532056e29d00006382caad9ccde66e54ca8aa5.tar.bz2 minetest-7a532056e29d00006382caad9ccde66e54ca8aa5.zip |
Use mathematical function to determine yaw direction
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/src/game.cpp b/src/game.cpp index 93d9e6d2c..9b9f3a75f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -4298,23 +4298,12 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, inline static const char *yawToDirectionString(int yaw) { - // NOTE: TODO: This can be done mathematically without the else/else-if - // cascade. - - const char *player_direction; + static const char *direction[4] = {"North [+Z]", "West [-X]", "South [-Z]", "East [+X]"}; yaw = wrapDegrees_0_360(yaw); + yaw = (yaw + 45) % 360 / 90; - if (yaw >= 45 && yaw < 135) - player_direction = "West [-X]"; - else if (yaw >= 135 && yaw < 225) - player_direction = "South [-Z]"; - else if (yaw >= 225 && yaw < 315) - player_direction = "East [+X]"; - else - player_direction = "North [+Z]"; - - return player_direction; + return direction[yaw]; } |