feat: simplification gravite, respawn

This commit is contained in:
StratiX0 2024-04-08 17:32:10 +02:00
parent 6eb50bf29f
commit b37f253c5c
3 changed files with 42 additions and 20 deletions

View File

@ -397,6 +397,13 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
void ApplicationClass::Shutdown() void ApplicationClass::Shutdown()
{ {
// Release the physics object.
if (m_Physics)
{
delete m_Physics;
m_Physics = 0;
}
// Release the frustum class object. // Release the frustum class object.
if (m_Frustum) if (m_Frustum)
{ {
@ -722,11 +729,17 @@ bool ApplicationClass::Frame(InputClass* Input)
//z -= 0.0174532925f * 0.2f; //z -= 0.0174532925f * 0.2f;
for (auto object : m_object) for (auto object : m_object)
{
if (object != nullptr) // Vérifie que l'objet n'est pas nullptr
{ {
m_Physics->ApplyGravity(object, frameTime); m_Physics->ApplyGravity(object, frameTime);
if (XMVectorGetY(object->GetPosition()) < -10.0f) if (XMVectorGetY(object->GetPosition()) < -10.0f)
{ {
object->SetPosition(XMVectorSet(0.0f, 20.0f, 0.0f, 0.0f)); // Obtenez la position actuelle de l'objet
XMVECTOR currentPosition = object->GetPosition();
// Définissez la nouvelle position y tout en conservant les positions x et z actuelles
object->SetPosition(XMVectorSetY(currentPosition, 20.0f));
}
} }
} }

View File

@ -1,32 +1,42 @@
#include "physics.h" #include "physics.h"
Physics::Physics() Physics::Physics()
{ {
m_gravity = -9.81f; m_gravity = -9.81f; // Initilize the gravity value
} }
Physics::Physics(const Physics& other) Physics::Physics(const Physics& other)
{ {
m_gravity = other.m_gravity; // Copy gravity value from the other object m_gravity = other.m_gravity; // Copy the gravity value
} }
Physics::~Physics() Physics::~Physics()
{ {
} }
float Physics::GetGravity() // Changed the method to return the gravity value // Get the gravity value
float Physics::GetGravity()
{ {
return m_gravity; return m_gravity;
} }
// Define the gravity value
void Physics::SetGravity(float gravity)
{
m_gravity = gravity;
}
// Apply gravity to an object
void Physics::ApplyGravity(Object* object, float frameTime) void Physics::ApplyGravity(Object* object, float frameTime)
{ {
// Update the position of the object by adding the change in position due to gravity. if (object == nullptr) // Verify if the object is not null
XMVECTOR position = object->GetPosition(); // Get the current position {
position = XMVectorSetY(position, XMVectorGetY(position) + m_gravity * frameTime); // Update the y value
object->SetPosition(position); // Set the updated position
return; return;
}
// Update the object position
XMVECTOR position = object->GetPosition();
position = XMVectorSetY(position, XMVectorGetY(position) + m_gravity * frameTime); // Update the Y position
object->SetPosition(position);
} }

View File

@ -3,20 +3,19 @@
#include "object.h" #include "object.h"
class Physics class Physics : public Object
{ {
public: public:
public:
Physics(); Physics();
Physics(const Physics&); explicit Physics(const Physics&); // Use explicit to avoid implicit conversion
~Physics(); ~Physics();
float GetGravity(); float GetGravity(); // Get the gravity value
void ApplyGravity(Object*, float); void SetGravity(float gravity); // Define the gravity value
void ApplyGravity(Object*, float); // Apply gravity to an object
private: private:
float m_gravity; float m_gravity;
}; };
#endif #endif