Terrain + Fix ImGui

Premier test de Terrain.
Fix les attributs des objets dans ImGui
This commit is contained in:
CatChow0 2024-03-27 11:32:50 +01:00
parent 8d56c159c6
commit 20401c1df8
9 changed files with 132 additions and 29 deletions

View File

@ -99,7 +99,6 @@ void SystemClass::Run()
MSG msg;
bool done, result;
// Initialize the message structure.
ZeroMemory(&msg, sizeof(MSG));
@ -165,6 +164,7 @@ bool SystemClass::Frame()
m_imguiManager->WidgetFPS();
m_imguiManager->WidgetAddObject(m_Application);
m_imguiManager->WidgetObjectWindow(m_Application);
m_imguiManager->WidgetTestTerrain(m_Application);
ImGui::End();

View File

@ -49,7 +49,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
// Set the initial position of the camera.
m_Camera->SetPosition(0.0f, 0.0f, -10.0f);
m_Camera->SetRotation(0.0f, 0.0f, 10.0f);
m_Camera->SetRotation(0.0f, 0.0f, 0.0f);
// Set the file name of the model.
strcpy_s(modelFilename, "cube.txt");
@ -80,7 +80,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
m_Light = new LightClass;
m_Light->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Light->SetDirection(0.0f, 0.0f, 1.0f);
m_Light->SetDirection(0.0f, -1.0f, 1.0f);
return true;
}
@ -166,7 +166,6 @@ bool ApplicationClass::Render(float rotation)
XMMATRIX worldMatrix, rotateMatrix, translateMatrix, scaleMatrix, srMatrix;
bool result;
// Clear the buffers to begin the scene.
m_Direct3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
@ -181,7 +180,15 @@ bool ApplicationClass::Render(float rotation)
cube->Render(m_Direct3D->GetDeviceContext());
scaleMatrix = cube->GetScaleMatrix();
rotateMatrix = XMMatrixRotationY(rotation);
if (cube->m_demoSpinning)
rotateMatrix = XMMatrixRotationY(rotation);
else
{
rotateMatrix = cube->GetRotateMatrix();
}
translateMatrix = cube->GetTranslateMatrix();
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
@ -215,7 +222,7 @@ int ApplicationClass::GetScreenHeight() const
return GetSystemMetrics(SM_CYSCREEN);
}
void ApplicationClass::AddCube()
void ApplicationClass::GenerateTerrain()
{
char modelFilename[128];
char textureFilename[128];
@ -226,10 +233,48 @@ void ApplicationClass::AddCube()
// Set the name of the texture file that we will be loading.
strcpy_s(textureFilename, "stone01.tga");
// Create cube objects to fill a 10x10 grid of cubes
for (int i = -10; i < 10; i++)
{
for (int j = -10; j < 10; j++)
{
Object* newCube = new Object();
newCube->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename);
newCube->SetTranslateMatrix(XMMatrixTranslation(i * 2.0f, -4.0f, j * 2.0f));
m_cubes.push_back(newCube);
}
}
}
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");
static int cubeCount = 0;
float position = cubeCount * 2.0f;
Object* newCube = new Object();
newCube->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename);
newCube->SetTranslateMatrix(XMMatrixTranslation(0.0f, 0.0f, 0.0f));
newCube->SetTranslateMatrix(XMMatrixTranslation(position, 0.0f, 0.0f));
m_cubes.push_back(newCube);
}
void ApplicationClass::DeleteCube(int index)
{
if (index < m_cubes.size())
{
m_cubes[index]->Shutdown();
delete m_cubes[index];
m_cubes.erase(m_cubes.begin() + index);
}
}

View File

@ -43,9 +43,12 @@ public:
void SetSpeed(float speed) { this->speed = speed; };
void AddCube();
void DeleteCube(int index);
int GetCubeCount() const { return m_cubes.size(); };
std::vector<Object*> GetCubes() const { return m_cubes; };
void GenerateTerrain();
private:
bool Render(float);

View File

@ -69,6 +69,21 @@
<ClCompile Include="include\imgui_widgets.cpp">
<Filter>Fichiers sources\ImGui</Filter>
</ClCompile>
<ClCompile Include="imguiManager.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="lightclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="lightshaderclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="object.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="textureclass.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="systemclass.h">
@ -116,6 +131,21 @@
<ClInclude Include="include\backends\imgui_impl_win32.h">
<Filter>Fichiers d%27en-tête\ImGui</Filter>
</ClInclude>
<ClInclude Include="..\..\dx11win10tut06_src\source\lightclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="imguiManager.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="lightshaderclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="object.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="textureclass.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
@ -125,21 +155,13 @@
<None Include="Color.vs">
<Filter>shader</Filter>
</None>
<None Include="light.vs">
<Filter>texture</Filter>
</None>
<None Include="light.ps">
<Filter>texture</Filter>
</None>
<None Include="light.ps" />
<None Include="light.vs" />
</ItemGroup>
<ItemGroup>
<Image Include="stone01.tga">
<Filter>assets</Filter>
</Image>
<Image Include="stone01.tga" />
</ItemGroup>
<ItemGroup>
<Text Include="cube.txt">
<Filter>assets</Filter>
</Text>
<Text Include="cube.txt" />
</ItemGroup>
</Project>

