diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp
index bc6974c..56c669a 100644
--- a/enginecustom/applicationclass.cpp
+++ b/enginecustom/applicationclass.cpp
@@ -30,6 +30,7 @@ ApplicationClass::ApplicationClass()
m_Frustum = 0;
m_DisplayPlane = 0;
m_ReflectionShader = 0;
+ m_Physics = 0;
}
@@ -388,6 +389,8 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
return false;
}
+ m_Physics = new Physics;
+
return true;
}
@@ -626,7 +629,7 @@ bool ApplicationClass::Frame(InputClass* Input)
static int lastMouseX = 0, lastMouseY = 0;
static float rotation = 360.0f;
- static float x = 6.f;
+ static float x = 0.f;
static float y = 3.f;
static float z = 0.f;
@@ -710,13 +713,23 @@ bool ApplicationClass::Frame(InputClass* Input)
rotation += 360.0f;
}
- // Update the x position variable each frame.
- x -= 0.0174532925f * 0.6f;
+ //// Update the x position variable each frame.
+ //x -= 0.0174532925f * 0.6f;
- y -= 0.0174532925f * 0.2f;
+ //y -= 0.0174532925f * 0.2f;
- // Update the z position variable each frame.
- z -= 0.0174532925f * 0.2f;
+ //// Update the z position variable each frame.
+ //z -= 0.0174532925f * 0.2f;
+
+ for (auto object : m_object)
+ {
+ m_Physics->ApplyGravity(object, frameTime);
+ if (XMVectorGetY(object->GetPosition()) < -10.0f)
+ {
+ object->SetPosition(XMVectorSet(0.0f, 20.0f, 0.0f, 0.0f));
+ }
+ }
+
// Render the scene to a render texture.
result = RenderSceneToTexture(rotation);
@@ -838,7 +851,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
cube->Render(m_Direct3D->GetDeviceContext());
- result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
+ result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), cube->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, cube->GetTexture(0),
diffuseColor, lightPosition);
if (!result)
{
@@ -861,7 +874,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
object->Render(m_Direct3D->GetDeviceContext());
- result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
+ result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, object->GetTexture(0),
diffuseColor, lightPosition);
if (!result)
diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h
index 820f2d7..48a1f8d 100644
--- a/enginecustom/applicationclass.h
+++ b/enginecustom/applicationclass.h
@@ -34,6 +34,7 @@
#include "displayplaneclass.h"
#include "translateshaderclass.h"
#include "reflectionshaderclass.h"
+#include "physics.h"
/////////////
@@ -157,6 +158,8 @@ private :
TextClass* m_FpsString;
int m_previousFps;
+ Physics* m_Physics;
+ float m_gravity;
};
#endif
\ No newline at end of file
diff --git a/enginecustom/enginecustom.vcxproj b/enginecustom/enginecustom.vcxproj
index 81c17e5..5d31d16 100644
--- a/enginecustom/enginecustom.vcxproj
+++ b/enginecustom/enginecustom.vcxproj
@@ -48,6 +48,7 @@
+
@@ -90,6 +91,7 @@
+
diff --git a/enginecustom/enginecustom.vcxproj.filters b/enginecustom/enginecustom.vcxproj.filters
index 07bef64..76766ec 100644
--- a/enginecustom/enginecustom.vcxproj.filters
+++ b/enginecustom/enginecustom.vcxproj.filters
@@ -156,6 +156,9 @@
Fichiers sources
+
+ Fichiers sources
+
@@ -281,6 +284,9 @@
Fichiers d%27en-tĂȘte
+
+ Fichiers d%27en-tĂȘte
+
diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini
index 21e4b2c..8f6e492 100644
--- a/enginecustom/imgui.ini
+++ b/enginecustom/imgui.ini
@@ -11,6 +11,6 @@ Pos=222,19
Size=492,353
[Window][Terrain]
-Pos=892,19
+Pos=890,19
Size=418,94
diff --git a/enginecustom/physics.cpp b/enginecustom/physics.cpp
new file mode 100644
index 0000000..3e7eff7
--- /dev/null
+++ b/enginecustom/physics.cpp
@@ -0,0 +1,32 @@
+#include "physics.h"
+
+Physics::Physics()
+{
+ m_gravity = -9.81f;
+}
+
+
+Physics::Physics(const Physics& other)
+{
+ m_gravity = other.m_gravity; // Copy gravity value from the other object
+}
+
+
+Physics::~Physics()
+{
+}
+
+float Physics::GetGravity() // Changed the method to return the gravity value
+{
+ return m_gravity;
+}
+
+void Physics::ApplyGravity(Object* object, float frameTime)
+{
+ // Update the position of the object by adding the change in position due to gravity.
+ 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;
+}
\ No newline at end of file
diff --git a/enginecustom/physics.h b/enginecustom/physics.h
new file mode 100644
index 0000000..cfe9153
--- /dev/null
+++ b/enginecustom/physics.h
@@ -0,0 +1,22 @@
+#ifndef _PHYSICS_H_
+#define _PHYSICS_H_
+
+#include "object.h"
+
+class Physics
+{
+public:
+ public:
+ Physics();
+ Physics(const Physics&);
+ ~Physics();
+
+ float GetGravity();
+ void ApplyGravity(Object*, float);
+
+private:
+ float m_gravity;
+};
+
+#endif
+