Iiiiiiiii don't wanna fly!
This commit is contained in:
parent
bce97c3480
commit
62caee0196
@ -66,7 +66,7 @@ void Engine::Render(float elapsedTime)
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
m_player.Move(m_keyW, m_keyS, m_keyA, m_keyD, elapsedTime);
|
||||
m_player.Move(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, elapsedTime);
|
||||
m_player.ApplyTransformation(all);
|
||||
m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!).
|
||||
|
||||
@ -256,6 +256,12 @@ void Engine::KeyPressEvent(unsigned char key)
|
||||
m_keyD = true;
|
||||
}
|
||||
break;
|
||||
case 57: // Space
|
||||
if (!m_keySpace) {
|
||||
std::cout << "Jump! " << std::endl;
|
||||
m_keySpace = true;
|
||||
}
|
||||
break;
|
||||
case 24: // Y - Ignorer
|
||||
case 255: // Fn - Ignorer
|
||||
break;
|
||||
@ -291,6 +297,10 @@ void Engine::KeyReleaseEvent(unsigned char key)
|
||||
std::cout << "rD " << std::endl;
|
||||
m_keyD = false;
|
||||
break;
|
||||
case 57:
|
||||
std::cout << "rSpace " << std::endl;
|
||||
m_keySpace = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ private:
|
||||
bool m_keyA = false;
|
||||
bool m_keyS = false;
|
||||
bool m_keyD = false;
|
||||
bool m_keySpace = false;
|
||||
};
|
||||
|
||||
#endif // ENGINE_H__
|
||||
|
@ -152,7 +152,7 @@ void OpenglContext::ShowCrossCursor() const
|
||||
|
||||
void OpenglContext::InitWindow(int width, int height)
|
||||
{
|
||||
m_app.create(sf::VideoMode(width, height, 32), m_title.c_str(), m_fullscreen ? sf::Style::Fullscreen : (sf::Style::Resize|sf::Style::Close), sf::ContextSettings(32, 8, 0));
|
||||
m_app.create((m_fullscreen ? sf::VideoMode::getFullscreenModes()[0] : sf::VideoMode(width, height, 32)), m_title.c_str(), m_fullscreen ? sf::Style::Fullscreen : (sf::Style::Resize | sf::Style::Close), sf::ContextSettings(32, 8, 0));
|
||||
}
|
||||
|
||||
OpenglContext::MOUSE_BUTTON OpenglContext::ConvertMouseButton(sf::Mouse::Button button) const
|
||||
|
@ -4,44 +4,100 @@ Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(po
|
||||
|
||||
void Player::TurnLeftRight(float value) {
|
||||
m_rotX += value;
|
||||
if (m_rotX > 45) m_rotX = 45;
|
||||
else if (m_rotX < -45) m_rotX = -45;
|
||||
}
|
||||
|
||||
void Player::TurnTopBottom(float value) {
|
||||
m_rotY += value;
|
||||
m_rotY += value;
|
||||
}
|
||||
|
||||
void Player::Move(bool front, bool back, bool left, bool right, float elapsedTime) {
|
||||
void Player::Move(bool front, bool back, bool left, bool right, bool jump, float elapsedTime) {
|
||||
float xrotrad, yrotrad;
|
||||
|
||||
if (m_accjmp == 0 && jump && !jumped) {
|
||||
m_accjmp = 0.3;
|
||||
jumped = true;
|
||||
}
|
||||
else if (m_position.y > -0.2f && m_accjmp != 0)
|
||||
if (m_accjmp > 0.1f) {
|
||||
if (jump) {
|
||||
m_accjmp *= 0.95 - m_accjmp * elapsedTime;
|
||||
m_accjmp -= elapsedTime * 1.1;
|
||||
}
|
||||
else {
|
||||
m_accjmp *= 0.75 - m_accjmp * elapsedTime;
|
||||
m_accjmp -= elapsedTime * 1.1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (jump) m_accjmp -= elapsedTime* 0.7;
|
||||
else m_accjmp -= elapsedTime*0.9;
|
||||
}
|
||||
else m_accjmp = 0;
|
||||
|
||||
if (!jump) jumped = false;
|
||||
|
||||
if (m_position.y < 0) {
|
||||
m_position.y += elapsedTime * 5;
|
||||
if (m_position.y > 0.f) m_position.y = 0;
|
||||
}
|
||||
|
||||
m_position.y += m_accjmp;
|
||||
|
||||
if (front) {
|
||||
if (m_accWS < 10) m_accWS += elapsedTime * 30; else m_accWS = 10;
|
||||
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;
|
||||
m_position.x += float(sin(yrotrad)) * elapsedTime * m_accWS;
|
||||
m_position.z += float(-cos(yrotrad)) * elapsedTime * m_accWS;
|
||||
// m_position.y += float(-sin(xrotrad)) * elapsedTime * 20; // à remettre pour implémenter une fonction de vol.
|
||||
}
|
||||
else if (back) {
|
||||
if (m_accWS > -10) m_accWS -= elapsedTime * 30; else m_accWS = -10;
|
||||
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;
|
||||
m_position.x += float(-sin(yrotrad)) * elapsedTime * -m_accWS;
|
||||
m_position.z += float(cos(yrotrad)) * elapsedTime * -m_accWS;
|
||||
// m_position.y += float(sin(xrotrad)) * elapsedTime * 20; // à remettre pour implémenter une fonction de vol.
|
||||
}
|
||||
else if (m_accWS != 0) {
|
||||
m_accWS = m_accWS > 0 ? m_accWS - elapsedTime * 60 : m_accWS + elapsedTime * 60;
|
||||
yrotrad = (m_rotY / 180 * 3.141592654f);
|
||||
xrotrad = (m_rotX / 180 * 3.141592654f);
|
||||
m_position.x += float(sin(yrotrad)) * elapsedTime * m_accWS;
|
||||
m_position.z += float(-cos(yrotrad)) * elapsedTime * m_accWS;
|
||||
if (m_accWS < 1 && m_accWS > -1) m_accWS = 0;
|
||||
}
|
||||
|
||||
if (left) {
|
||||
if (m_accAD < 10) m_accAD += elapsedTime * 30; else m_accAD = 10;
|
||||
yrotrad = (m_rotY / 180 * 3.141592654f);
|
||||
m_position.x += float(-cos(yrotrad)) * elapsedTime * 20;
|
||||
m_position.z += float(-sin(yrotrad)) * elapsedTime * 20;
|
||||
m_position.x += float(-cos(yrotrad)) * elapsedTime * m_accAD;
|
||||
m_position.z += float(-sin(yrotrad)) * elapsedTime * m_accAD;
|
||||
}
|
||||
else if (right) {
|
||||
if (m_accAD > -10) m_accAD -= elapsedTime * 30; else m_accAD = -10;
|
||||
yrotrad = (m_rotY / 180 * 3.141592654f);
|
||||
m_position.x += float(cos(yrotrad)) * elapsedTime * 20;
|
||||
m_position.z += float(sin(yrotrad)) * elapsedTime * 20;
|
||||
m_position.x += float(cos(yrotrad)) * elapsedTime * -m_accAD;
|
||||
m_position.z += float(sin(yrotrad)) * elapsedTime * -m_accAD;
|
||||
}
|
||||
else if (m_accAD != 0) {
|
||||
m_accAD = m_accAD > 0 ? m_accAD - elapsedTime * 60 : m_accAD + elapsedTime * 60;
|
||||
yrotrad = (m_rotY / 180 * 3.141592654f);
|
||||
m_position.x += float(-cos(yrotrad)) * elapsedTime * m_accAD;
|
||||
m_position.z += float(-sin(yrotrad)) * elapsedTime * m_accAD;
|
||||
if (m_accAD < 1 && m_accAD > -1) m_accAD = 0;
|
||||
}
|
||||
|
||||
if ((m_accWS >= 0? m_accWS: -m_accWS + m_accAD >= 0 ? m_accAD : -m_accAD) > 12) {
|
||||
m_accWS *= 0.9;
|
||||
m_accAD *= 0.9;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::ApplyTransformation(Transformation& transformation, bool rel) const {
|
||||
transformation.ApplyRotation(-m_rotX, 1.f, 0, 0);
|
||||
transformation.ApplyRotation(-m_rotY, 0, 1.f, 0);
|
||||
transformation.ApplyRotation(-m_rotX, 1, 0, 0);
|
||||
transformation.ApplyRotation(-m_rotY, 0, 1, 0);
|
||||
if (rel) transformation.ApplyTranslation(-m_position);
|
||||
}
|
||||
|
@ -8,13 +8,17 @@ public:
|
||||
Player(const Vector3f& position, float rotX = 0, float rotY = 0);
|
||||
void TurnLeftRight(float value);
|
||||
void TurnTopBottom(float value);
|
||||
void Move(bool front, bool back, bool left, bool right, float elapsedTime);
|
||||
void Move(bool front, bool back, bool left, bool right, bool jump, float elapsedTime);
|
||||
void ApplyTransformation(Transformation& transformation, bool rel = true) const;
|
||||
|
||||
private:
|
||||
Vector3f m_position;
|
||||
float m_rotX = 0;
|
||||
float m_rotY = 0;
|
||||
float m_accWS = 0;
|
||||
float m_accAD = 0;
|
||||
float m_accjmp = 0;
|
||||
bool jumped = false;
|
||||
};
|
||||
#endif //_PLAYER_H__
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user