feat: gravite dans toutes les directions
This commit is contained in:
parent
ebccd2cf68
commit
56ed2d1d5f
@ -740,7 +740,7 @@ bool ApplicationClass::Frame(InputClass* Input)
|
|||||||
object->SetPosition(XMVectorSetY(currentPosition, 20.0f)); // Define the new position of the object
|
object->SetPosition(XMVectorSetY(currentPosition, 20.0f)); // Define the new position of the object
|
||||||
}
|
}
|
||||||
m_Physics->ApplyGravity(object, frameTime);
|
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
|
// Update object position based on its velocity
|
||||||
XMVECTOR position = object->GetPosition();
|
XMVECTOR position = object->GetPosition();
|
||||||
XMVECTOR velocity = object->GetVelocity();
|
XMVECTOR velocity = object->GetVelocity();
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
#include "physics.h"
|
#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)
|
Physics::Physics(const Physics& other)
|
||||||
@ -16,13 +15,13 @@ Physics::~Physics()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the gravity value
|
// Get the gravity value
|
||||||
float Physics::GetGravity()
|
XMVECTOR Physics::GetGravity()
|
||||||
{
|
{
|
||||||
return m_gravity;
|
return m_gravity;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the gravity value
|
// Define the gravity value
|
||||||
void Physics::SetGravity(float gravity)
|
void Physics::SetGravity(XMVECTOR gravity)
|
||||||
{
|
{
|
||||||
m_gravity = gravity;
|
m_gravity = gravity;
|
||||||
}
|
}
|
||||||
@ -38,8 +37,8 @@ void Physics::ApplyGravity(Object* object, float frameTime)
|
|||||||
// Get the object velocity
|
// Get the object velocity
|
||||||
XMVECTOR velocity = object->GetVelocity();
|
XMVECTOR velocity = object->GetVelocity();
|
||||||
|
|
||||||
// Update the Y component of the velocity
|
// Update the velocity with gravity
|
||||||
velocity = XMVectorSetY(velocity, XMVectorGetY(velocity) + m_gravity * frameTime);
|
velocity += m_gravity * frameTime;
|
||||||
|
|
||||||
// Set the new velocity
|
// Set the new velocity
|
||||||
object->SetVelocity(velocity);
|
object->SetVelocity(velocity);
|
||||||
|
@ -10,14 +10,13 @@ public:
|
|||||||
explicit Physics(const Physics&); // Use explicit to avoid implicit conversion
|
explicit Physics(const Physics&); // Use explicit to avoid implicit conversion
|
||||||
~Physics();
|
~Physics();
|
||||||
|
|
||||||
float GetGravity(); // Get the gravity value
|
XMVECTOR GetGravity(); // Get the gravity value
|
||||||
void SetGravity(float gravity); // Define the gravity value
|
void SetGravity(XMVECTOR gravity); // Define the gravity value
|
||||||
void ApplyGravity(Object*, float); // Apply gravity to an object
|
void ApplyGravity(Object*, float); // Apply gravity to an object
|
||||||
void ApplyDrag(Object*, float, float);
|
void ApplyDrag(Object*, float, float);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float m_gravity;
|
XMVECTOR m_gravity;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user