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 @@
-
+
+
\ 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 @@
+
+
-
-
-
+
+
+
+
-
-
@@ -26,10 +27,9 @@
-
-
+
@@ -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"
- ]
}
}]]>
-
+
-
+
-
@@ -82,18 +74,19 @@
+
+
-
+
-
@@ -101,11 +94,11 @@
+
-
+
-
@@ -113,20 +106,10 @@
+
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -184,6 +167,7 @@
+
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 @@
+
@@ -125,6 +126,7 @@
+
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
+
+#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 textures;
+ std::vector 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
+#include "skybox.h"
+
+#include
#include
#include // Pour _com_error
#include
@@ -167,13 +169,10 @@ private:
bool RenderReflectionToTexture();
bool RenderPass(const std::vector>>& 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 textures;
- std::vector m_SkyboxTextures;
private :
@@ -203,7 +202,6 @@ private :
int m_screenWidth, m_screenHeight;
CameraClass* m_Camera;
PositionClass* m_Position;
- std::vector 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 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 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 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 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 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();