Terrain + Fix ImGui
Premier test de Terrain. Fix les attributs des objets dans ImGui
This commit is contained in:
parent
8d56c159c6
commit
20401c1df8
@ -99,7 +99,6 @@ void SystemClass::Run()
|
|||||||
MSG msg;
|
MSG msg;
|
||||||
bool done, result;
|
bool done, result;
|
||||||
|
|
||||||
|
|
||||||
// Initialize the message structure.
|
// Initialize the message structure.
|
||||||
ZeroMemory(&msg, sizeof(MSG));
|
ZeroMemory(&msg, sizeof(MSG));
|
||||||
|
|
||||||
@ -165,6 +164,7 @@ bool SystemClass::Frame()
|
|||||||
m_imguiManager->WidgetFPS();
|
m_imguiManager->WidgetFPS();
|
||||||
m_imguiManager->WidgetAddObject(m_Application);
|
m_imguiManager->WidgetAddObject(m_Application);
|
||||||
m_imguiManager->WidgetObjectWindow(m_Application);
|
m_imguiManager->WidgetObjectWindow(m_Application);
|
||||||
|
m_imguiManager->WidgetTestTerrain(m_Application);
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
|||||||
|
|
||||||
// Set the initial position of the camera.
|
// Set the initial position of the camera.
|
||||||
m_Camera->SetPosition(0.0f, 0.0f, -10.0f);
|
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.
|
// Set the file name of the model.
|
||||||
strcpy_s(modelFilename, "cube.txt");
|
strcpy_s(modelFilename, "cube.txt");
|
||||||
@ -80,7 +80,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
|||||||
m_Light = new LightClass;
|
m_Light = new LightClass;
|
||||||
|
|
||||||
m_Light->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -166,7 +166,6 @@ bool ApplicationClass::Render(float rotation)
|
|||||||
XMMATRIX worldMatrix, rotateMatrix, translateMatrix, scaleMatrix, srMatrix;
|
XMMATRIX worldMatrix, rotateMatrix, translateMatrix, scaleMatrix, srMatrix;
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
|
|
||||||
// Clear the buffers to begin the scene.
|
// Clear the buffers to begin the scene.
|
||||||
m_Direct3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
|
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());
|
cube->Render(m_Direct3D->GetDeviceContext());
|
||||||
|
|
||||||
scaleMatrix = cube->GetScaleMatrix();
|
scaleMatrix = cube->GetScaleMatrix();
|
||||||
rotateMatrix = XMMatrixRotationY(rotation);
|
|
||||||
|
if (cube->m_demoSpinning)
|
||||||
|
rotateMatrix = XMMatrixRotationY(rotation);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rotateMatrix = cube->GetRotateMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
translateMatrix = cube->GetTranslateMatrix();
|
translateMatrix = cube->GetTranslateMatrix();
|
||||||
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
|
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
|
||||||
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
|
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
|
||||||
@ -215,7 +222,7 @@ int ApplicationClass::GetScreenHeight() const
|
|||||||
return GetSystemMetrics(SM_CYSCREEN);
|
return GetSystemMetrics(SM_CYSCREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationClass::AddCube()
|
void ApplicationClass::GenerateTerrain()
|
||||||
{
|
{
|
||||||
char modelFilename[128];
|
char modelFilename[128];
|
||||||
char textureFilename[128];
|
char textureFilename[128];
|
||||||
@ -226,10 +233,48 @@ void ApplicationClass::AddCube()
|
|||||||
// Set the name of the texture file that we will be loading.
|
// Set the name of the texture file that we will be loading.
|
||||||
strcpy_s(textureFilename, "stone01.tga");
|
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();
|
Object* newCube = new Object();
|
||||||
newCube->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename);
|
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);
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -43,9 +43,12 @@ public:
|
|||||||
void SetSpeed(float speed) { this->speed = speed; };
|
void SetSpeed(float speed) { this->speed = speed; };
|
||||||
|
|
||||||
void AddCube();
|
void AddCube();
|
||||||
|
void DeleteCube(int index);
|
||||||
int GetCubeCount() const { return m_cubes.size(); };
|
int GetCubeCount() const { return m_cubes.size(); };
|
||||||
std::vector<Object*> GetCubes() const { return m_cubes; };
|
std::vector<Object*> GetCubes() const { return m_cubes; };
|
||||||
|
|
||||||
|
void GenerateTerrain();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool Render(float);
|
bool Render(float);
|
||||||
|
|
||||||
|
@ -69,6 +69,21 @@
|
|||||||
<ClCompile Include="include\imgui_widgets.cpp">
|
<ClCompile Include="include\imgui_widgets.cpp">
|
||||||
<Filter>Fichiers sources\ImGui</Filter>
|
<Filter>Fichiers sources\ImGui</Filter>
|
||||||
</ClCompile>
|
</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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="systemclass.h">
|
<ClInclude Include="systemclass.h">
|
||||||
@ -116,6 +131,21 @@
|
|||||||
<ClInclude Include="include\backends\imgui_impl_win32.h">
|
<ClInclude Include="include\backends\imgui_impl_win32.h">
|
||||||
<Filter>Fichiers d%27en-tête\ImGui</Filter>
|
<Filter>Fichiers d%27en-tête\ImGui</Filter>
|
||||||
</ClInclude>
|
</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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
@ -125,21 +155,13 @@
|
|||||||
<None Include="Color.vs">
|
<None Include="Color.vs">
|
||||||
<Filter>shader</Filter>
|
<Filter>shader</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="light.vs">
|
<None Include="light.ps" />
|
||||||
<Filter>texture</Filter>
|
<None Include="light.vs" />
|
||||||
</None>
|
|
||||||
<None Include="light.ps">
|
|
||||||
<Filter>texture</Filter>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="stone01.tga">
|
<Image Include="stone01.tga" />
|
||||||
<Filter>assets</Filter>
|
|
||||||
</Image>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="cube.txt">
|
<Text Include="cube.txt" />
|
||||||
<Filter>assets</Filter>
|
|
||||||
</Text>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -3,10 +3,10 @@ Pos=60,60
|
|||||||
Size=400,400
|
Size=400,400
|
||||||
|
|
||||||
[Window][Khaotic Engine]
|
[Window][Khaotic Engine]
|
||||||
Pos=765,19
|
Pos=765,20
|
||||||
Size=694,367
|
Size=694,366
|
||||||
|
|
||||||
[Window][Objects]
|
[Window][Objects]
|
||||||
Pos=44,57
|
Pos=69,21
|
||||||
Size=492,353
|
Size=492,353
|
||||||
|
|
||||||
|
@ -81,34 +81,63 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app)
|
|||||||
{
|
{
|
||||||
ImGui::Begin("Objects");
|
ImGui::Begin("Objects");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (auto object : app->GetCubes())
|
for (auto& object : app->GetCubes())
|
||||||
{
|
{
|
||||||
std::string headerName = "Object " + std::to_string(index);
|
std::string headerName = "Object " + std::to_string(index);
|
||||||
if (ImGui::CollapsingHeader(headerName.c_str()))
|
if (ImGui::CollapsingHeader(headerName.c_str()))
|
||||||
{
|
{
|
||||||
|
|
||||||
XMVECTOR position = object->GetPosition();
|
XMVECTOR position = object->GetPosition();
|
||||||
XMVECTOR rotation = object->GetRotation();
|
XMVECTOR rotation = object->GetRotation();
|
||||||
XMVECTOR scale = object->GetScale();
|
XMVECTOR scale = object->GetScale();
|
||||||
float pos[3] = { XMVectorGetX(position), XMVectorGetY(position), XMVectorGetZ(position) };
|
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));
|
object->SetPosition(XMVectorSet(pos[0], pos[1], pos[2], 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
float rot[3] = { XMVectorGetX(rotation), XMVectorGetY(rotation), XMVectorGetZ(rotation) };
|
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));
|
object->SetRotation(XMVectorSet(rot[0], rot[1], rot[2], 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
float scl[3] = { XMVectorGetX(scale), XMVectorGetY(scale), XMVectorGetZ(scale) };
|
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));
|
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++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void imguiManager::WidgetTestTerrain(ApplicationClass* app)
|
||||||
|
{
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
if (ImGui::Button("Generate Terrain"))
|
||||||
|
{
|
||||||
|
app->GenerateTerrain();
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,7 @@ public:
|
|||||||
void WidgetButton();
|
void WidgetButton();
|
||||||
void WidgetFPS();
|
void WidgetFPS();
|
||||||
void WidgetAddObject(ApplicationClass* app);
|
void WidgetAddObject(ApplicationClass* app);
|
||||||
|
void WidgetTestTerrain(ApplicationClass* app);
|
||||||
|
|
||||||
void WidgetObjectWindow(ApplicationClass* app);
|
void WidgetObjectWindow(ApplicationClass* app);
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ XMMATRIX Object::GetWorldMatrix()
|
|||||||
XMVECTOR Object::GetPosition()
|
XMVECTOR Object::GetPosition()
|
||||||
{
|
{
|
||||||
XMFLOAT4X4 matrix;
|
XMFLOAT4X4 matrix;
|
||||||
XMStoreFloat4x4(&matrix, m_worldMatrix);
|
XMStoreFloat4x4(&matrix, m_translateMatrix);
|
||||||
return XMVectorSet(matrix._41, matrix._42, matrix._43, 0.0f);
|
return XMVectorSet(matrix._41, matrix._42, matrix._43, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,11 +94,11 @@ XMVECTOR Object::GetScale()
|
|||||||
void Object::SetPosition(XMVECTOR position)
|
void Object::SetPosition(XMVECTOR position)
|
||||||
{
|
{
|
||||||
XMFLOAT4X4 matrix;
|
XMFLOAT4X4 matrix;
|
||||||
XMStoreFloat4x4(&matrix, m_worldMatrix);
|
XMStoreFloat4x4(&matrix, m_translateMatrix);
|
||||||
matrix._41 = XMVectorGetX(position);
|
matrix._41 = XMVectorGetX(position);
|
||||||
matrix._42 = XMVectorGetY(position);
|
matrix._42 = XMVectorGetY(position);
|
||||||
matrix._43 = XMVectorGetZ(position);
|
matrix._43 = XMVectorGetZ(position);
|
||||||
m_worldMatrix = XMLoadFloat4x4(&matrix);
|
m_translateMatrix = XMLoadFloat4x4(&matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::SetRotation(XMVECTOR rotation)
|
void Object::SetRotation(XMVECTOR rotation)
|
||||||
|
@ -27,6 +27,9 @@ public:
|
|||||||
XMVECTOR GetRotation();
|
XMVECTOR GetRotation();
|
||||||
XMVECTOR GetScale();
|
XMVECTOR GetScale();
|
||||||
|
|
||||||
|
public :
|
||||||
|
bool m_demoSpinning = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XMMATRIX m_scaleMatrix;
|
XMMATRIX m_scaleMatrix;
|
||||||
XMMATRIX m_rotateMatrix;
|
XMMATRIX m_rotateMatrix;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user