Fix collision of scaled entities
This commit is contained in:
parent
edee72e4b8
commit
ccc275c0f6
@ -74,13 +74,13 @@ void game::Entity::Move(glm::vec3& velocity, float dt)
|
|||||||
{
|
{
|
||||||
// Primary occurrence hit firstly
|
// Primary occurrence hit firstly
|
||||||
hit_fraction = occu_hit_fraction;
|
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)
|
else if (other_hit)
|
||||||
{
|
{
|
||||||
// Other occurrence hit firstly
|
// Other occurrence hit firstly
|
||||||
hit_fraction = other_hit_fraction;
|
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
|
// 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)
|
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)
|
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(
|
return sector_->SweepCapsule(
|
||||||
bt_capsule_,
|
bt_capsule_,
|
||||||
basis_,
|
normal_basis_,
|
||||||
position_,
|
position_,
|
||||||
target_position,
|
target_position,
|
||||||
hit_fraction,
|
hit_fraction,
|
||||||
|
|||||||
@ -30,9 +30,12 @@ namespace game
|
|||||||
glm::vec3 position_;
|
glm::vec3 position_;
|
||||||
|
|
||||||
float scale_;
|
float scale_;
|
||||||
glm::mat3 basis_; // Orthonormal basis in sector space
|
glm::mat3 basis_; // Orthogonal basis in sector space
|
||||||
glm::mat3 inv_basis_;
|
glm::mat3 inv_basis_;
|
||||||
|
|
||||||
|
glm::mat3 normal_basis_; // Normalized basis for collision detection
|
||||||
|
glm::mat3 inv_normal_basis_;
|
||||||
|
|
||||||
btCapsuleShapeZ bt_capsule_;
|
btCapsuleShapeZ bt_capsule_;
|
||||||
|
|
||||||
friend class Entity;
|
friend class Entity;
|
||||||
|
|||||||
@ -87,7 +87,7 @@ void game::Player::Update(float dt)
|
|||||||
|
|
||||||
glm::vec3 velocity = glm::vec3(
|
glm::vec3 velocity = glm::vec3(
|
||||||
velocity_xy,
|
velocity_xy,
|
||||||
-1.0f // No vertical movement for now
|
velocity_.z - gravity_ * dt // No vertical movement for now
|
||||||
);
|
);
|
||||||
|
|
||||||
velocity_ = velocity;
|
velocity_ = velocity;
|
||||||
|
|||||||
@ -20,6 +20,7 @@ namespace game
|
|||||||
float max_speed_ = 4.0f;
|
float max_speed_ = 4.0f;
|
||||||
float acceleration_ = 50.0f;
|
float acceleration_ = 50.0f;
|
||||||
float deceleration_ = 20.0f;
|
float deceleration_ = 20.0f;
|
||||||
|
float gravity_ = 9.81f; // Gravity acceleration
|
||||||
|
|
||||||
float time_ = 0.0f;
|
float time_ = 0.0f;
|
||||||
float current_speed_ = 0.0f;
|
float current_speed_ = 0.0f;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user