diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index 00bf8b9..5010ea6 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -636,9 +636,9 @@ bool ApplicationClass::Frame(InputClass* Input) static int lastMouseX = 0, lastMouseY = 0; static float rotation = 360.0f; - static float x = 0.f; - static float y = 3.f; - static float z = 0.f; + static float x = 0.0f; + static float y = 3.0f; + static float z = 0.0f; // Update the system stats. m_Timer->Frame(); @@ -736,7 +736,7 @@ bool ApplicationClass::Frame(InputClass* Input) keyUp = Input->IsUpArrowPressed(); keyDown = Input->IsDownArrowPressed(); - for (auto object : m_object) + for (auto& object : m_object) { if (object != nullptr) // Check if the object is not null { @@ -778,8 +778,7 @@ bool ApplicationClass::Frame(InputClass* Input) position = position + velocity * frameTime; object->SetPosition(position); - m_Physics->ApplyGravity(object, frameTime); - m_Physics->ApplyDrag(object, 1.0f, frameTime); + m_Physics->ApplyGravity(object, 1.0f, frameTime); // Check if the object has fallen below a certain position if (XMVectorGetY(object->GetPosition()) < -30.0f) diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index da1de71..da5bd9e 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -3,14 +3,14 @@ Pos=60,60 Size=400,400 [Window][Khaotic Engine] -Pos=593,31 +Pos=29,636 Size=694,210 [Window][Objects] -Pos=81,40 +Pos=34,270 Size=492,353 [Window][Terrain] -Pos=1120,255 +Pos=755,731 Size=418,94 diff --git a/enginecustom/physics.cpp b/enginecustom/physics.cpp index 0fc2d46..bb5c182 100644 --- a/enginecustom/physics.cpp +++ b/enginecustom/physics.cpp @@ -28,7 +28,7 @@ void Physics::SetGravity(XMVECTOR gravity) } // Apply gravity to an object -void Physics::ApplyGravity(Object* object, float frameTime) +void Physics::ApplyGravity(Object* object, float dragValue, float frameTime) { if (object == nullptr) // Verify if the object is not null { @@ -41,30 +41,13 @@ void Physics::ApplyGravity(Object* object, float frameTime) // Add the gravity acceleration to the object's current acceleration object->SetAcceleration(object->GetAcceleration() + gravityAcceleration); - // Get the object velocity - XMVECTOR velocity = object->GetVelocity(); - - // Update the velocity with the object's acceleration - velocity += object->GetAcceleration() * frameTime; - - // Set the new velocity - object->SetVelocity(velocity); -} - -void Physics::ApplyDrag(Object* object, float dragValue, float frameTime) -{ - if (object == nullptr) // Verify if the object is not null - { - return; - } - // Calculate the acceleration caused by drag XMVECTOR dragAcceleration = -object->GetVelocity() * dragValue / object->GetMass(); // Add the drag acceleration to the object's current acceleration object->SetAcceleration(object->GetAcceleration() + dragAcceleration); - // Get the velocity of the object + // Get the object velocity XMVECTOR velocity = object->GetVelocity(); // Update the velocity with the object's acceleration diff --git a/enginecustom/physics.h b/enginecustom/physics.h index 5307551..0d774b0 100644 --- a/enginecustom/physics.h +++ b/enginecustom/physics.h @@ -12,8 +12,7 @@ public: XMVECTOR GetGravity() const; // 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); + void ApplyGravity(Object*, float, float); // Apply gravity to an object void ApplyForce(Object*, XMVECTOR); private: