diff --git a/KhaoticDemo/KhaoticDemo.vcxproj b/KhaoticDemo/KhaoticDemo.vcxproj
new file mode 100644
index 0000000..d17dbb5
--- /dev/null
+++ b/KhaoticDemo/KhaoticDemo.vcxproj
@@ -0,0 +1,140 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 17.0
+ Win32Proj
+ {9e5ef415-5337-4eed-ae23-edc4b1fff455}
+ KhaoticDemo
+ 10.0
+
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Level3
+ true
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+ Level3
+ true
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+ {92cf56c4-76bb-40d4-8fe5-36c15f5f127a}
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/KhaoticDemo/KhaoticDemo.vcxproj.filters b/KhaoticDemo/KhaoticDemo.vcxproj.filters
new file mode 100644
index 0000000..5d997ac
--- /dev/null
+++ b/KhaoticDemo/KhaoticDemo.vcxproj.filters
@@ -0,0 +1,22 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ Fichiers sources
+
+
+
\ No newline at end of file
diff --git a/KhaoticDemo/main.cpp b/KhaoticDemo/main.cpp
new file mode 100644
index 0000000..e69de29
diff --git a/README.md b/README.md
index 30738b3..ccf1aa7 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,29 @@
-[](https://classroom.github.com/a/Ki-dD_5X)
-# Khaotic Engine
+# Khaotic Engine - C++ Custom Engine
+
+Khaotic Engine est un moteur de rendu fait en c++ réalisé par une petite équipe dans le but d'apprendre a utilisé les API de rendu (OpenGL,DirectX 11/12 et Vulkan).
+
+Ce moteur est basé sur DirectX11 utilise ImGui avec une couche d'abstraction pour permetre son usage avec d'autre API.
+
+---
+
+Khaotic Engine is a rendering engine made in C++ by a small team with the aim of learning how to use rendering APIs (OpenGL, DirectX 11/12 and Vulkan).
+
+This DirectX11-based engine uses ImGui with an abstraction layer to enable its use with other APIs.
+
+
+
+## Demo
+
+[](https://www.youtube.com/watch?v=qCOCTyB_97c)
-A custom engine build with chaos and DirectX11 in less than 5 weeks in C++.
## Engine Build by :
+
- [@CatChow0](https://github.com/CatChow0)
- [@miragefr0st](https://github.com/miragefr0st)
- [@StratiX0](https://github.com/StratiX0)
- [@Kagutsuchi84](https://github.com/Mattys8423)
+- [@Harpie94](https://github.com/Harpie94)
+- [@axelpicou](https://github.com/axelpicou)
+- [@GolfOcean334](https://github.com/GolfOcean334)
diff --git a/enginecustom.sln b/enginecustom.sln
index 1ae2734..1248089 100644
--- a/enginecustom.sln
+++ b/enginecustom.sln
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.9.34607.119
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "enginecustom", "enginecustom\enginecustom.vcxproj", "{92CF56C4-76BB-40D4-8FE5-36C15F5F127A}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KhaoticDemo", "KhaoticDemo\KhaoticDemo.vcxproj", "{9E5EF415-5337-4EED-AE23-EDC4B1FFF455}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -21,6 +23,14 @@ Global
{92CF56C4-76BB-40D4-8FE5-36C15F5F127A}.Release|x64.Build.0 = Release|x64
{92CF56C4-76BB-40D4-8FE5-36C15F5F127A}.Release|x86.ActiveCfg = Release|Win32
{92CF56C4-76BB-40D4-8FE5-36C15F5F127A}.Release|x86.Build.0 = Release|Win32
+ {9E5EF415-5337-4EED-AE23-EDC4B1FFF455}.Debug|x64.ActiveCfg = Debug|x64
+ {9E5EF415-5337-4EED-AE23-EDC4B1FFF455}.Debug|x64.Build.0 = Debug|x64
+ {9E5EF415-5337-4EED-AE23-EDC4B1FFF455}.Debug|x86.ActiveCfg = Debug|Win32
+ {9E5EF415-5337-4EED-AE23-EDC4B1FFF455}.Debug|x86.Build.0 = Debug|Win32
+ {9E5EF415-5337-4EED-AE23-EDC4B1FFF455}.Release|x64.ActiveCfg = Release|x64
+ {9E5EF415-5337-4EED-AE23-EDC4B1FFF455}.Release|x64.Build.0 = Release|x64
+ {9E5EF415-5337-4EED-AE23-EDC4B1FFF455}.Release|x86.ActiveCfg = Release|Win32
+ {9E5EF415-5337-4EED-AE23-EDC4B1FFF455}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/enginecustom/Cameraclass.cpp b/enginecustom/Cameraclass.cpp
index 0520dd2..b76598a 100644
--- a/enginecustom/Cameraclass.cpp
+++ b/enginecustom/Cameraclass.cpp
@@ -105,8 +105,67 @@ void CameraClass::Render()
return;
}
-void CameraClass::GetViewMatrix(XMMATRIX& viewMatrix)
+XMMATRIX CameraClass::GetViewMatrix(XMMATRIX& viewMatrix)
{
viewMatrix = m_viewMatrix;
+ return viewMatrix;
+}
+
+void CameraClass::RenderReflection(float height)
+{
+ XMFLOAT3 up, position, lookAt;
+ XMVECTOR upVector, positionVector, lookAtVector;
+ float yaw, pitch, roll;
+ XMMATRIX rotationMatrix;
+
+
+ // Setup the vector that points upwards.
+ up.x = 0.0f;
+ up.y = 1.0f;
+ up.z = 0.0f;
+
+ // Load it into a XMVECTOR structure.
+ upVector = XMLoadFloat3(&up);
+
+ // Setup the position of the camera in the world.
+ position.x = m_positionX;
+ position.y = -m_positionY + (height * 2.0f);
+ position.z = m_positionZ;
+
+ // Load it into a XMVECTOR structure.
+ positionVector = XMLoadFloat3(&position);
+
+ // Setup where the camera is looking by default.
+ lookAt.x = 0.0f;
+ lookAt.y = 0.0f;
+ lookAt.z = 1.0f;
+
+ // Load it into a XMVECTOR structure.
+ lookAtVector = XMLoadFloat3(&lookAt);
+
+ // Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
+ pitch = (-1.0f * m_rotationX) * 0.0174532925f; // Invert for reflection
+ yaw = m_rotationY * 0.0174532925f;
+ roll = m_rotationZ * 0.0174532925f;
+
+ // Create the rotation matrix from the yaw, pitch, and roll values.
+ rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll);
+
+ // Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
+ lookAtVector = XMVector3TransformCoord(lookAtVector, rotationMatrix);
+ upVector = XMVector3TransformCoord(upVector, rotationMatrix);
+
+ // Translate the rotated camera position to the location of the viewer.
+ lookAtVector = XMVectorAdd(positionVector, lookAtVector);
+
+ // Finally create the view matrix from the three updated vectors.
+ m_reflectionViewMatrix = XMMatrixLookAtLH(positionVector, lookAtVector, upVector);
+
+ return;
+}
+
+void CameraClass::GetReflectionViewMatrix(XMMATRIX& reflectionViewMatrix)
+{
+ reflectionViewMatrix = m_reflectionViewMatrix;
return;
}
\ No newline at end of file
diff --git a/enginecustom/Cameraclass.h b/enginecustom/Cameraclass.h
index 1c4cfed..fe41bdd 100644
--- a/enginecustom/Cameraclass.h
+++ b/enginecustom/Cameraclass.h
@@ -28,13 +28,19 @@ public:
XMFLOAT3 GetPosition();
XMFLOAT3 GetRotation();
+
void Render();
- void GetViewMatrix(XMMATRIX&);
+ XMMATRIX GetViewMatrix(XMMATRIX& viewMatrix);
+
+ void RenderReflection(float);
+ void GetReflectionViewMatrix(XMMATRIX&);
private:
float m_positionX, m_positionY, m_positionZ;
float m_rotationX, m_rotationY, m_rotationZ;
XMMATRIX m_viewMatrix;
+ XMMATRIX m_reflectionViewMatrix;
+
};
#endif
\ No newline at end of file
diff --git a/enginecustom/Positionclass.cpp b/enginecustom/Positionclass.cpp
index 1e66b88..cf05768 100644
--- a/enginecustom/Positionclass.cpp
+++ b/enginecustom/Positionclass.cpp
@@ -108,37 +108,39 @@ void PositionClass::TurnRight(bool keydown)
return;
}
-void PositionClass::TurnMouse(float deltaX, float deltaY)
+void PositionClass::TurnMouse(float deltaX, float deltaY, bool rightMouseDown)
{
float speed = 0.1f;
// The turning speed is proportional to the horizontal mouse movement
m_horizontalTurnSpeed = deltaX * speed;
- // Update the rotation using the turning speed
- m_rotationY += m_horizontalTurnSpeed;
- if (m_rotationY < 0.0f)
+ if (rightMouseDown)
{
- m_rotationY += 360.0f;
- }
- else if (m_rotationY > 360.0f)
- {
- m_rotationY -= 360.0f;
- }
+ // Update the rotation using the turning speed
+ m_rotationY += m_horizontalTurnSpeed;
+ if (m_rotationY < 0.0f)
+ {
+ m_rotationY += 360.0f;
+ }
+ else if (m_rotationY > 360.0f)
+ {
+ m_rotationY -= 360.0f;
+ }
- // The turning speed is proportional to the vertical mouse movement
- m_verticalTurnSpeed = deltaY * speed;
+ // The turning speed is proportional to the vertical mouse movement
+ m_verticalTurnSpeed = deltaY * speed;
- // Update the rotation using the turning speed
- m_rotationX += m_verticalTurnSpeed;
- if (m_rotationX < -90.0f)
- {
- m_rotationX = -90.0f;
+ // Update the rotation using the turning speed
+ m_rotationX += m_verticalTurnSpeed;
+ if (m_rotationX < -90.0f)
+ {
+ m_rotationX = -90.0f;
+ }
+ else if (m_rotationX > 90.0f)
+ {
+ m_rotationX = 90.0f;
+ }
}
- else if (m_rotationX > 90.0f)
- {
- m_rotationX = 90.0f;
- }
-
return;
}
diff --git a/enginecustom/Positionclass.h b/enginecustom/Positionclass.h
index 5048610..7123aca 100644
--- a/enginecustom/Positionclass.h
+++ b/enginecustom/Positionclass.h
@@ -24,7 +24,7 @@ public:
void TurnLeft(bool);
void TurnRight(bool);
- void TurnMouse(float, float);
+ void TurnMouse(float, float, bool);
void MoveCamera(bool, bool, bool, bool, bool, bool);
private:
diff --git a/enginecustom/Systemclass.cpp b/enginecustom/Systemclass.cpp
index fe8abac..c5ebe29 100644
--- a/enginecustom/Systemclass.cpp
+++ b/enginecustom/Systemclass.cpp
@@ -1,9 +1,14 @@
#include "systemclass.h"
+#include
+#include // Include for DragAcceptFiles and DragQueryFile
+#include
+extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
SystemClass::SystemClass()
{
m_Input = 0;
m_Application = 0;
+ m_imguiManager = 0;
}
SystemClass::SystemClass(const SystemClass& other)
@@ -24,6 +29,10 @@ bool SystemClass::Initialize()
// Initialize the width and height of the screen to zero before sending the variables into the function.
screenWidth = 0;
screenHeight = 0;
+
+ m_initialWindowWidth = 0;
+ m_initialWindowHeight = 0;
+ m_isDirect3DInitialized = false;
// Initialize the windows api.
InitializeWindows(screenWidth, screenHeight);
@@ -46,6 +55,19 @@ bool SystemClass::Initialize()
return false;
}
+ m_isDirect3DInitialized = true;
+
+ // If we received a WM_SIZE message before Direct3D was initialized, resize the swap chain now
+ if (m_initialWindowWidth > 0 && m_initialWindowHeight > 0)
+ {
+ m_Application->GetDirect3D()->ResizeSwapChain(m_initialWindowWidth, m_initialWindowHeight);
+ }
+
+ // Initialize imgui
+ m_imguiManager = new imguiManager;
+ m_imguiManager->Initialize(m_hwnd, m_Application->GetDirect3D()->GetDevice(), m_Application->GetDirect3D()->GetDeviceContext());
+
+
return true;
}
@@ -66,6 +88,14 @@ void SystemClass::Shutdown()
m_Input = 0;
}
+ // Shutdown imgui
+ if (m_imguiManager)
+ {
+ m_imguiManager->Shutdown();
+ delete m_imguiManager;
+ m_imguiManager = 0;
+ }
+
// Shutdown the window.
ShutdownWindows();
@@ -77,7 +107,6 @@ void SystemClass::Run()
MSG msg;
bool done, result;
-
// Initialize the message structure.
ZeroMemory(&msg, sizeof(MSG));
@@ -130,12 +159,99 @@ bool SystemClass::Frame()
return false;
}
+ // Render ImGui
+ m_imguiManager->ImGuiWidgetRenderer(m_Application);
+
return true;
}
LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam)
{
- return DefWindowProc(hwnd, umsg, wparam, lparam);
+
+ if (ImGui_ImplWin32_WndProcHandler(hwnd, umsg, wparam, lparam))
+ {
+ return true;
+ }
+
+ switch (umsg)
+ {
+ // Check if a key has been pressed on the keyboard.
+ case WM_KEYDOWN:
+ {
+ // If a key is pressed send it to the input object so it can record that state.
+ m_Input->KeyDown((unsigned int)wparam);
+ return 0;
+ }
+
+ // Check if a key has been released on the keyboard.
+ case WM_KEYUP:
+ {
+ // If a key is released then send it to the input object so it can unset the state for that key.
+ m_Input->KeyUp((unsigned int)wparam);
+ return 0;
+ }
+ case WM_SIZE:
+ {
+ int newWidth = LOWORD(lparam);
+ int newHeight = HIWORD(lparam);
+
+ // If Direct3D is initialized, update the swap chain. Otherwise, store the window dimensions
+ if (m_isDirect3DInitialized && m_Application && m_Application->GetDirect3D())
+ {
+ m_Application->GetDirect3D()->ResizeSwapChain(newWidth, newHeight);
+ }
+ else
+ {
+ m_initialWindowWidth = newWidth;
+ m_initialWindowHeight = newHeight;
+ }
+ }
+ case WM_ENTERSIZEMOVE:
+ {
+ m_isResizing = true;
+ break;
+ }
+ case WM_EXITSIZEMOVE:
+ {
+ m_isResizing = false;
+ break;
+ }
+ case WM_DROPFILES:
+ {
+ HDROP hDrop = reinterpret_cast(wparam);
+ UINT numFiles = DragQueryFile(hDrop, 0xFFFFFFFF, nullptr, 0);
+
+ if (numFiles > 0) {
+ for (UINT i = 0; i < numFiles; ++i) {
+ WCHAR filePath[MAX_PATH];
+ DragQueryFile(hDrop, i, filePath, MAX_PATH);
+
+ // Get the file extension
+ std::wstring fileName = filePath;
+ std::wstring extension = fileName.substr(fileName.find_last_of(L".") + 1);
+
+ // Check if the file has a valid extension
+ if (extension == L"txt" || extension == L"kobj") {
+ // Handle dropped files with valid extensions
+ std::wcout << L"File dropped: " << filePath << std::endl;
+ m_Application->AddKobject(filePath);
+ }
+ else {
+ // Handle files with invalid extensions (optional)
+ std::wcout << L"Ignored file: " << filePath << std::endl;
+ }
+ }
+ }
+
+ DragFinish(hDrop);
+ return 0;
+ }
+ // Any other messages send to the default message handler as our application won't make use of them.
+ default:
+ {
+ return DefWindowProc(hwnd, umsg, wparam, lparam);
+ }
+ }
}
void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
@@ -152,7 +268,7 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
m_hinstance = GetModuleHandle(NULL);
// Give the application a name.
- m_applicationName = L"Engine";
+ m_applicationName = L"Khaotic Engine";
// Setup the windows class with default settings.
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
@@ -205,7 +321,7 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
// Create the window with the screen settings and get the handle to it.
m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName,
- WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
+ WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL);
// Bring the window up on the screen and set it as main focus.
@@ -214,7 +330,10 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
SetFocus(m_hwnd);
// Hide the mouse cursor.
- ShowCursor(false);
+ ShowCursor(true);
+
+ //drag and drop
+ DragAcceptFiles(m_hwnd, TRUE);
return;
}
@@ -241,6 +360,11 @@ void SystemClass::ShutdownWindows()
// Release the pointer to this class.
ApplicationHandle = NULL;
+ //Releases COM references that ImGui was given on setup
+ ImGui_ImplDX11_Shutdown();
+ ImGui_ImplWin32_Shutdown();
+ ImGui::DestroyContext();
+
return;
}
@@ -262,10 +386,16 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam)
return 0;
}
+ case WM_DROPFILES:
+ {
+ ApplicationHandle->MessageHandler(hwnd, umessage, wparam, lparam);
+ return(0);
+ }
+
// All other messages pass to the message handler in the system class.
default:
{
return ApplicationHandle->MessageHandler(hwnd, umessage, wparam, lparam);
}
}
-}
+}
\ No newline at end of file
diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp
index 2e78ff6..e22e1a9 100644
--- a/enginecustom/applicationclass.cpp
+++ b/enginecustom/applicationclass.cpp
@@ -25,6 +25,7 @@ ApplicationClass::ApplicationClass()
m_Position = 0;
m_Frustum = 0;
m_DisplayPlane = 0;
+ m_ReflectionShader = 0;
}
@@ -58,7 +59,6 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
return false;
}
- // Initialize the Direct3D object.
result = m_Direct3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR);
if (!result)
{
@@ -357,6 +357,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
{
return false;
}
+
return true;
}
@@ -420,6 +421,7 @@ void ApplicationClass::Shutdown()
delete[] m_MouseStrings;
m_MouseStrings = 0;
}
+
// Release the text object for the fps string.
if (m_FpsString)
{
@@ -523,7 +525,7 @@ void ApplicationClass::Shutdown()
bool ApplicationClass::Frame(InputClass* Input)
{
int mouseX, mouseY, currentMouseX, currentMouseY;
- bool result, mouseDown, keyDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE;
+ bool result, leftMouseDown, rightMouseDown, keyDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE;
float rotationY, rotationX, positionX, positionY, positionZ;
static float textureTranslation = 0.0f;
@@ -551,6 +553,10 @@ bool ApplicationClass::Frame(InputClass* Input)
// Get the location of the mouse from the input object,
Input->GetMouseLocation(mouseX, mouseY);
+ // Check if the mouse has been pressed.
+ leftMouseDown = Input->IsLeftMousePressed();
+ rightMouseDown = Input->IsRightMousePressed();
+
currentMouseX = mouseX;
float deltaX = currentMouseX - lastMouseX; // Calculez le d�placement de la souris
@@ -571,7 +577,7 @@ bool ApplicationClass::Frame(InputClass* Input)
keyDown = Input->IsRightArrowPressed();
m_Position->TurnRight(keyDown);
- m_Position->TurnMouse(deltaX, deltaY);
+ m_Position->TurnMouse(deltaX, deltaY, rightMouseDown);
// Get the current view point rotation.
m_Position->GetRotation(rotationY, rotationX);
@@ -606,7 +612,7 @@ bool ApplicationClass::Frame(InputClass* Input)
}
// Update the rotation variable each frame.
- rotation -= 0.0174532925f * 0.8f;
+ rotation -= 0.0174532925f * speed;
if (rotation < 0.0f)
{
rotation += 360.0f;
@@ -631,7 +637,7 @@ bool ApplicationClass::Frame(InputClass* Input)
mouseDown = Input->IsMousePressed();
// Update the mouse strings each frame.
- result = UpdateMouseStrings(mouseX, mouseY, mouseDown);
+ result = UpdateMouseStrings(mouseX, mouseY, leftMouseDown);
if (!result)
{
return false;
@@ -667,7 +673,6 @@ bool ApplicationClass::RenderSceneToTexture(float rotation)
m_RenderTexture->ClearRenderTarget(m_Direct3D->GetDeviceContext(), 0.0f, 0.5f, 1.0f, 1.0f);
// Set the position of the camera for viewing the cube.
- m_Camera->SetPosition(0.0f, 0.0f, -5.0f);
m_Camera->Render();
// Get the matrices.
@@ -706,7 +711,6 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Direct3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
// Generate the view matrix based on the camera's position.
- m_Camera->SetPosition(0.0f, 0.0f, -10.0f);
m_Camera->Render();
// Get the world, view, and projection matrices from the camera and d3d objects.
@@ -715,6 +719,103 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Direct3D->GetProjectionMatrix(projectionMatrix);
m_Direct3D->GetOrthoMatrix(orthoMatrix);
+ // Get the light properties.
+ for (i = 0; i < m_numLights; i++)
+ {
+ // Create the diffuse color array from the four light colors.
+ diffuseColor[i] = m_Lights[i].GetDiffuseColor();
+
+ // Create the light position array from the four light positions.
+ lightPosition[i] = m_Lights[i].GetPosition();
+ }
+
+ scaleMatrix = XMMatrixScaling(0.5f, 0.5f, 0.5f); // Build the scaling matrix.
+ rotateMatrix = XMMatrixRotationY(rotation); // Build the rotation matrix.
+ translateMatrix = XMMatrixTranslation(x, y, z); // Build the translation matrix.
+
+ // Multiply the scale, rotation, and translation matrices together to create the final world transformation matrix.
+ srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
+ worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
+
+ // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
+ m_Model->Render(m_Direct3D->GetDeviceContext());
+
+ // Render the model using the light shader.
+ result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
+ diffuseColor, lightPosition);
+
+ for (auto cube : m_cubes)
+ {
+
+ scaleMatrix = cube->GetScaleMatrix();
+
+ if (cube->m_demoSpinning)
+ rotateMatrix = XMMatrixRotationY(rotation);
+ else
+ {
+ rotateMatrix = cube->GetRotateMatrix();
+ }
+
+
+ translateMatrix = cube->GetTranslateMatrix();
+ srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
+ worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
+
+ cube->Render(m_Direct3D->GetDeviceContext());
+
+ result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
+ diffuseColor, lightPosition);
+ if (!result)
+ {
+ return false;
+ }
+ }
+
+ for (auto object : m_object)
+ {
+ scaleMatrix = object->GetScaleMatrix();
+ if (object->m_demoSpinning)
+ rotateMatrix = XMMatrixRotationY(rotation);
+ else
+ {
+ rotateMatrix = object->GetRotateMatrix();
+ }
+ translateMatrix = object->GetTranslateMatrix();
+ srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
+ worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
+
+ object->Render(m_Direct3D->GetDeviceContext());
+
+ result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
+ diffuseColor, lightPosition);
+
+ if (!result)
+ {
+ return false;
+ }
+ }
+
+ // Render terrain
+ for (auto chunk : m_terrainChunk)
+ {
+
+ scaleMatrix = chunk->GetScaleMatrix();
+ rotateMatrix = chunk->GetRotateMatrix();
+ translateMatrix = chunk->GetTranslateMatrix();
+
+ srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
+ worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
+
+ chunk->Render(m_Direct3D->GetDeviceContext());
+
+ result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), chunk->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, chunk->GetTexture(1),
+ diffuseColor, lightPosition);
+ if (!result)
+ {
+ return false;
+ }
+ }
+
// Setup matrices - Top display plane.
worldMatrix = XMMatrixTranslation(0.0f, 1.5f, 0.0f);
@@ -751,16 +852,6 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
return false;
}
- // Get the light properties.
- for (i = 0; i < m_numLights; i++)
- {
- // Create the diffuse color array from the four light colors.
- diffuseColor[i] = m_Lights[i].GetDiffuseColor();
-
- // Create the light position array from the four light positions.
- lightPosition[i] = m_Lights[i].GetPosition();
- }
-
// Construct the frustum.
m_Frustum->ConstructFrustum(viewMatrix, projectionMatrix, SCREEN_DEPTH);
@@ -928,6 +1019,33 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
//srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
//worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
+ // Render the model using the multitexture shader.
+ m_Model->Render(m_Direct3D->GetDeviceContext());
+
+ scaleMatrix = XMMatrixScaling(2.0f, 2.0f, 2.0f); // Build the scaling matrix.
+ rotateMatrix = XMMatrixRotationY(-rotation); // Build the rotation matrix.
+ translateMatrix = XMMatrixTranslation(-x, -y, -z); // Build the translation matrix.
+
+ // Multiply the scale, rotation, and translation matrices together to create the final world transformation matrix.
+ srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
+ worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
+
+ // Get the light properties.
+ for (i = 0; i < m_numLights; i++)
+ {
+ // Create the diffuse color array from the four light colors.
+ diffuseColor[i] = m_Lights[i].GetDiffuseColor();
+
+ // Create the light position array from the four light positions.
+ lightPosition[i] = m_Lights[i].GetPosition();
+ }
+
+
+
+ // Render the model using the multitexture shader.
+ //result = m_MultiTextureShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
+ // m_Model->GetTexture(0), m_Model->GetTexture(1));
+
//// Render the model using the multitexture shader.
//m_Model->Render(m_Direct3D->GetDeviceContext());
@@ -1041,26 +1159,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
// return false;
//}
- ////Specular Mapping
- //result = m_SpecMapShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
- // m_Model->GetTexture(0), m_Model->GetTexture(1), m_Model->GetTexture(2), m_Light->GetDirection(), m_Light->GetDiffuseColor(),
- // m_Camera->GetPosition(), m_Light->GetSpecularColor(), m_Light->GetSpecularPower());
- //if (!result)
- //{
- // return false;
- //}
-
- //scaleMatrix = XMMatrixScaling(1.0f, 1.0f, 1.0f); // Build the scaling matrix.
- //rotateMatrix = XMMatrixRotationY(40); // Build the rotation matrix.
- //translateMatrix = XMMatrixTranslation(0, -2.0f, -10.0f); // Build the translation matrix.
-
- //// Multiply the scale, rotation, and translation matrices together to create the final world transformation matrix.
- //srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
- //worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
-
- //// Render the model using the multitexture shader.
- //m_Model->Render(m_Direct3D->GetDeviceContext());
-
+
// Enable the Z buffer and disable alpha blending now that 2D rendering is complete.
m_Direct3D->TurnZBufferOn();
m_Direct3D->DisableAlphaBlending();
@@ -1071,6 +1170,134 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
return true;
}
+D3DClass* ApplicationClass::GetDirect3D()
+{
+ return m_Direct3D;
+}
+
+int ApplicationClass::GetScreenWidth() const
+{
+ return GetSystemMetrics(SM_CXSCREEN);
+}
+
+int ApplicationClass::GetScreenHeight() const
+{
+ return GetSystemMetrics(SM_CYSCREEN);
+}
+
+void ApplicationClass::GenerateTerrain()
+{
+ char modelFilename[128];
+ char textureFilename[128];
+ char textureFilename2[128];
+ char textureFilename3[128];
+
+ XMMATRIX scaleMatrix;
+ int scaleX, scaleY, scaleZ;
+
+ scaleX = 10.0f;
+ scaleY = 1.0f;
+ scaleZ = 10.0f;
+
+ scaleMatrix = XMMatrixScaling(scaleX, scaleY, scaleZ);
+
+ // Set the file name of the model.
+ strcpy_s(modelFilename, "plane.txt");
+ strcpy_s(textureFilename, "stone01.tga");
+ strcpy_s(textureFilename2, "moss01.tga");
+ strcpy_s(textureFilename3, "alpha01.tga");
+
+ // for loop to generate terrain chunks for a 10x10 grid
+ for (int i = 0; i < 10; i++)
+ {
+ for (int j = 0; j < 10; j++)
+ {
+ Object* newTerrain = new Object();
+ newTerrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename, textureFilename2, textureFilename3);
+
+ newTerrain->SetScaleMatrix(scaleMatrix);
+
+ newTerrain->SetTranslateMatrix(XMMatrixTranslation(i / 2 * (scaleX * 2), -5.0f, j * (scaleZ * 2)));
+
+ m_terrainChunk.push_back(newTerrain);
+
+ }
+ }
+
+}
+
+void ApplicationClass::AddKobject(WCHAR* filepath)
+{
+ char modelFilename[128];
+ char textureFilename[128];
+ char textureFilename2[128];
+ char textureFilename3[128];
+
+ filesystem::path p(filepath);
+ string filename = p.stem().string();
+
+ size_t convertedChars = 0;
+ wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), filepath, _TRUNCATE);
+
+
+ // Set the name of the texture file that we will be loading.
+ strcpy_s(textureFilename, "stone01.tga");
+ strcpy_s(textureFilename2, "moss01.tga");
+ strcpy_s(textureFilename3, "alpha01.tga");
+
+ Object* newObject = new Object();
+ newObject->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename, textureFilename2, textureFilename3);
+
+ newObject->SetTranslateMatrix(XMMatrixTranslation(0.0f, 0.0f, 0.0f));
+ newObject->SetName(filename);
+
+ m_object.push_back(newObject);
+}
+
+void ApplicationClass::AddCube()
+{
+ char modelFilename[128];
+ char textureFilename[128];
+ char textureFilename2[128];
+ char textureFilename3[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");
+ strcpy_s(textureFilename2, "moss01.tga");
+ strcpy_s(textureFilename3, "alpha01.tga");
+ static int cubeCount = 0;
+ float position = cubeCount * 2.0f;
+ Object* newCube = new Object();
+ newCube->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename, textureFilename2, textureFilename3);
+
+ newCube->SetTranslateMatrix(XMMatrixTranslation(position, 0.0f, 0.0f));
+
+ m_cubes.push_back(newCube);
+}
+
+void ApplicationClass::DeleteKobject(int index)
+{
+ if (index < m_object.size())
+ {
+ m_object[index]->Shutdown();
+ delete m_object[index];
+ m_object.erase(m_object.begin() + index);
+ }
+}
+
+void ApplicationClass::DeleteTerrain()
+{
+ for (auto cube : m_terrainChunk)
+ {
+ cube->Shutdown();
+ delete cube;
+ }
+ m_terrainChunk.clear();
+}
+
bool ApplicationClass::UpdateMouseStrings(int mouseX, int mouseY, bool mouseDown)
{
char tempString[16], finalString[32];
diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h
index 71dbd8a..579dc37 100644
--- a/enginecustom/applicationclass.h
+++ b/enginecustom/applicationclass.h
@@ -7,9 +7,12 @@
///////////////////////
#include "d3dclass.h"
#include "cameraclass.h"
-#include "modelclass.h"
+#include "object.h"
#include "lightshaderclass.h"
#include "lightclass.h"
+#include
+#include
+
#include "lightmapshaderclass.h"
#include "bitmapclass.h"
#include "spriteclass.h"
@@ -26,6 +29,7 @@
#include "frustumclass.h"
#include "rendertextureclass.h"
#include "displayplaneclass.h"
+#include "reflectionshaderclass.h"
/////////////
@@ -46,11 +50,30 @@ public:
ApplicationClass();
ApplicationClass(const ApplicationClass&);
~ApplicationClass();
+ D3DClass* GetDirect3D();
bool Initialize(int, int, HWND);
void Shutdown();
bool Frame(InputClass*);
+ int GetScreenWidth() const;
+ int GetScreenHeight() const;
+
+ float GetSpeed() const { return speed; };
+ void SetSpeed(float speed) { this->speed = speed; };
+
+ void AddCube();
+ void DeleteKobject(int index);
+ int GetCubeCount() const { return m_cubes.size(); };
+ int GetTerrainCubeCount() const { return m_terrainChunk.size(); };
+ std::vector