From d51619f437820f33fd069705283624fb2e1deb51 Mon Sep 17 00:00:00 2001 From: StratiX0 Date: Mon, 22 Apr 2024 14:50:14 +0200 Subject: [PATCH] fix du spawn d'un objet fix: + les objets ne spawn plus a une distance elevees --- enginecustom/applicationclass.cpp | 12 +++++++----- enginecustom/imgui.ini | 2 +- enginecustom/object.cpp | 2 +- enginecustom/physics.cpp | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index b011e0c..00bf8b9 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -744,8 +744,7 @@ bool ApplicationClass::Frame(InputClass* Input) object->SetAcceleration(XMVectorZero()); // Apply forces - m_Physics->ApplyGravity(object, frameTime); - m_Physics->ApplyDrag(object, 1.0f, frameTime); + float forceX = 0, forceY = 0, forceZ = 0, forceW = 0; @@ -779,11 +778,14 @@ bool ApplicationClass::Frame(InputClass* Input) position = position + velocity * frameTime; object->SetPosition(position); - // Check if the object has fallen below the ground - if (XMVectorGetY(object->GetPosition()) < -10.0f) + m_Physics->ApplyGravity(object, frameTime); + m_Physics->ApplyDrag(object, 1.0f, frameTime); + + // Check if the object has fallen below a certain position + if (XMVectorGetY(object->GetPosition()) < -30.0f) { XMVECTOR currentPosition = object->GetPosition(); // Obtain the current position of the object - object->SetPosition(XMVectorSetY(currentPosition, 20.0f)); // Define the new position of the object + object->SetPosition(XMVectorSetY(currentPosition, 50.0f)); // Define the new position of the object } object->m_previousPosition = object->GetPosition(); diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index d7295bb..da1de71 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -7,7 +7,7 @@ Pos=593,31 Size=694,210 [Window][Objects] -Pos=87,45 +Pos=81,40 Size=492,353 [Window][Terrain] diff --git a/enginecustom/object.cpp b/enginecustom/object.cpp index 2c37036..a721a31 100644 --- a/enginecustom/object.cpp +++ b/enginecustom/object.cpp @@ -10,7 +10,7 @@ Object::Object() : ModelClass() m_previousPosition = XMVectorZero(); m_velocity = XMVectorZero(); m_acceleration = XMVectorZero(); - m_mass = 1.0f; + m_mass = NULL; } Object::~Object() diff --git a/enginecustom/physics.cpp b/enginecustom/physics.cpp index a73aad2..0fc2d46 100644 --- a/enginecustom/physics.cpp +++ b/enginecustom/physics.cpp @@ -1,8 +1,9 @@ #include "physics.h" -Physics::Physics() : m_gravity(XMVectorSet(0.0f, -9.81f, 0.0f, 0.0f)) // Initialize the gravity vector +Physics::Physics() { + m_gravity = XMVectorSet(0.0f, -9.81f, 0.0f, 0.0f); // Initialize the gravity vector } Physics::Physics(const Physics& other)