Ajout collision avec le terrain, mais tres bancale
feat: + les cubes ajoutes s'arretent lorsqu'il y a collision avec le terrain, seulement sur un seul chunk
This commit is contained in:
@@ -72,4 +72,35 @@ void Physics::ApplyForce(Object* object, XMVECTOR force)
|
||||
|
||||
// Add the acceleration to the object's current acceleration
|
||||
object->SetAcceleration(object->GetAcceleration() + acceleration);
|
||||
}
|
||||
}
|
||||
|
||||
bool Physics::IsColliding(Object* object1, Object* object2)
|
||||
{
|
||||
|
||||
if (object1 == nullptr || object2 == nullptr) // Verify if the objects are not null
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the positions of the two objects
|
||||
XMVECTOR position1 = object1->GetPosition();
|
||||
XMVECTOR position2 = object2->GetPosition();
|
||||
|
||||
// Get the scale of the two objects (assuming the scale represents the size of the cube)
|
||||
XMVECTOR scale1 = object1->GetScale();
|
||||
XMVECTOR scale2 = object2->GetScale();
|
||||
|
||||
// Calculate the min and max coordinates of the two cubes
|
||||
XMVECTOR min1 = position1 - scale1 / 2.0f;
|
||||
XMVECTOR max1 = position1 + scale1 / 2.0f;
|
||||
XMVECTOR min2 = position2 - scale2 / 2.0f;
|
||||
XMVECTOR max2 = position2 + scale2 / 2.0f;
|
||||
|
||||
// Check if the two cubes overlap on all three axes
|
||||
bool overlapX = max1.m128_f32[0] > min2.m128_f32[0] && min1.m128_f32[0] < max2.m128_f32[0];
|
||||
bool overlapY = max1.m128_f32[1] > min2.m128_f32[1] && min1.m128_f32[1] < max2.m128_f32[1];
|
||||
bool overlapZ = max1.m128_f32[2] > min2.m128_f32[2] && min1.m128_f32[2] < max2.m128_f32[2];
|
||||
|
||||
// If the cubes overlap on all three axes, they are colliding
|
||||
return overlapX && overlapY && overlapZ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user