Skip to content

Commit

Permalink
Use mathematical function to determine yaw direction
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 authored and est31 committed Jul 5, 2016
1 parent 6014e72 commit 7a53205
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/game.cpp
Expand Up @@ -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];
}


Expand Down

0 comments on commit 7a53205

Please sign in to comment.