#include "player.h" Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) { } void Player::TurnLeftRight(float value) { m_rotX += value; } void Player::TurnTopBottom(float value) { m_rotY += value; } void Player::Move(bool front, bool back, bool left, bool right, float elapsedTime) { float xrotrad, yrotrad; if (front) { yrotrad = (m_rotY / 180 * 3.141592654f); xrotrad = (m_rotX / 180 * 3.141592654f); m_position.x += float(sin(yrotrad)) * elapsedTime * 20; m_position.z += float(-cos(yrotrad)) * elapsedTime * 20; m_position.y += float(-sin(xrotrad)) * elapsedTime * 20; } else if (back) { yrotrad = (m_rotY / 180 * 3.141592654f); xrotrad = (m_rotX / 180 * 3.141592654f); m_position.x += float(-sin(yrotrad)) * elapsedTime * 20; m_position.z += float(cos(yrotrad)) * elapsedTime * 20; m_position.y += float(sin(xrotrad)) * elapsedTime * 20; } if (left) { yrotrad = (m_rotY / 180 * 3.141592654f); m_position.x += float(-cos(yrotrad)) * elapsedTime * 20; m_position.z += float(-sin(yrotrad)) * elapsedTime * 20; } else if (right) { yrotrad = (m_rotY / 180 * 3.141592654f); m_position.x += float(cos(yrotrad)) * elapsedTime * 20; m_position.z += float(sin(yrotrad)) * elapsedTime * 20; } } void Player::ApplyTransformation(Transformation& transformation, bool rel) const { transformation.ApplyRotation(-m_rotX, 1.f, 0, 0); transformation.ApplyRotation(-m_rotY, 0, 1.f, 0); if (rel) transformation.ApplyTranslation(-m_position); }