summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2016-06-20 18:11:05 +0200
committerest31 <MTest31@outlook.com>2016-07-05 20:36:05 +0200
commit7a532056e29d00006382caad9ccde66e54ca8aa5 (patch)
tree8f2f32729ee5f0ff07b5e9b5657ba1a734487ef8 /src/game.cpp
parent6014e7257e1052b8a4b3e29793aaf296b94b80d7 (diff)
downloadminetest-7a532056e29d00006382caad9ccde66e54ca8aa5.tar.gz
minetest-7a532056e29d00006382caad9ccde66e54ca8aa5.tar.bz2
minetest-7a532056e29d00006382caad9ccde66e54ca8aa5.zip
Use mathematical function to determine yaw direction
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp17
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];
}