mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 01:53:45 +01:00
Use mathematical function to determine yaw direction
This commit is contained in:
parent
6014e7257e
commit
7a532056e2
17
src/game.cpp
17
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];
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user