2021-09-27 13:15:57 -04:00
|
|
|
#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);
|
2021-09-28 18:50:28 -04:00
|
|
|
m_position.x += float(sin(yrotrad)) * elapsedTime * 20;
|
|
|
|
m_position.z += float(-cos(yrotrad)) * elapsedTime * 20;
|
|
|
|
m_position.y += float(-sin(xrotrad)) * elapsedTime * 20;
|
2021-09-27 13:15:57 -04:00
|
|
|
}
|
|
|
|
else if (back) {
|
|
|
|
yrotrad = (m_rotY / 180 * 3.141592654f);
|
|
|
|
xrotrad = (m_rotX / 180 * 3.141592654f);
|
2021-09-28 18:50:28 -04:00
|
|
|
m_position.x += float(-sin(yrotrad)) * elapsedTime * 20;
|
|
|
|
m_position.z += float(cos(yrotrad)) * elapsedTime * 20;
|
|
|
|
m_position.y += float(sin(xrotrad)) * elapsedTime * 20;
|
2021-09-27 13:15:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (left) {
|
|
|
|
yrotrad = (m_rotY / 180 * 3.141592654f);
|
2021-09-28 18:50:28 -04:00
|
|
|
m_position.x += float(-cos(yrotrad)) * elapsedTime * 20;
|
|
|
|
m_position.z += float(-sin(yrotrad)) * elapsedTime * 20;
|
2021-09-27 13:15:57 -04:00
|
|
|
}
|
|
|
|
else if (right) {
|
|
|
|
yrotrad = (m_rotY / 180 * 3.141592654f);
|
2021-09-28 18:50:28 -04:00
|
|
|
m_position.x += float(cos(yrotrad)) * elapsedTime * 20;
|
|
|
|
m_position.z += float(sin(yrotrad)) * elapsedTime * 20;
|
2021-09-27 13:15:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-27 13:56:29 -04:00
|
|
|
void Player::ApplyTransformation(Transformation& transformation, bool rel) const {
|
2021-09-27 13:15:57 -04:00
|
|
|
transformation.ApplyRotation(-m_rotX, 1.f, 0, 0);
|
|
|
|
transformation.ApplyRotation(-m_rotY, 0, 1.f, 0);
|
2021-09-27 13:56:29 -04:00
|
|
|
if (rel) transformation.ApplyTranslation(-m_position);
|
2021-09-27 13:15:57 -04:00
|
|
|
}
|