[PlayerBox] Position fixed. It was needed because of precision PR.
This commit is contained in:
parent
27fb5e935a
commit
fabefd81b4
@ -27,20 +27,16 @@
|
||||
#ifndef PLAYERBOX_HPP_
|
||||
#define PLAYERBOX_HPP_
|
||||
|
||||
#include <gk/gl/Camera.hpp>
|
||||
#include <gk/gl/Drawable.hpp>
|
||||
#include <gk/gl/VertexBuffer.hpp>
|
||||
#include <gk/gl/Transformable.hpp>
|
||||
|
||||
#include "Player.hpp"
|
||||
|
||||
class PlayerBox : public gk::Drawable, public gk::Transformable, public Player {
|
||||
class PlayerBox : public gk::Drawable, public Player {
|
||||
public:
|
||||
PlayerBox();
|
||||
|
||||
void setPosition(float x, float y, float z) {
|
||||
gk::Transformable::setPosition(x, y, z);
|
||||
Player::setPosition(x, y, z);
|
||||
}
|
||||
PlayerBox(const gk::Camera &camera);
|
||||
|
||||
private:
|
||||
void updateVertexBuffer();
|
||||
@ -48,6 +44,8 @@ class PlayerBox : public gk::Drawable, public gk::Transformable, public Player {
|
||||
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
|
||||
|
||||
gk::VertexBuffer m_vbo;
|
||||
|
||||
const gk::Camera &m_camera;
|
||||
};
|
||||
|
||||
#endif // PLAYERBOX_HPP_
|
||||
|
@ -66,9 +66,7 @@ static const float cubeCoords[6 * 4 * 3] = {
|
||||
0, 1, 1,
|
||||
};
|
||||
|
||||
PlayerBox::PlayerBox() {
|
||||
setScale(1, 1, 2);
|
||||
|
||||
PlayerBox::PlayerBox(const gk::Camera &camera) : m_camera(camera) {
|
||||
updateVertexBuffer();
|
||||
}
|
||||
|
||||
@ -77,7 +75,7 @@ void PlayerBox::updateVertexBuffer() {
|
||||
for (u8 i = 0 ; i < 24 ; ++i) {
|
||||
vertices[i].coord3d[0] = cubeCoords[i * 3];
|
||||
vertices[i].coord3d[1] = cubeCoords[i * 3 + 1];
|
||||
vertices[i].coord3d[2] = cubeCoords[i * 3 + 2] - 0.5;
|
||||
vertices[i].coord3d[2] = cubeCoords[i * 3 + 2] * 2 - 1;
|
||||
vertices[i].coord3d[3] = -1;
|
||||
|
||||
vertices[i].color[0] = 0.3f;
|
||||
@ -92,7 +90,9 @@ void PlayerBox::updateVertexBuffer() {
|
||||
}
|
||||
|
||||
void PlayerBox::draw(gk::RenderTarget &target, gk::RenderStates states) const {
|
||||
states.transform *= getTransform();
|
||||
// Subtract the camera position - see comment in ClientWorld::draw()
|
||||
gk::Vector3d cameraPosition = m_camera.getDPosition();
|
||||
states.transform.translate(m_x - cameraPosition.x, m_y - cameraPosition.y, m_z - cameraPosition.z);
|
||||
|
||||
target.draw(m_vbo, GL_QUADS, 0, 24, states);
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ void ClientCommandHandler::setupCallbacks() {
|
||||
packet >> clientId >> pos.x >> pos.y >> pos.z;
|
||||
|
||||
if (clientId != m_client.id()) {
|
||||
m_playerBoxes.emplace(clientId, PlayerBox{});
|
||||
m_playerBoxes.emplace(clientId, PlayerBox{m_player.camera()});
|
||||
m_playerBoxes.at(clientId).setPosition(pos.x, pos.y, pos.z);
|
||||
m_playerBoxes.at(clientId).setClientID(clientId);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user