View File

@ -3,10 +3,10 @@ Pos=60,60
Size=400,400
[Window][Khaotic Engine]
Pos=765,19
Size=694,367
Pos=765,20
Size=694,366
[Window][Objects]
Pos=44,57
Pos=69,21
Size=492,353

View File

@ -81,34 +81,63 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app)
{
ImGui::Begin("Objects");
int index = 0;
for (auto object : app->GetCubes())
for (auto& object : app->GetCubes())
{
std::string headerName = "Object " + std::to_string(index);
if (ImGui::CollapsingHeader(headerName.c_str()))
{
XMVECTOR position = object->GetPosition();
XMVECTOR rotation = object->GetRotation();
XMVECTOR scale = object->GetScale();
float pos[3] = { XMVectorGetX(position), XMVectorGetY(position), XMVectorGetZ(position) };
if (ImGui::DragFloat3("Position", pos))
std::string posLabel = "Position##" + std::to_string(index);
if (ImGui::DragFloat3(posLabel.c_str(), pos))
{
object->SetPosition(XMVectorSet(pos[0], pos[1], pos[2], 0.0f));
}
float rot[3] = { XMVectorGetX(rotation), XMVectorGetY(rotation), XMVectorGetZ(rotation) };
if (ImGui::DragFloat3("Rotation", rot))
std::string rotLabel = "Rotation##" + std::to_string(index);
if (ImGui::DragFloat3(rotLabel.c_str(), rot))
{
object->SetRotation(XMVectorSet(rot[0], rot[1], rot[2], 0.0f));
}
float scl[3] = { XMVectorGetX(scale), XMVectorGetY(scale), XMVectorGetZ(scale) };
if (ImGui::DragFloat3("Scale", scl))
std::string sclLabel = "Scale##" + std::to_string(index);
if (ImGui::DragFloat3(sclLabel.c_str(), scl))
{
object->SetScale(XMVectorSet(scl[0], scl[1], scl[2], 0.0f));
}
ImGui::Separator();
// Delete button
std::string deleteLabel = "Delete##" + std::to_string(index);
if (ImGui::Button(deleteLabel.c_str()))
{
app->DeleteCube(index);
}
ImGui::Separator();
// Demo spinning
std::string demoLabel = "Demo spinning##" + std::to_string(index);
ImGui::Checkbox(demoLabel.c_str(), &object->m_demoSpinning);
}
index++;
}
ImGui::End();
}
void imguiManager::WidgetTestTerrain(ApplicationClass* app)
{
ImGui::Separator();
if (ImGui::Button("Generate Terrain"))
{
app->GenerateTerrain();
}
}

View File

@ -25,6 +25,7 @@ public:
void WidgetButton();
void WidgetFPS();
void WidgetAddObject(ApplicationClass* app);
void WidgetTestTerrain(ApplicationClass* app);
void WidgetObjectWindow(ApplicationClass* app);

View File

@ -66,7 +66,7 @@ XMMATRIX Object::GetWorldMatrix()
XMVECTOR Object::GetPosition()
{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_worldMatrix);
XMStoreFloat4x4(&matrix, m_translateMatrix);
return XMVectorSet(matrix._41, matrix._42, matrix._43, 0.0f);
}
@ -94,11 +94,11 @@ XMVECTOR Object::GetScale()
void Object::SetPosition(XMVECTOR position)
{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_worldMatrix);
XMStoreFloat4x4(&matrix, m_translateMatrix);
matrix._41 = XMVectorGetX(position);
matrix._42 = XMVectorGetY(position);
matrix._43 = XMVectorGetZ(position);
m_worldMatrix = XMLoadFloat4x4(&matrix);
m_translateMatrix = XMLoadFloat4x4(&matrix);
}
void Object::SetRotation(XMVECTOR rotation)

View File

@ -27,6 +27,9 @@ public:
XMVECTOR GetRotation();
XMVECTOR GetScale();
public :
bool m_demoSpinning = false;
private:
XMMATRIX m_scaleMatrix;
XMMATRIX m_rotateMatrix;