feat: gravite dans toutes les directions

This commit is contained in:
StratiX0 2024-04-09 12:52:32 +02:00
parent ebccd2cf68
commit 56ed2d1d5f
3 changed files with 9 additions and 11 deletions

View File

@ -740,7 +740,7 @@ bool ApplicationClass::Frame(InputClass* Input)
object->SetPosition(XMVectorSetY(currentPosition, 20.0f)); // Define the new position of the object
}
m_Physics->ApplyGravity(object, frameTime);
m_Physics->ApplyDrag(object, 0.1f, frameTime);
m_Physics->ApplyDrag(object, 1.0f, frameTime);
// Update object position based on its velocity
XMVECTOR position = object->GetPosition();
XMVECTOR velocity = object->GetVelocity();

View File

@ -1,9 +1,8 @@
#include "physics.h"
Physics::Physics()
Physics::Physics() : m_gravity(XMVectorSet(0.0f, -9.81f, 0.0f, 0.0f)) // Initialize the gravity vector
{
m_gravity = -9.81f; // Initilize the gravity value
}
Physics::Physics(const Physics& other)
@ -16,13 +15,13 @@ Physics::~Physics()
}
// Get the gravity value
float Physics::GetGravity()
XMVECTOR Physics::GetGravity()
{
return m_gravity;
}
// Define the gravity value
void Physics::SetGravity(float gravity)
void Physics::SetGravity(XMVECTOR gravity)
{
m_gravity = gravity;
}
@ -38,8 +37,8 @@ void Physics::ApplyGravity(Object* object, float frameTime)
// Get the object velocity
XMVECTOR velocity = object->GetVelocity();
// Update the Y component of the velocity
velocity = XMVectorSetY(velocity, XMVectorGetY(velocity) + m_gravity * frameTime);
// Update the velocity with gravity
velocity += m_gravity * frameTime;
// Set the new velocity
object->SetVelocity(velocity);

View File

@ -10,14 +10,13 @@ public:
explicit Physics(const Physics&); // Use explicit to avoid implicit conversion
~Physics();
float GetGravity(); // Get the gravity value
void SetGravity(float gravity); // Define the gravity value
XMVECTOR GetGravity(); // Get the gravity value
void SetGravity(XMVECTOR gravity); // Define the gravity value
void ApplyGravity(Object*, float); // Apply gravity to an object
void ApplyDrag(Object*, float, float);
private:
float m_gravity;
XMVECTOR m_gravity;
};
#endif