Boutton "Add object" ajoute un cube qui tourne
This commit is contained in:
parent
7ad8ed3483
commit
7ef3237d88
@ -163,6 +163,7 @@ bool SystemClass::Frame()
|
|||||||
m_Application->SetSpeed(speed);
|
m_Application->SetSpeed(speed);
|
||||||
m_imguiManager->WidgetButton();
|
m_imguiManager->WidgetButton();
|
||||||
m_imguiManager->WidgetFPS();
|
m_imguiManager->WidgetFPS();
|
||||||
|
m_imguiManager->WidgetAddObject(m_Application);
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
@ -126,6 +126,14 @@ void ApplicationClass::Shutdown()
|
|||||||
m_Direct3D = 0;
|
m_Direct3D = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Libérez la mémoire pour chaque cube
|
||||||
|
for (auto cube : m_cubes)
|
||||||
|
{
|
||||||
|
cube->Shutdown();
|
||||||
|
delete cube;
|
||||||
|
}
|
||||||
|
m_cubes.clear();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,34 +178,22 @@ bool ApplicationClass::Render(float rotation)
|
|||||||
m_Camera->GetViewMatrix(viewMatrix);
|
m_Camera->GetViewMatrix(viewMatrix);
|
||||||
m_Direct3D->GetProjectionMatrix(projectionMatrix);
|
m_Direct3D->GetProjectionMatrix(projectionMatrix);
|
||||||
|
|
||||||
// Render the first cube
|
for (auto cube : m_cubes)
|
||||||
scaleMatrix = XMMatrixScaling(0.5f, 0.5f, 0.5f);
|
|
||||||
rotateMatrix = XMMatrixRotationX(rotation);
|
|
||||||
translateMatrix = XMMatrixTranslation(-2.0f, 0.0f, 0.0f);
|
|
||||||
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
|
|
||||||
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
|
|
||||||
|
|
||||||
m_Model->Render(m_Direct3D->GetDeviceContext());
|
|
||||||
result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(),
|
|
||||||
m_Light->GetDirection(), m_Light->GetDiffuseColor());
|
|
||||||
if (!result)
|
|
||||||
{
|
{
|
||||||
return false;
|
cube->Render(m_Direct3D->GetDeviceContext());
|
||||||
}
|
|
||||||
|
|
||||||
// Render the second cube
|
scaleMatrix = cube->GetScaleMatrix();
|
||||||
scaleMatrix = XMMatrixScaling(1.5f, 1.5f, 1.5f);
|
rotateMatrix = XMMatrixRotationY(rotation);
|
||||||
rotateMatrix = XMMatrixRotationY(rotation);
|
translateMatrix = cube->GetTranslateMatrix();
|
||||||
translateMatrix = XMMatrixTranslation(2.0f, 0.0f, 0.0f);
|
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
|
||||||
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
|
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
|
||||||
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
|
|
||||||
|
|
||||||
m_Model->Render(m_Direct3D->GetDeviceContext());
|
result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), cube->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, cube->GetTexture(),
|
||||||
result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(),
|
m_Light->GetDirection(), m_Light->GetDiffuseColor());
|
||||||
m_Light->GetDirection(), m_Light->GetDiffuseColor());
|
if (!result)
|
||||||
if (!result)
|
{
|
||||||
{
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present the rendered scene to the screen.
|
// Present the rendered scene to the screen.
|
||||||
@ -220,3 +216,22 @@ int ApplicationClass::GetScreenHeight() const
|
|||||||
{
|
{
|
||||||
return GetSystemMetrics(SM_CYSCREEN);
|
return GetSystemMetrics(SM_CYSCREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ApplicationClass::AddCube()
|
||||||
|
{
|
||||||
|
char modelFilename[128];
|
||||||
|
char textureFilename[128];
|
||||||
|
|
||||||
|
// Set the file name of the model.
|
||||||
|
strcpy_s(modelFilename, "cube.txt");
|
||||||
|
|
||||||
|
// Set the name of the texture file that we will be loading.
|
||||||
|
strcpy_s(textureFilename, "stone01.tga");
|
||||||
|
|
||||||
|
Object* newCube = new Object();
|
||||||
|
newCube->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename);
|
||||||
|
|
||||||
|
newCube->SetTranslateMatrix(XMMatrixTranslation(0.0f, 0.0f, 0.0f));
|
||||||
|
|
||||||
|
m_cubes.push_back(newCube);
|
||||||
|
}
|
@ -7,9 +7,10 @@
|
|||||||
///////////////////////
|
///////////////////////
|
||||||
#include "d3dclass.h"
|
#include "d3dclass.h"
|
||||||
#include "cameraclass.h"
|
#include "cameraclass.h"
|
||||||
#include "modelclass.h"
|
#include "object.h"
|
||||||
#include "lightshaderclass.h"
|
#include "lightshaderclass.h"
|
||||||
#include "lightclass.h"
|
#include "lightclass.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
/////////////
|
/////////////
|
||||||
// GLOBALS //
|
// GLOBALS //
|
||||||
@ -41,6 +42,9 @@ public:
|
|||||||
float GetSpeed() const { return speed; };
|
float GetSpeed() const { return speed; };
|
||||||
void SetSpeed(float speed) { this->speed = speed; };
|
void SetSpeed(float speed) { this->speed = speed; };
|
||||||
|
|
||||||
|
void AddCube();
|
||||||
|
int GetCubeCount() const { return m_cubes.size(); };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool Render(float);
|
bool Render(float);
|
||||||
|
|
||||||
@ -52,6 +56,7 @@ private:
|
|||||||
LightShaderClass* m_LightShader;
|
LightShaderClass* m_LightShader;
|
||||||
LightClass* m_Light;
|
LightClass* m_Light;
|
||||||
float speed = 0.1f;
|
float speed = 0.1f;
|
||||||
|
std::vector<Object*> m_cubes;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
<ClCompile Include="lightshaderclass.cpp" />
|
<ClCompile Include="lightshaderclass.cpp" />
|
||||||
<ClCompile Include="Main.cpp" />
|
<ClCompile Include="Main.cpp" />
|
||||||
<ClCompile Include="modelclass.cpp" />
|
<ClCompile Include="modelclass.cpp" />
|
||||||
|
<ClCompile Include="object.cpp" />
|
||||||
<ClCompile Include="Systemclass.cpp" />
|
<ClCompile Include="Systemclass.cpp" />
|
||||||
<ClCompile Include="textureclass.cpp" />
|
<ClCompile Include="textureclass.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -58,6 +59,7 @@
|
|||||||
<ClInclude Include="inputclass.h" />
|
<ClInclude Include="inputclass.h" />
|
||||||
<ClInclude Include="lightshaderclass.h" />
|
<ClInclude Include="lightshaderclass.h" />
|
||||||
<ClInclude Include="modelclass.h" />
|
<ClInclude Include="modelclass.h" />
|
||||||
|
<ClInclude Include="object.h" />
|
||||||
<ClInclude Include="systemclass.h" />
|
<ClInclude Include="systemclass.h" />
|
||||||
<ClInclude Include="textureclass.h" />
|
<ClInclude Include="textureclass.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -3,6 +3,6 @@ Pos=60,60
|
|||||||
Size=400,400
|
Size=400,400
|
||||||
|
|
||||||
[Window][Khaotic Engine]
|
[Window][Khaotic Engine]
|
||||||
Pos=21,21
|
Pos=522,44
|
||||||
Size=694,367
|
Size=694,367
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "imguiManager.h"
|
#include "imguiManager.h"
|
||||||
|
#include "applicationclass.h"
|
||||||
|
|
||||||
imguiManager::imguiManager()
|
imguiManager::imguiManager()
|
||||||
{
|
{
|
||||||
@ -62,7 +63,15 @@ void imguiManager::WidgetFPS()
|
|||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io->Framerate, io->Framerate);
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io->Framerate, io->Framerate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void imguiManager::WidgetFullscreen(bool* fullscreen)
|
void imguiManager::WidgetAddObject(ApplicationClass* app)
|
||||||
{
|
{
|
||||||
ImGui::Checkbox("Fullscreen", fullscreen);
|
if (ImGui::CollapsingHeader("Objects"))
|
||||||
|
{
|
||||||
|
if (ImGui::Button("Add Cube"))
|
||||||
|
{
|
||||||
|
app->AddCube();
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text("Number of cubes: %d", app->GetCubeCount());
|
||||||
|
}
|
||||||
}
|
}
|
@ -7,6 +7,8 @@
|
|||||||
#include <imgui_impl_win32.h>
|
#include <imgui_impl_win32.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
class ApplicationClass;
|
||||||
|
|
||||||
class imguiManager
|
class imguiManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -22,7 +24,7 @@ public:
|
|||||||
void WidgetSpeedSlider(float* speed);
|
void WidgetSpeedSlider(float* speed);
|
||||||
void WidgetButton();
|
void WidgetButton();
|
||||||
void WidgetFPS();
|
void WidgetFPS();
|
||||||
void WidgetFullscreen(bool* fullscreen);
|
void WidgetAddObject(ApplicationClass* app);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ImGuiIO* io;
|
ImGuiIO* io;
|
||||||
|
64
enginecustom/object.cpp
Normal file
64
enginecustom/object.cpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include "object.h"
|
||||||
|
|
||||||
|
Object::Object() : ModelClass()
|
||||||
|
{
|
||||||
|
m_scaleMatrix = XMMatrixIdentity();
|
||||||
|
m_rotateMatrix = XMMatrixIdentity();
|
||||||
|
m_translateMatrix = XMMatrixIdentity();
|
||||||
|
m_srMatrix = XMMatrixIdentity();
|
||||||
|
m_worldMatrix = XMMatrixIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::~Object()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Object::SetScaleMatrix(XMMATRIX scaleMatrix)
|
||||||
|
{
|
||||||
|
m_scaleMatrix = scaleMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Object::SetRotateMatrix(XMMATRIX rotateMatrix)
|
||||||
|
{
|
||||||
|
m_rotateMatrix = rotateMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Object::SetTranslateMatrix(XMMATRIX translateMatrix)
|
||||||
|
{
|
||||||
|
m_translateMatrix = translateMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Object::SetSRMatrix(XMMATRIX srMatrix)
|
||||||
|
{
|
||||||
|
m_srMatrix = srMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Object::SetWorldMatrix(XMMATRIX worldMatrix)
|
||||||
|
{
|
||||||
|
m_worldMatrix = worldMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
XMMATRIX Object::GetScaleMatrix()
|
||||||
|
{
|
||||||
|
return m_scaleMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
XMMATRIX Object::GetRotateMatrix()
|
||||||
|
{
|
||||||
|
return m_rotateMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
XMMATRIX Object::GetTranslateMatrix()
|
||||||
|
{
|
||||||
|
return m_translateMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
XMMATRIX Object::GetSRMatrix()
|
||||||
|
{
|
||||||
|
return m_srMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
XMMATRIX Object::GetWorldMatrix()
|
||||||
|
{
|
||||||
|
return m_worldMatrix;
|
||||||
|
}
|
28
enginecustom/object.h
Normal file
28
enginecustom/object.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "modelclass.h"
|
||||||
|
|
||||||
|
class Object : public ModelClass
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Object();
|
||||||
|
~Object();
|
||||||
|
|
||||||
|
void SetScaleMatrix(XMMATRIX scaleMatrix);
|
||||||
|
void SetRotateMatrix(XMMATRIX rotateMatrix);
|
||||||
|
void SetTranslateMatrix(XMMATRIX translateMatrix);
|
||||||
|
void SetSRMatrix(XMMATRIX srMatrix);
|
||||||
|
void SetWorldMatrix(XMMATRIX worldMatrix);
|
||||||
|
|
||||||
|
XMMATRIX GetScaleMatrix();
|
||||||
|
XMMATRIX GetRotateMatrix();
|
||||||
|
XMMATRIX GetTranslateMatrix();
|
||||||
|
XMMATRIX GetSRMatrix();
|
||||||
|
XMMATRIX GetWorldMatrix();
|
||||||
|
|
||||||
|
private:
|
||||||
|
XMMATRIX m_scaleMatrix;
|
||||||
|
XMMATRIX m_rotateMatrix;
|
||||||
|
XMMATRIX m_translateMatrix;
|
||||||
|
XMMATRIX m_srMatrix;
|
||||||
|
XMMATRIX m_worldMatrix;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user