Modifications dans Player
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "player.h"
|
||||
#include "world.h"
|
||||
|
||||
Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) {
|
||||
m_velocity = Vector3f(0, 0, 0);
|
||||
@@ -66,19 +67,19 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
|
||||
/* Gestion de collisions */
|
||||
BlockType bt1, bt2, bt3;
|
||||
|
||||
bt1 = world.BlockAt(m_position.x, m_position.y + input.y, m_position.z);
|
||||
bt2 = world.BlockAt(m_position.x, m_position.y + input.y - 0.9f, m_position.z);
|
||||
bt3 = world.BlockAt(m_position.x, m_position.y + input.y - 1.7f, m_position.z);
|
||||
bt1 = world.BlockAt(GetPosition().x, GetPosition().y + input.y, GetPosition().z);
|
||||
bt2 = world.BlockAt(GetPosition().x, GetPosition().y + input.y - 0.9f, GetPosition().z);
|
||||
bt3 = world.BlockAt(GetPosition().x, GetPosition().y + input.y - 1.7f, GetPosition().z);
|
||||
if ((bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) && m_position.y < 129.7f) {
|
||||
bt1 = world.BlockAt(m_position.x, m_position.y + .3f, m_position.z);
|
||||
bt1 = world.BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z);
|
||||
if (bt1 == BTYPE_AIR) m_position.y = (int)m_position.y + .7f;
|
||||
m_velocity.y = input.y = 0;
|
||||
m_airborne = false;
|
||||
}
|
||||
else {
|
||||
if (abs(m_velocity.y) < 1.1f) m_velocity.y += input.y - 1.1f * elapsedTime;
|
||||
bt3 = world.BlockAt(m_position.x, m_position.y + m_velocity.y - 1.7f, m_position.z);
|
||||
bt1 = world.BlockAt(m_position.x, m_position.y + .3f, m_position.z);
|
||||
bt3 = world.BlockAt(GetPosition().x, GetPosition().y + m_velocity.y - 1.7f, GetPosition().z);
|
||||
bt1 = world.BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z);
|
||||
if (bt3 != BTYPE_AIR) {
|
||||
m_velocity.y = 0;
|
||||
m_airborne = false;
|
||||
@@ -89,17 +90,17 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
|
||||
else m_airborne = true;
|
||||
}
|
||||
|
||||
bt1 = world.BlockAt(m_position.x + input.x, m_position.y, m_position.z);
|
||||
bt2 = world.BlockAt(m_position.x + input.x, m_position.y - 0.9f, m_position.z);
|
||||
bt3 = world.BlockAt(m_position.x + input.x, m_position.y - 1.7f, m_position.z);
|
||||
bt1 = world.BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z);
|
||||
bt2 = world.BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z);
|
||||
bt3 = world.BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z);
|
||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
input.x = m_velocity.x = 0;
|
||||
m_velocity.z *= .5f;
|
||||
}
|
||||
|
||||
bt1 = world.BlockAt(m_position.x, m_position.y, m_position.z + input.z);
|
||||
bt2 = world.BlockAt(m_position.x, m_position.y - 0.9f, m_position.z + input.z);
|
||||
bt3 = world.BlockAt(m_position.x, m_position.y - 1.7f, m_position.z + input.z);
|
||||
bt1 = world.BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z);
|
||||
bt2 = world.BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z);
|
||||
bt3 = world.BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z);
|
||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
input.z = m_velocity.z = 0;
|
||||
m_velocity.x *= .5f;
|
||||
@@ -145,13 +146,20 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
|
||||
void Player::ApplyTransformation(Transformation& transformation, bool rel) const {
|
||||
transformation.ApplyRotation(-m_rotX, 1, 0, 0);
|
||||
transformation.ApplyRotation(-m_rotY, 0, 1, 0);
|
||||
if (rel) transformation.ApplyTranslation(-m_position.x,-m_POV,-m_position.z);
|
||||
if (rel) transformation.ApplyTranslation(-GetPOV());
|
||||
}
|
||||
|
||||
Vector3f Player::GetPosition() const { return m_position; }
|
||||
Vector3f Player::GetPosition() const { return Vector3f(m_position.x + CHUNK_SIZE_X * WORLD_SIZE_X / 2, m_position.y, m_position.z + CHUNK_SIZE_Z * WORLD_SIZE_Y / 2);
|
||||
}
|
||||
|
||||
Vector3f Player::GetVelocity() const { return m_velocity; }
|
||||
|
||||
Vector3f Player::GetPOV() const { return Vector3f(m_position.x, m_POV, m_position.z); }
|
||||
Vector3f Player::GetPOV() const { return Vector3f(GetPosition().x, m_POV, GetPosition().z); }
|
||||
|
||||
Vector3f Player::GetDirection() const { return m_direction; }
|
||||
|
||||
void Player::Transpose(int& x, int& z) {
|
||||
m_position.x -= x * CHUNK_SIZE_X;
|
||||
m_position.z -= z * CHUNK_SIZE_Z;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user