Skip to content

Commit fabefd8

Browse files
committed
[PlayerBox] Position fixed. It was needed because of precision PR.
1 parent 27fb5e9 commit fabefd8

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

client/include/graphics/PlayerBox.hpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,25 @@
2727
#ifndef PLAYERBOX_HPP_
2828
#define PLAYERBOX_HPP_
2929

30+
#include <gk/gl/Camera.hpp>
3031
#include <gk/gl/Drawable.hpp>
3132
#include <gk/gl/VertexBuffer.hpp>
3233
#include <gk/gl/Transformable.hpp>
3334

3435
#include "Player.hpp"
3536

36-
class PlayerBox : public gk::Drawable, public gk::Transformable, public Player {
37+
class PlayerBox : public gk::Drawable, public Player {
3738
public:
38-
PlayerBox();
39-
40-
void setPosition(float x, float y, float z) {
41-
gk::Transformable::setPosition(x, y, z);
42-
Player::setPosition(x, y, z);
43-
}
39+
PlayerBox(const gk::Camera &camera);
4440

4541
private:
4642
void updateVertexBuffer();
4743

4844
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
4945

5046
gk::VertexBuffer m_vbo;
47+
48+
const gk::Camera &m_camera;
5149
};
5250

5351
#endif // PLAYERBOX_HPP_

client/source/graphics/PlayerBox.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ static const float cubeCoords[6 * 4 * 3] = {
6666
0, 1, 1,
6767
};
6868

69-
PlayerBox::PlayerBox() {
70-
setScale(1, 1, 2);
71-
69+
PlayerBox::PlayerBox(const gk::Camera &camera) : m_camera(camera) {
7270
updateVertexBuffer();
7371
}
7472

@@ -77,7 +75,7 @@ void PlayerBox::updateVertexBuffer() {
7775
for (u8 i = 0 ; i < 24 ; ++i) {
7876
vertices[i].coord3d[0] = cubeCoords[i * 3];
7977
vertices[i].coord3d[1] = cubeCoords[i * 3 + 1];
80-
vertices[i].coord3d[2] = cubeCoords[i * 3 + 2] - 0.5;
78+
vertices[i].coord3d[2] = cubeCoords[i * 3 + 2] * 2 - 1;
8179
vertices[i].coord3d[3] = -1;
8280

8381
vertices[i].color[0] = 0.3f;
@@ -92,7 +90,9 @@ void PlayerBox::updateVertexBuffer() {
9290
}
9391

9492
void PlayerBox::draw(gk::RenderTarget &target, gk::RenderStates states) const {
95-
states.transform *= getTransform();
93+
// Subtract the camera position - see comment in ClientWorld::draw()
94+
gk::Vector3d cameraPosition = m_camera.getDPosition();
95+
states.transform.translate(m_x - cameraPosition.x, m_y - cameraPosition.y, m_z - cameraPosition.z);
9696

9797
target.draw(m_vbo, GL_QUADS, 0, 24, states);
9898
}

client/source/network/ClientCommandHandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void ClientCommandHandler::setupCallbacks() {
160160
packet >> clientId >> pos.x >> pos.y >> pos.z;
161161

162162
if (clientId != m_client.id()) {
163-
m_playerBoxes.emplace(clientId, PlayerBox{});
163+
m_playerBoxes.emplace(clientId, PlayerBox{m_player.camera()});
164164
m_playerBoxes.at(clientId).setPosition(pos.x, pos.y, pos.z);
165165
m_playerBoxes.at(clientId).setClientID(clientId);
166166
}

0 commit comments

Comments
 (0)