diff --git a/src/game/entity.cpp b/src/game/entity.cpp index 6a16b00..5755507 100644 --- a/src/game/entity.cpp +++ b/src/game/entity.cpp @@ -74,13 +74,13 @@ void game::Entity::Move(glm::vec3& velocity, float dt) { // Primary occurrence hit firstly hit_fraction = occu_hit_fraction; - hit_normal = occu_->inv_basis_ * occu_hit_normal; + hit_normal = occu_->inv_normal_basis_ * occu_hit_normal; } else if (other_hit) { // Other occurrence hit firstly hit_fraction = other_hit_fraction; - hit_normal = other_occu_->inv_basis_ * other_hit_normal; + hit_normal = other_occu_->inv_normal_basis_ * other_hit_normal; } // Update the position based on the hit fraction @@ -153,6 +153,14 @@ game::EntityOccurrence::EntityOccurrence(Entity* entity, const CreateOccurrenceP bt_capsule_(entity->GetCapsuleShape().radius * params.scale, entity->GetCapsuleShape().height * params.scale) { + // compute normalized basis + for (size_t i = 0; i < 3; ++i) + { + normal_basis_[i] = glm::normalize(basis_[i]); + } + + // compute inverse normalized basis + inv_normal_basis_ = glm::inverse(normal_basis_); } bool game::EntityOccurrence::Sweep(const glm::vec3& target_position, float& hit_fraction, glm::vec3& hit_normal, const Portal** hit_portal) @@ -169,7 +177,7 @@ bool game::EntityOccurrence::Sweep(const glm::vec3& target_position, float& hit_ return sector_->SweepCapsule( bt_capsule_, - basis_, + normal_basis_, position_, target_position, hit_fraction, diff --git a/src/game/entity.hpp b/src/game/entity.hpp index 04e07aa..0a4b345 100644 --- a/src/game/entity.hpp +++ b/src/game/entity.hpp @@ -30,9 +30,12 @@ namespace game glm::vec3 position_; float scale_; - glm::mat3 basis_; // Orthonormal basis in sector space + glm::mat3 basis_; // Orthogonal basis in sector space glm::mat3 inv_basis_; + glm::mat3 normal_basis_; // Normalized basis for collision detection + glm::mat3 inv_normal_basis_; + btCapsuleShapeZ bt_capsule_; friend class Entity; diff --git a/src/game/player.cpp b/src/game/player.cpp index 67ff3f3..339d5e5 100644 --- a/src/game/player.cpp +++ b/src/game/player.cpp @@ -87,7 +87,7 @@ void game::Player::Update(float dt) glm::vec3 velocity = glm::vec3( velocity_xy, - -1.0f // No vertical movement for now + velocity_.z - gravity_ * dt // No vertical movement for now ); velocity_ = velocity; diff --git a/src/game/player.hpp b/src/game/player.hpp index 4dea2eb..88e366d 100644 --- a/src/game/player.hpp +++ b/src/game/player.hpp @@ -20,6 +20,7 @@ namespace game float max_speed_ = 4.0f; float acceleration_ = 50.0f; float deceleration_ = 20.0f; + float gravity_ = 9.81f; // Gravity acceleration float time_ = 0.0f; float current_speed_ = 0.0f;