SQCSimulator2023/SQCSim2021/player.cpp
2021-09-27 13:15:57 -04:00

48 lines
1.5 KiB
C++

#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 * 10;
m_position.z += float(-cos(yrotrad)) * elapsedTime * 10;
m_position.y += float(-sin(xrotrad)) * elapsedTime * 10;
}
else if (back) {
yrotrad = (m_rotY / 180 * 3.141592654f);
xrotrad = (m_rotX / 180 * 3.141592654f);
m_position.x += float(-sin(yrotrad)) * elapsedTime * 10;
m_position.z += float(cos(yrotrad)) * elapsedTime * 10;
m_position.y += float(sin(xrotrad)) * elapsedTime * 10;
}
if (left) {
yrotrad = (m_rotY / 180 * 3.141592654f);
m_position.x += float(-cos(yrotrad)) * elapsedTime * 10;
m_position.z += float(-sin(yrotrad)) * elapsedTime * 10;
}
else if (right) {
yrotrad = (m_rotY / 180 * 3.141592654f);
m_position.x += float(cos(yrotrad)) * elapsedTime * 10;
m_position.z += float(sin(yrotrad)) * elapsedTime * 10;
}
}
void Player::ApplyTransformation(Transformation& transformation) const {
transformation.ApplyRotation(-m_rotX, 1.f, 0, 0);
transformation.ApplyRotation(-m_rotY, 0, 1.f, 0);
transformation.ApplyTranslation(-m_position);
}