Use a local position variable for the camera

This makes it easier to change the camera position if necessary.
This commit is contained in:
Pedro Gimeno 2020-02-26 20:39:32 +01:00
parent 6483c5c846
commit 1af45d68c4
2 changed files with 7 additions and 3 deletions

View File

@ -94,10 +94,11 @@ class ClientPlayer : public Player {
double m_viewAngleH;
double m_viewAngleV;
double m_viewAngleRoll;
// TODO: Add model transform
gk::Vector3d m_forwardDir;
gk::Vector3d m_cameraLocalPos;
glm::dvec3 m_velocity{0};
bool m_isJumping = false;

View File

@ -41,6 +41,7 @@ ClientPlayer::ClientPlayer(gk::Camera &camera) : m_camera(camera) {
m_x = 14;
m_y = 14;
m_z = 18;
m_cameraLocalPos = gk::Vector3d{0., 0., 1.625};
m_viewAngleH = -90.;
m_viewAngleV = 0.01;
@ -48,7 +49,7 @@ ClientPlayer::ClientPlayer(gk::Camera &camera) : m_camera(camera) {
updateDir();
m_camera.setDPosition(m_x, m_y, m_z - 0.1);
m_camera.setDPosition(m_x + m_cameraLocalPos.x, m_y + m_cameraLocalPos.y, m_z + m_cameraLocalPos.z);
}
void ClientPlayer::turnH(double angle) {
@ -149,7 +150,9 @@ void ClientPlayer::setPosition(double x, double y, double z) {
m_z = z;
Player::setPosition(x, y, z);
m_camera.setDPosition(x, y, z - 0.1);
gk::Vector3d camPos = m_cameraLocalPos;
m_camera.setDPosition(m_x + camPos.x, m_y + camPos.y, m_z + camPos.z);
}
void ClientPlayer::checkCollisions(const ClientWorld &world) {