feat: debut de la physique, ajout de la gravite
This commit is contained in:
parent
c21a66f386
commit
6eb50bf29f
@ -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)
|
||||
|
@ -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
|
@ -48,6 +48,7 @@
|
||||
<ClCompile Include="modellistclass.cpp" />
|
||||
<ClCompile Include="Multitextureshaderclass.cpp" />
|
||||
<ClCompile Include="normalmapshaderclass.cpp" />
|
||||
<ClCompile Include="physics.cpp" />
|
||||
<ClCompile Include="positionclass.cpp" />
|
||||
<ClCompile Include="reflectionshaderclass.cpp" />
|
||||
<ClCompile Include="rendertextureclass.cpp" />
|
||||
@ -90,6 +91,7 @@
|
||||
<ClInclude Include="modellistclass.h" />
|
||||
<ClInclude Include="Multitextureshaderclass.h" />
|
||||
<ClInclude Include="normalmapshaderclass.h" />
|
||||
<ClInclude Include="physics.h" />
|
||||
<ClInclude Include="positionclass.h" />
|
||||
<ClInclude Include="reflectionshaderclass.h" />
|
||||
<ClInclude Include="rendertextureclass.h" />
|
||||
|
@ -156,6 +156,9 @@
|
||||
<ClCompile Include="reflectionshaderclass.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="physics.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="systemclass.h">
|
||||
@ -281,6 +284,9 @@
|
||||
<ClInclude Include="reflectionshaderclass.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="physics.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="font01.tga">
|
||||
|
@ -11,6 +11,6 @@ Pos=222,19
|
||||
Size=492,353
|
||||
|
||||
[Window][Terrain]
|
||||
Pos=892,19
|
||||
Pos=890,19
|
||||
Size=418,94
|
||||
|
||||
|
32
enginecustom/physics.cpp
Normal file
32
enginecustom/physics.cpp
Normal file
@ -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;
|
||||
}
|
22
enginecustom/physics.h
Normal file
22
enginecustom/physics.h
Normal file
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user