Skip to content

Commit

Permalink
[DebugOverlay] Now displaying player direction and angle.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Mar 1, 2020
1 parent a9da012 commit c1becd9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions client/source/hud/DebugOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ void DebugOverlay::update() {
s32 py = std::floor(m_player.y());
s32 pz = std::floor(m_player.z());

const char *directions[5] = {"West", "East", "South", "North"};
const char *direction = directions[m_player.getDirection()];

std::stringstream stream;
stream << "x: " << px << " | ";
stream << "y: " << py << " | ";
Expand All @@ -61,6 +64,8 @@ void DebugOverlay::update() {
stream << "cy: " << (py & -CHUNK_DEPTH) / CHUNK_DEPTH << " | ";
stream << "cz: " << (pz & -CHUNK_HEIGHT) / CHUNK_HEIGHT;
stream << '\n';
stream << "dir: " << direction << " (" << m_player.viewAngleH() << ")";
stream << '\n';
stream << "Loaded chunks: " << m_world.loadedChunkCount();

m_positionText.setText(stream.str());
Expand Down
16 changes: 16 additions & 0 deletions client/source/world/ClientPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void ClientPlayer::turnH(double angle) {
m_viewAngleH + angle : fmod(m_viewAngleH + angle, 360.);

if (m_viewAngleH >= 180.) m_viewAngleH -= 360.;
if (m_viewAngleH <= -180.) m_viewAngleH += 360.; // FIXME: Temporary fix, needs review

updateDir();
}
Expand All @@ -67,6 +68,21 @@ void ClientPlayer::turnViewV(double angle) {
updateDir();
}

u8 ClientPlayer::getDirection() const {
if (m_viewAngleH >= -45. && m_viewAngleH <= 45.) {
return West;
}
else if (m_viewAngleH >= -135. && m_viewAngleH <= -45.) {
return North;
}
else if (m_viewAngleH <= -135. || m_viewAngleH >= 135.) {
return East;
}
else {
return South;
}
}

void ClientPlayer::updateDir() {
double ch = cos(m_viewAngleH * RADIANS_PER_DEGREES);
double sh = sin(m_viewAngleH * RADIANS_PER_DEGREES);
Expand Down
4 changes: 4 additions & 0 deletions client/source/world/ClientPlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class ClientPlayer : public Player {
void turnH(double angle);
void turnViewV(double angle);

// West, East, South, North
u8 getDirection() const;
double viewAngleH() const { return m_viewAngleH; }

void move(double direction);

void processInputs();
Expand Down

0 comments on commit c1becd9

Please sign in to comment.