diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index 989ca9a..e763530 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -285,20 +285,24 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) m_numLights = 4; // Create and initialize the light objects array. - m_Lights = new LightClass[m_numLights]; + m_Lights.resize(m_numLights); - // Manually set the color and position of each light. - m_Lights[0].SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f); // Red - m_Lights[0].SetPosition(-3.0f, 1.0f, 3.0f); + // Définissez manuellement la couleur et la position de chaque lumière. + m_Lights[0] = new LightClass; + m_Lights[0]->SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f); // Rouge + m_Lights[0]->SetPosition(-3.0f, 1.0f, 3.0f); - m_Lights[1].SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f); // Green - m_Lights[1].SetPosition(3.0f, 1.0f, 3.0f); + m_Lights[1] = new LightClass; + m_Lights[1]->SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f); // Vert + m_Lights[1]->SetPosition(3.0f, 1.0f, 3.0f); - m_Lights[2].SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue - m_Lights[2].SetPosition(-3.0f, 1.0f, -3.0f); + m_Lights[2] = new LightClass; + m_Lights[2]->SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f); // Bleu + m_Lights[2]->SetPosition(-3.0f, 1.0f, -3.0f); - m_Lights[3].SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White - m_Lights[3].SetPosition(3.0f, 1.0f, -3.0f); + m_Lights[3] = new LightClass; + m_Lights[3]->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // Blanc + m_Lights[3]->SetPosition(3.0f, 1.0f, -3.0f); // Create and initialize the light map shader object. m_LightMapShader = new LightMapShaderClass; @@ -511,12 +515,12 @@ void ApplicationClass::Shutdown() m_Sprite = 0; } - // Release the light objects. - if(m_Lights) - { - delete [] m_Lights; - m_Lights = 0; - } + // Supprimez tous les objets de lumière. + for (int i = 0; i < m_Lights.size(); i++) + { + delete m_Lights[i]; + m_Lights[i] = 0; + } // Release the light shader object. if (m_LightShader) @@ -833,10 +837,10 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z) for (i = 0; i < m_numLights; i++) { // Create the diffuse color array from the four light colors. - diffuseColor[i] = m_Lights[i].GetDiffuseColor(); + diffuseColor[i] = m_Lights[i]->GetDiffuseColor(); // Create the light position array from the four light positions. - lightPosition[i] = m_Lights[i].GetPosition(); + lightPosition[i] = m_Lights[i]->GetPosition(); } // Construct the frustum. @@ -1011,10 +1015,10 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z) for (i = 0; i < m_numLights; i++) { // Create the diffuse color array from the four light colors. - diffuseColor[i] = m_Lights[i].GetDiffuseColor(); + diffuseColor[i] = m_Lights[i]->GetDiffuseColor(); // Create the light position array from the four light positions. - lightPosition[i] = m_Lights[i].GetPosition(); + lightPosition[i] = m_Lights[i]->GetPosition(); } scaleMatrix = XMMatrixScaling(0.5f, 0.5f, 0.5f); // Build the scaling matrix. @@ -1408,4 +1412,40 @@ bool ApplicationClass::UpdateRenderCountString(int renderCount) } return true; +} + +XMVECTOR ApplicationClass::GetLightColor(int index) +{ + //convert to XMVECTOR + XMVECTOR lightColor = XMVectorSet(m_Lights[index]->GetDiffuseColor().x, m_Lights[index]->GetDiffuseColor().y, m_Lights[index]->GetDiffuseColor().z, 1.0f); + + return lightColor; +} + +XMVECTOR ApplicationClass::GetLightPosition(int index) +{ + //convert to XMVECTOR + XMVECTOR lightPosition = XMVectorSet(m_Lights[index]->GetPosition().x, m_Lights[index]->GetPosition().y, m_Lights[index]->GetPosition().z, 1.0f); + + return lightPosition; +} + +void ApplicationClass::SetLightColor(int index, XMVECTOR color) +{ + //convert to XMFLOAT4 + XMFLOAT4 lightColor; + XMStoreFloat4(&lightColor, color); + + //set the color + m_Lights[index]->SetDiffuseColor(lightColor.x, lightColor.y, lightColor.z, 1.0f); +} + +void ApplicationClass::SetLightPosition(int index, XMVECTOR position) +{ + //convert to XMFLOAT4 + XMFLOAT4 lightPosition; + XMStoreFloat4(&lightPosition, position); + + //set the position + m_Lights[index]->SetPosition(lightPosition.x, lightPosition.y, lightPosition.z); } \ No newline at end of file diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index 820f2d7..9ecf3eb 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -78,6 +78,14 @@ public: void GenerateTerrain(); void DeleteTerrain(); + XMVECTOR GetLightPosition(int index); + XMVECTOR GetLightColor(int index); + + void SetLightPosition(int index, XMVECTOR color); + void SetLightColor(int index, XMVECTOR color); + + std::vector GetLights() const { return m_Lights; }; + private: bool Render(float, float, float, float); bool UpdateMouseStrings(int, int, bool); @@ -123,7 +131,7 @@ private : // ----------------------------------- // LightClass* m_Light; - LightClass* m_Lights; + std::vector m_Lights; int m_numLights; // ----------------------------------- // diff --git a/enginecustom/enginecustom.vcxproj b/enginecustom/enginecustom.vcxproj index 81c17e5..1c7211c 100644 --- a/enginecustom/enginecustom.vcxproj +++ b/enginecustom/enginecustom.vcxproj @@ -118,8 +118,12 @@ - - + + Document + + + Document + diff --git a/enginecustom/enginecustom.vcxproj.filters b/enginecustom/enginecustom.vcxproj.filters index 07bef64..22eaea8 100644 --- a/enginecustom/enginecustom.vcxproj.filters +++ b/enginecustom/enginecustom.vcxproj.filters @@ -352,12 +352,6 @@ shader - - shader - - - shader - Texture @@ -399,4 +393,12 @@ assets + + + shader + + + shader + + \ No newline at end of file diff --git a/enginecustom/imguiManager.cpp b/enginecustom/imguiManager.cpp index e0ead44..9b57fa5 100644 --- a/enginecustom/imguiManager.cpp +++ b/enginecustom/imguiManager.cpp @@ -197,6 +197,7 @@ void imguiManager::ImGuiWidgetRenderer(ApplicationClass* app) WidgetAddObject(app); WidgetObjectWindow(app); WidgetTerrainWindow(app); + WidgetLightWindow(app); ImGui::End(); @@ -204,4 +205,48 @@ void imguiManager::ImGuiWidgetRenderer(ApplicationClass* app) Render(); app->GetDirect3D()->m_swapChain->Present(0, NULL); +} + +void imguiManager::WidgetLightWindow(ApplicationClass* app) +{ + ImGui::Begin("Light"); + int index = 0; + for(auto& light : app->GetLights()) + { + std::string headerName = "Light " + std::to_string(index); + if (ImGui::CollapsingHeader(headerName.c_str())) + { + XMVECTOR position = light->GetPosition(); + XMVECTOR color = light->GetColor(); + float pos[3] = { XMVectorGetX(position), XMVectorGetY(position), XMVectorGetZ(position) }; + float col[3] = { XMVectorGetX(color), XMVectorGetY(color), XMVectorGetZ(color) }; + + std::string posLabel = "Position##" + std::to_string(index); + std::string colLabel = "Color##" + std::to_string(index); + + if (ImGui::DragFloat3(posLabel.c_str(), pos)) + { + light->SetPosition(XMVectorSet(pos[0], pos[1], pos[2], 0.0f)); + } + + if (ImGui::ColorEdit3(colLabel.c_str(), col)) + { + light->SetColor(XMVectorSet(col[0], col[1], col[2], 0.0f)); + } + + ImGui::Separator(); + + // Delete button + std::string deleteLabel = "Delete##" + std::to_string(index); + if (ImGui::Button(deleteLabel.c_str())) + { + app->DeleteLight(index); + } + + ImGui::Separator(); + } + index++; + }) + + ImGui::End(); } \ No newline at end of file diff --git a/enginecustom/imguiManager.h b/enginecustom/imguiManager.h index 1147f54..9f03c76 100644 --- a/enginecustom/imguiManager.h +++ b/enginecustom/imguiManager.h @@ -28,6 +28,7 @@ public: void WidgetObjectWindow(ApplicationClass* app); void WidgetTerrainWindow(ApplicationClass* app); + void WidgetLightWindow(ApplicationClass* app); void ImGuiWidgetRenderer(ApplicationClass* app);