From e34b44996afff50f2e22c94f40f1921fedc48be9 Mon Sep 17 00:00:00 2001 From: CatChow0 <thetrueshibadoggo@gmail.com> Date: Thu, 1 May 2025 16:41:33 +0200 Subject: [PATCH] Minor Update - Skybox Update - V9.3.0 --- .../.idea/projectSettingsUpdater.xml | 3 +- .../.idea/workspace.xml | 50 +++---- enginecustom/assets/Texture/imgui.ini | 94 ++++-------- enginecustom/demo.ker | 1 + enginecustom/enginecustom.vcxproj | 2 + enginecustom/src/inc/system/Skybox.h | 30 ++++ .../src/inc/system/applicationclass.h | 10 +- enginecustom/src/src/system/Positionclass.cpp | 1 - enginecustom/src/src/system/Skybox.cpp | 69 +++++++++ .../src/src/system/applicationclass.cpp | 140 +++--------------- 10 files changed, 172 insertions(+), 228 deletions(-) create mode 100644 enginecustom/demo.ker create mode 100644 enginecustom/src/inc/system/Skybox.h create mode 100644 enginecustom/src/src/system/Skybox.cpp diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml b/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml index 4bb9f4d..64af657 100644 --- a/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml +++ b/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="RiderProjectSettingsUpdater"> - <option name="vcsConfiguration" value="2" /> + <option name="singleClickDiffPreview" value="1" /> + <option name="vcsConfiguration" value="3" /> </component> </project> \ No newline at end of file diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml index 51139dd..176017c 100644 --- a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml +++ b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml @@ -5,14 +5,15 @@ </component> <component name="ChangeListManager"> <list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment=""> + <change afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/Skybox.h" afterDir="false" /> + <change afterPath="$PROJECT_DIR$/enginecustom/src/src/system/Skybox.cpp" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/enginecustom/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/imgui.ini" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/imguiManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/imguiManager.h" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/object.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/object.h" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/assets/Texture/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/assets/Texture/imgui.ini" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/applicationclass.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/applicationclass.h" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/Positionclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/Positionclass.cpp" afterDir="false" /> <change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.cpp" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/object.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/object.cpp" afterDir="false" /> </list> <option name="SHOW_DIALOG" value="false" /> <option name="HIGHLIGHT_CONFLICTS" value="true" /> @@ -26,10 +27,9 @@ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> </component> <component name="HighlightingSettingsPerFile"> - <setting file="file://$PROJECT_DIR$/../../../../../Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/shared/windef.h" root0="SKIP_HIGHLIGHTING" /> - <setting file="file://$PROJECT_DIR$/../../../../../Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um/DirectXMath.h" root0="SKIP_HIGHLIGHTING" /> <setting file="file://$PROJECT_DIR$/enginecustom/include/Vulkan/Include/vulkan/vulkan_core.h" root0="SKIP_HIGHLIGHTING" /> <setting file="file://$PROJECT_DIR$/enginecustom/src/src/shader/CelShadingShader.cpp" root0="FORCE_HIGHLIGHTING" /> + <setting file="file://$PROJECT_DIR$/../../IDE_VS/VC/Tools/MSVC/14.38.33130/include/type_traits" root0="SKIP_HIGHLIGHTING" /> </component> <component name="MetaFilesCheckinStateConfiguration" checkMetaFiles="true" /> <component name="ProblemsViewState"> @@ -60,21 +60,13 @@ "nodejs_package_manager_path": "npm", "settings.editor.selected.configurable": "preferences.pluginManager", "vue.rearranger.settings.migration": "true" - }, - "keyToStringList": { - "rider.external.source.directories": [ - "C:\\Users\\arivas\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache", - "C:\\Users\\arivas\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache", - "C:\\Users\\arivas\\AppData\\Local\\Symbols\\src" - ] } }]]></component> - <component name="RunManager" selected="C++ Project.enginecustom"> + <component name="RunManager" selected="C/C++ Project.enginecustom"> <configuration name="KhaoticDemo" type="CppProject" factoryName="C++ Project"> - <configuration_1> + <configuration_1 setup="1"> <option name="CONFIGURATION" value="Debug" /> <option name="PLATFORM" value="x64" /> - <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/KhaoticDemo/KhaoticDemo.vcxproj" /> <option name="CURRENT_LAUNCH_PROFILE" value="Local" /> <option name="EXE_PATH" value="$(LocalDebuggerCommand)" /> <option name="PROGRAM_PARAMETERS" value="$(LocalDebuggerCommandArguments)" /> @@ -82,18 +74,19 @@ <option name="PASS_PARENT_ENVS" value="1" /> <option name="USE_EXTERNAL_CONSOLE" value="0" /> <option name="TERMINAL_INTERACTION_BEHAVIOR" value="AUTO_DETECT" /> + <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/KhaoticDemo/KhaoticDemo.vcxproj" /> </configuration_1> <option name="DEFAULT_PROJECT_PATH" value="$PROJECT_DIR$/KhaoticDemo/KhaoticDemo.vcxproj" /> + <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/KhaoticDemo/KhaoticDemo.vcxproj" /> <option name="AUTO_SELECT_PRIORITY" value="0" /> <method v="2"> <option name="Build" /> </method> </configuration> <configuration name="enginecustom" type="CppProject" factoryName="C++ Project"> - <configuration_1> + <configuration_1 setup="1"> <option name="CONFIGURATION" value="Debug" /> <option name="PLATFORM" value="x64" /> - <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" /> <option name="CURRENT_LAUNCH_PROFILE" value="Local" /> <option name="EXE_PATH" value="$(LocalDebuggerCommand)" /> <option name="PROGRAM_PARAMETERS" value="$(LocalDebuggerCommandArguments)" /> @@ -101,11 +94,11 @@ <option name="PASS_PARENT_ENVS" value="1" /> <option name="USE_EXTERNAL_CONSOLE" value="0" /> <option name="TERMINAL_INTERACTION_BEHAVIOR" value="AUTO_DETECT" /> + <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" /> </configuration_1> - <configuration_2> + <configuration_2 setup="1"> <option name="CONFIGURATION" value="Release" /> <option name="PLATFORM" value="x64" /> - <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" /> <option name="CURRENT_LAUNCH_PROFILE" value="Local" /> <option name="EXE_PATH" value="$(TargetPath)" /> <option name="PROGRAM_PARAMETERS" value="" /> @@ -113,20 +106,10 @@ <option name="PASS_PARENT_ENVS" value="1" /> <option name="USE_EXTERNAL_CONSOLE" value="0" /> <option name="TERMINAL_INTERACTION_BEHAVIOR" value="AUTO_DETECT" /> + <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" /> </configuration_2> - <configuration_3> - <option name="CONFIGURATION" value="" /> - <option name="PLATFORM" value="" /> - <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" /> - <option name="CURRENT_LAUNCH_PROFILE" value="Local" /> - <option name="EXE_PATH" value="$(TargetPath)" /> - <option name="PROGRAM_PARAMETERS" value="" /> - <option name="WORKING_DIRECTORY" value="$(ProjectDir)" /> - <option name="PASS_PARENT_ENVS" value="1" /> - <option name="USE_EXTERNAL_CONSOLE" value="0" /> - <option name="TERMINAL_INTERACTION_BEHAVIOR" value="AUTO_DETECT" /> - </configuration_3> <option name="DEFAULT_PROJECT_PATH" value="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" /> + <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" /> <option name="AUTO_SELECT_PRIORITY" value="0" /> <method v="2"> <option name="Build" /> @@ -184,6 +167,7 @@ <workItem from="1743355837694" duration="1514000" /> <workItem from="1743370106270" duration="901000" /> <workItem from="1743505399891" duration="2361000" /> + <workItem from="1746106963725" duration="3390000" /> </task> <task id="LOCAL-00001" summary="Minor update - viewport window tweak"> <option name="closed" value="true" /> diff --git a/enginecustom/assets/Texture/imgui.ini b/enginecustom/assets/Texture/imgui.ini index 765b673..596ef8a 100644 --- a/enginecustom/assets/Texture/imgui.ini +++ b/enginecustom/assets/Texture/imgui.ini @@ -1,89 +1,49 @@ +[Window][DockSpace] +Pos=0,0 +Size=2048,1129 +Collapsed=0 + [Window][Debug##Default] Pos=60,60 Size=400,400 Collapsed=0 [Window][Khaotic Engine] -Pos=1233,27 -Size=343,826 +Pos=1687,27 +Size=353,1094 Collapsed=0 -DockId=0x00000005,0 +DockId=0x00000002,0 [Window][Objects] Pos=8,27 -Size=522,826 +Size=345,896 Collapsed=0 -DockId=0x00000009,0 +DockId=0x00000005,0 + +[Window][Engine Settings] +Pos=1687,27 +Size=353,1094 +Collapsed=0 +DockId=0x00000002,1 [Window][Terrain] Pos=8,27 -Size=250,974 +Size=345,896 Collapsed=0 -DockId=0x00000007,0 +DockId=0x00000005,1 [Window][Light] -Pos=8,27 -Size=290,866 -Collapsed=0 -DockId=0x00000007,1 - -[Window][Shader Manager] -Pos=8,27 -Size=330,487 -Collapsed=0 -DockId=0x00000001,2 - -[Window][Engine Settings] -Pos=8,27 -Size=289,974 -Collapsed=0 -DockId=0x00000009,0 - -[Window][DockSpace Demo] -Size=1584,861 -Collapsed=0 - -[Window][Render Window] -Pos=8,27 -Size=1559,974 -Collapsed=0 -DockId=0x00000009,0 - -[Window][DockSpace] -Pos=0,0 -Size=1584,861 -Collapsed=0 - -[Window][Add Object] -Pos=1188,0 -Size=396,430 -Collapsed=0 - -[Window][Log] -Pos=8,518 -Size=1568,335 -Collapsed=0 -DockId=0x0000000C,0 - -[Window][Log Window] -Pos=8,627 -Size=1568,226 +Pos=8,925 +Size=345,196 Collapsed=0 DockId=0x00000006,0 [Docking][Data] -DockSpace ID=0xC0DFADC4 Pos=8,27 Size=1568,826 Split=X - DockNode ID=0x00000001 Parent=0xC0DFADC4 SizeRef=330,1094 Selected=0x393905AB - DockNode ID=0x00000003 Parent=0xC0DFADC4 SizeRef=1700,1094 CentralNode=1 -DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=8,27 Size=1568,826 Split=X - DockNode ID=0x00000009 Parent=0xCCBD8CF7 SizeRef=522,974 Selected=0x031DC75C - DockNode ID=0x0000000D Parent=0xCCBD8CF7 SizeRef=1044,974 Split=X - DockNode ID=0x00000002 Parent=0x0000000D SizeRef=699,826 Split=Y - DockNode ID=0x00000004 Parent=0x00000002 SizeRef=2032,866 Split=Y - DockNode ID=0x0000000B Parent=0x00000004 SizeRef=1568,637 Split=X - DockNode ID=0x00000007 Parent=0x0000000B SizeRef=250,826 Selected=0x393905AB - DockNode ID=0x00000008 Parent=0x0000000B SizeRef=971,826 CentralNode=1 Selected=0x031DC75C - DockNode ID=0x0000000C Parent=0x00000004 SizeRef=1568,335 Selected=0x139FDA3F - DockNode ID=0x00000006 Parent=0x00000002 SizeRef=2032,226 Selected=0xAB74BEE9 - DockNode ID=0x00000005 Parent=0x0000000D SizeRef=343,826 Selected=0x9F035453 +DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=8,27 Size=2032,1094 Split=X + DockNode ID=0x00000003 Parent=0xCCBD8CF7 SizeRef=345,826 Split=Y Selected=0x393905AB + DockNode ID=0x00000005 Parent=0x00000003 SizeRef=345,896 Selected=0x393905AB + DockNode ID=0x00000006 Parent=0x00000003 SizeRef=345,196 Selected=0x321620B2 + DockNode ID=0x00000004 Parent=0xCCBD8CF7 SizeRef=1221,826 Split=X + DockNode ID=0x00000001 Parent=0x00000004 SizeRef=866,826 CentralNode=1 + DockNode ID=0x00000002 Parent=0x00000004 SizeRef=353,826 Selected=0x9F035453 diff --git a/enginecustom/demo.ker b/enginecustom/demo.ker new file mode 100644 index 0000000..33afb2a --- /dev/null +++ b/enginecustom/demo.ker @@ -0,0 +1 @@ +0 86 111.063 12.7056 0 0 -0 0 1 1 1 Content/Assets/Kobject/86.obj CEL_SHADING 1 Cube 1 1 diff --git a/enginecustom/enginecustom.vcxproj b/enginecustom/enginecustom.vcxproj index e1bd7a4..4e7d937 100644 --- a/enginecustom/enginecustom.vcxproj +++ b/enginecustom/enginecustom.vcxproj @@ -66,6 +66,7 @@ <ClCompile Include="src\src\system\physics.cpp" /> <ClCompile Include="src\src\system\Positionclass.cpp" /> <ClCompile Include="src\src\system\rendertextureclass.cpp" /> + <ClCompile Include="src\src\system\Skybox.cpp" /> <ClCompile Include="src\src\system\Spriteclass.cpp" /> <ClCompile Include="src\src\system\Systemclass.cpp" /> <ClCompile Include="src\src\system\textclass.cpp" /> @@ -125,6 +126,7 @@ <ClInclude Include="src\inc\system\Positionclass.h" /> <ClInclude Include="src\inc\system\rendertextureclass.h" /> <ClInclude Include="src\inc\system\sceneManager.h" /> + <ClInclude Include="src\inc\system\Skybox.h" /> <ClInclude Include="src\inc\system\Spriteclass.h" /> <ClInclude Include="src\inc\system\systemclass.h" /> <ClInclude Include="src\inc\system\textclass.h" /> diff --git a/enginecustom/src/inc/system/Skybox.h b/enginecustom/src/inc/system/Skybox.h new file mode 100644 index 0000000..1d332fb --- /dev/null +++ b/enginecustom/src/inc/system/Skybox.h @@ -0,0 +1,30 @@ +#pragma once +#include <vector> + +#include "d3dclass.h" +#include "object.h" + +class Skybox +{ +public: + + Skybox(); + ~Skybox(); + + void Initialize(D3DClass* d3dClassRef); // Get all the required references + + Object* ConstructSkybox(); + + + // Variables + + std::vector<ID3D11ShaderResourceView*> textures; + std::vector<XMMATRIX> translations; + +private: + + D3DClass* m_d3dClassRef; // Reference to the D3DClass instance + Object* m_Skybox; + + +}; diff --git a/enginecustom/src/inc/system/applicationclass.h b/enginecustom/src/inc/system/applicationclass.h index f5999f1..bbb5597 100644 --- a/enginecustom/src/inc/system/applicationclass.h +++ b/enginecustom/src/inc/system/applicationclass.h @@ -30,8 +30,10 @@ #include "reflectionshaderclass.h" #include "physics.h" #include "frustum.h" -#include <fstream> +#include "skybox.h" + +#include <fstream> #include <WICTextureLoader.h> #include <comdef.h> // Pour _com_error #include <chrono> @@ -167,13 +169,10 @@ private: bool RenderReflectionToTexture(); bool RenderPass(const std::vector<std::reference_wrapper<std::vector<Object*>>>& RenderQueues, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection); - void ConstructSkybox(); // Construct the skybox - void UpdateSkyboxPosition(); // Update the skybox position - bool RenderSkybox(XMMATRIX view, XMMATRIX projection); // Render the skybox + void UpdateSkyboxPosition(); public : std::vector<ID3D11ShaderResourceView*> textures; - std::vector<ID3D11ShaderResourceView*> m_SkyboxTextures; private : @@ -203,7 +202,6 @@ private : int m_screenWidth, m_screenHeight; CameraClass* m_Camera; PositionClass* m_Position; - std::vector<XMMATRIX> m_SkyboxInitialTranslations; // ------------------------------------ // // ------------- OBJECTS -------------- // diff --git a/enginecustom/src/src/system/Positionclass.cpp b/enginecustom/src/src/system/Positionclass.cpp index b94c2da..3005071 100644 --- a/enginecustom/src/src/system/Positionclass.cpp +++ b/enginecustom/src/src/system/Positionclass.cpp @@ -12,7 +12,6 @@ PositionClass::PositionClass() m_rightTurnSpeed = 0.0f; m_horizontalTurnSpeed = 0.0f; m_verticalTurnSpeed = 0.0f; - m_verticalTurnSpeed = 0.0f; m_cameraSpeed = 4.0f; m_speed = m_cameraSpeed; } diff --git a/enginecustom/src/src/system/Skybox.cpp b/enginecustom/src/src/system/Skybox.cpp new file mode 100644 index 0000000..0c0b685 --- /dev/null +++ b/enginecustom/src/src/system/Skybox.cpp @@ -0,0 +1,69 @@ +#include "Skybox.h" + +Skybox::Skybox() +{ +} + +Skybox::~Skybox() +{ + for (auto& texture : textures) + { + if (texture) + { + texture->Release(); + texture = nullptr; + } + } + textures.clear(); + translations.clear(); +} + +void Skybox::Initialize(D3DClass* d3dClassRef) +{ + m_d3dClassRef = d3dClassRef; +} + +Object* Skybox::ConstructSkybox() +{ + Logger::Get().Log("Construct skybox", __FILE__, __LINE__, Logger::LogLevel::Initialize); + + char modelFilename[128]; + strcpy_s(modelFilename, "assets/Model/OBJ/invertcube.obj"); + + textures.clear(); + std::vector<std::wstring> skyboxTextures = { + L"assets/Skybox/skybox_front.png", + L"assets/Skybox/skybox_back.png", + L"assets/Skybox/skybox_left.png", + L"assets/Skybox/skybox_right.png", + L"assets/Skybox/skybox_top.png", + L"assets/Skybox/skybox_bottom.png" + }; + + // Load the textures + for (const auto& textureFilename : skyboxTextures) + { + ID3D11ShaderResourceView* texture = nullptr; + HRESULT result = DirectX::CreateWICTextureFromFile(m_d3dClassRef->GetDevice(), m_d3dClassRef->GetDeviceContext(), textureFilename.c_str(), nullptr, &texture); + if (FAILED(result)) + { + Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error); + return nullptr; + } + textures.push_back(texture); + } + + // Create the model object + m_Skybox = new Object(); + HRESULT result = m_Skybox->Initialize(m_d3dClassRef->GetDevice(), m_d3dClassRef->GetDeviceContext(), modelFilename, textures); + if (!result) + { + Logger::Get().Log("Could not initialize the skybox model object", __FILE__, __LINE__, Logger::LogLevel::Error); + delete m_Skybox; + return nullptr; + } + m_Skybox->SetTranslateMatrix(XMMatrixTranslation(0.0f, 0.0f, 0.0f)); // Set the initial translation of the skybox + m_Skybox->SetActiveShader(ShaderType::SKYBOX); + + return m_Skybox; // Return the constructed skybox object +} \ No newline at end of file diff --git a/enginecustom/src/src/system/applicationclass.cpp b/enginecustom/src/src/system/applicationclass.cpp index d0190db..89f4338 100644 --- a/enginecustom/src/src/system/applicationclass.cpp +++ b/enginecustom/src/src/system/applicationclass.cpp @@ -81,6 +81,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd, m_RenderQueues.push_back(std::ref(m_object)); m_RenderQueues.push_back(std::ref(m_cubes)); m_RenderQueues.push_back(std::ref(m_terrainChunk)); + m_RenderQueues.push_back(std::ref(m_Skybox)); m_screenWidth = screenWidth; m_screenHeight = screenHeight; @@ -454,7 +455,10 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd, m_PhysicsThread = std::thread(&ApplicationClass::PhysicsThreadFunction, this); - ConstructSkybox(); + //ConstructSkyboxWithPlanes(); + Skybox* skybox = new Skybox; + skybox->Initialize(m_Direct3D); + m_Skybox.push_back(skybox->ConstructSkybox()); } catch (const std::exception& e) @@ -1026,20 +1030,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t diffuseColor, lightPosition, ambientColor); UpdateSkyboxPosition(); // Update the position of the skybox to match the camera position. - - // ------------------------------------------------------------- // - // --------------------- Render the skybox --------------------- // - // ------------------------------------------------------------- // - - m_Direct3D->TurnZBufferOff(); // Disable the Z buffer for rendering the skybox. - - result = RenderSkybox(viewMatrix, projectionMatrix); // Render the skybox. - if (!result) - { - Logger::Get().Log("Could not render the skybox", __FILE__, __LINE__, Logger::LogLevel::Error); - return false; - } - + m_Direct3D->TurnZBufferOn(); // Enable the Z buffer after rendering the skybox. // -------------------------------------------------------- // @@ -2010,70 +2001,6 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std:: return true; } -void ApplicationClass::ConstructSkybox() { - Logger::Get().Log("Initializing skybox", __FILE__, __LINE__, Logger::LogLevel::Initialize); - - char modelFilename[128]; - strcpy_s(modelFilename, "assets/Model/OBJ/plane.obj"); - - // Liste des fichiers de texture pour chaque face du skybox - std::vector<std::wstring> skyboxTextures = { - L"assets/Skybox/skybox_front.png", - L"assets/Skybox/skybox_back.png", - L"assets/Skybox/skybox_left.png", - L"assets/Skybox/skybox_right.png", - L"assets/Skybox/skybox_top.png", - L"assets/Skybox/skybox_bottom.png" - }; - - // Charger les textures - std::vector<ID3D11ShaderResourceView*> textures; - for (const auto& textureFilename : skyboxTextures) - { - ID3D11ShaderResourceView* texture = nullptr; - HRESULT result = DirectX::CreateWICTextureFromFile(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), textureFilename.c_str(), nullptr, &texture); - if (FAILED(result)) - { - Logger::Get().Log("Failed to load skybox texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error); - return; - } - textures.push_back(texture); - } - - // Cr�er les 6 faces du skybox - std::vector<XMMATRIX> translations = { - XMMatrixTranslation(0.0f, 0.0f, 1.0f), // Front - XMMatrixTranslation(0.0f, 0.0f, -1.0f), // Back - XMMatrixTranslation(-1.0f, 0.0f, 0.0f), // Left - XMMatrixTranslation(1.0f, 0.0f, 0.0f), // Right - XMMatrixTranslation(0.0f, 1.0f, 0.0f), // Top - XMMatrixTranslation(0.0f, -1.0f, 0.0f) // Bottom - }; - - std::vector<XMMATRIX> rotations = { - XMMatrixRotationRollPitchYaw(-XM_PIDIV2, 0, 0.0f), // Front - XMMatrixRotationRollPitchYaw(XM_PIDIV2, 0, 0.0f), // Back - XMMatrixRotationRollPitchYaw(XM_PIDIV2, XM_PIDIV2, 0.0f), // Left - XMMatrixRotationRollPitchYaw(XM_PIDIV2, -XM_PIDIV2, 0.0f), // Right - XMMatrixRotationRollPitchYaw(XM_PI, 0.0f, 0.0f), // top - XMMatrixRotationRollPitchYaw(0.0f, 0.0f, 0.0f) // Bottom - }; - - for (int i = 0; i < 6; ++i) - { - Object* face = new Object(); - face->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, { textures[i] }); - face->SetScaleMatrix(XMMatrixScaling(2.01f, 2.01f, 2.01f)); - face->SetRotateMatrix(rotations[i]); - face->SetTranslateMatrix(translations[i]); - face->SetActiveShader(ShaderType::SKYBOX); - m_Skybox.push_back(face); - m_SkyboxInitialTranslations.push_back(translations[i]); - } - - Logger::Get().Log("Skybox initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); -} - void ApplicationClass::ConstructFrustum() { XMMATRIX projectionMatrix = m_Direct3D->GetProjectionMatrix(); @@ -2083,6 +2010,20 @@ void ApplicationClass::ConstructFrustum() m_FrustumCulling.ConstructFrustum(SCREEN_DEPTH, projectionMatrix, viewMatrix); } +// Update the position of the skybox based on the camera position +void ApplicationClass::UpdateSkyboxPosition() +{ + + if (m_Skybox.empty()) + { + Logger::Get().Log("Skybox is empty", __FILE__, __LINE__, Logger::LogLevel::Error); + return; + } + + m_Skybox[0]->SetTranslateMatrix(XMMatrixTranslation(m_Camera->GetPosition().x, m_Camera->GetPosition().y, m_Camera->GetPosition().z)); + +} + bool ApplicationClass::RenderPhysics(bool keyLeft, bool keyRight, bool keyUp, bool keyDown, float deltaTime) { const float maxSpeed = 50.0f; // Limite de vitesse maximale @@ -2190,47 +2131,6 @@ void ApplicationClass::PhysicsThreadFunction() } } -void ApplicationClass::UpdateSkyboxPosition() { - XMFLOAT3 cameraPositionFloat3 = m_Camera->GetPosition(); - XMVECTOR cameraPosition = XMLoadFloat3(&cameraPositionFloat3); - for (size_t i = 0; i < m_Skybox.size(); ++i) { - Object* face = m_Skybox[i]; - XMMATRIX initialTranslation = m_SkyboxInitialTranslations[i]; - XMVECTOR initialTranslationVector = initialTranslation.r[3]; - XMVECTOR newTranslation = XMVectorAdd(cameraPosition, initialTranslationVector); - XMMATRIX translateMatrix = XMMatrixTranslationFromVector(newTranslation); - face->SetTranslateMatrix(translateMatrix); - } -} - -bool ApplicationClass::RenderSkybox(XMMATRIX view, XMMATRIX projection) { - - bool result; - XMMATRIX worldMatrix, scaleMatrix, rotateMatrix, translateMatrix, srMatrix; - - for (auto& face : m_Skybox) { - if (face == nullptr) { - Logger::Get().Log("Skybox face is null", __FILE__, __LINE__, Logger::LogLevel::Error); - return false; - } - scaleMatrix = face->GetScaleMatrix(); - rotateMatrix = face->GetRotateMatrix(); - translateMatrix = face->GetTranslateMatrix(); - srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix); - worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix); - face->Render(m_Direct3D->GetDeviceContext()); - result = m_ShaderManager->RenderTextureShader(m_Direct3D->GetDeviceContext(), face->GetIndexCount(), worldMatrix, view, projection, face->GetTexture(0)); - if (!result) - { - Logger::Get().Log("Could not render the model using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error); - return false; - } - } - - - return true; -} - std::string ApplicationClass::ConvertWStringToString(const std::wstring& wstr) { if (wstr.empty()) return std::string();