From ca82f3712746a5a3908eb5e0a734f97d4414f4db Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Tue, 9 Apr 2024 13:02:33 +0200 Subject: [PATCH] Minor Update - Fix Warning + Add texture in the object inspector Feat : + Show the texture of the object in the Object Window Fix : - No warning for now... --- enginecustom/Positionclass.cpp | 2 +- enginecustom/Positionclass.h | 2 +- enginecustom/Systemclass.cpp | 137 +++++++++++++++--------------- enginecustom/applicationclass.cpp | 14 ++- enginecustom/applicationclass.h | 6 +- enginecustom/imgui.ini | 2 +- enginecustom/imguiManager.cpp | 16 ++++ enginecustom/textureclass.cpp | 1 - 8 files changed, 102 insertions(+), 78 deletions(-) diff --git a/enginecustom/Positionclass.cpp b/enginecustom/Positionclass.cpp index cf05768..ec0e796 100644 --- a/enginecustom/Positionclass.cpp +++ b/enginecustom/Positionclass.cpp @@ -108,7 +108,7 @@ void PositionClass::TurnRight(bool keydown) return; } -void PositionClass::TurnMouse(float deltaX, float deltaY, bool rightMouseDown) +void PositionClass::TurnMouse(int deltaX, int deltaY, bool rightMouseDown) { float speed = 0.1f; // The turning speed is proportional to the horizontal mouse movement diff --git a/enginecustom/Positionclass.h b/enginecustom/Positionclass.h index 7123aca..643045c 100644 --- a/enginecustom/Positionclass.h +++ b/enginecustom/Positionclass.h @@ -24,7 +24,7 @@ public: void TurnLeft(bool); void TurnRight(bool); - void TurnMouse(float, float, bool); + void TurnMouse(int, int, bool); void MoveCamera(bool, bool, bool, bool, bool, bool); private: diff --git a/enginecustom/Systemclass.cpp b/enginecustom/Systemclass.cpp index 4c42b81..7abe5e4 100644 --- a/enginecustom/Systemclass.cpp +++ b/enginecustom/Systemclass.cpp @@ -176,82 +176,85 @@ LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam 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()) + case WM_KEYDOWN: { - m_Application->GetDirect3D()->ResizeSwapChain(newWidth, newHeight); + // 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; } - else + + // Check if a key has been released on the keyboard. + case WM_KEYUP: { - m_initialWindowWidth = newWidth; - m_initialWindowHeight = newHeight; + // 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_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); + case WM_SIZE: + { + int newWidth = LOWORD(lparam); + int newHeight = HIWORD(lparam); - 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; - } + // 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); + } - 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); - } } + + return 0; } void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight) diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index f2a838c..795935f 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -43,7 +43,6 @@ ApplicationClass::~ApplicationClass() bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) { char mouseString1[32], mouseString2[32], mouseString3[32]; - char testString1[32], testString2[32], testString3[32]; char modelFilename[128], textureFilename1[128], textureFilename2[128], textureFilename3[128], renderString[32]; char bitmapFilename[128]; char spriteFilename[128]; @@ -598,12 +597,12 @@ bool ApplicationClass::Frame(InputClass* Input) currentMouseX = mouseX; - float deltaX = currentMouseX - lastMouseX; // Calculez le d�placement de la souris + int deltaX = currentMouseX - lastMouseX; // Calculez le d�placement de la souris lastMouseX = currentMouseX; // Mettez � jour la derni�re position de la souris pour la prochaine image currentMouseY = mouseY; - float deltaY = currentMouseY - lastMouseY; // Calculez le d�placement de la souris + int deltaY = currentMouseY - lastMouseY; // Calculez le d�placement de la souris lastMouseY = currentMouseY; // Mettez � jour la derni�re position de la souris pour la prochaine image // Set the frame time for calculating the updated position. @@ -1080,7 +1079,7 @@ void ApplicationClass::GenerateTerrain() char textureFilename3[128]; XMMATRIX scaleMatrix; - int scaleX, scaleY, scaleZ; + float scaleX, scaleY, scaleZ; scaleX = 10.0f; scaleY = 1.0f; @@ -1231,6 +1230,13 @@ bool ApplicationClass::UpdateMouseStrings(int mouseX, int mouseY, bool mouseDown // Update the sentence vertex buffer with the new string information. result = m_MouseStrings[2].UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 100, 1.0f, 1.0f, 1.0f); + + if (!result) + { + return false; + } + + return true; } bool ApplicationClass::UpdateFps() diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index e338546..8c5c32c 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -68,8 +68,8 @@ public: void AddCube(); void DeleteKobject(int index); - int GetCubeCount() const { return m_cubes.size(); }; - int GetTerrainCubeCount() const { return m_terrainChunk.size(); }; + size_t GetCubeCount() const { return m_cubes.size(); }; + size_t GetTerrainCubeCount() const { return m_terrainChunk.size(); }; std::vector GetCubes() const { return m_cubes; }; std::vector GetTerrainCubes() const { return m_terrainChunk; }; std::vector GetKobjects() const { return m_object; }; @@ -113,7 +113,7 @@ private : XMMATRIX m_baseViewMatrix; RenderTextureClass* m_RenderTexture; DisplayPlaneClass* m_DisplayPlane; - float m_screenWidth, m_screenHeight; + int m_screenWidth, m_screenHeight; CameraClass* m_Camera; PositionClass* m_Position; FrustumClass* m_Frustum; diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index 5691449..9d3f9bb 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -7,7 +7,7 @@ Pos=260,25 Size=694,210 [Window][Objects] -Pos=1348,34 +Pos=994,39 Size=492,353 [Window][Terrain] diff --git a/enginecustom/imguiManager.cpp b/enginecustom/imguiManager.cpp index 1991569..4e795f7 100644 --- a/enginecustom/imguiManager.cpp +++ b/enginecustom/imguiManager.cpp @@ -106,6 +106,7 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app) { ImGui::Begin("Objects", &showObjectWindow); int index = 0; + int count = 0; for (auto& object : app->GetKobjects()) { std::string headerName = object->GetName() + " " + std::to_string(index); @@ -139,6 +140,21 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app) ImGui::Separator(); + // Texture + std::string textureLabel = "Texture##" + std::to_string(index); + ID3D11ShaderResourceView* texture = object->GetTexture(0); + if (texture != nullptr) + { + if (ImGui::ImageButton((ImTextureID)texture, ImVec2(64, 64))) + { + count++; + + } + } + ImGui::Text("Texture count: %d", count); + + ImGui::Separator(); + // Delete button std::string deleteLabel = "Delete##" + std::to_string(index); if (ImGui::Button(deleteLabel.c_str())) diff --git a/enginecustom/textureclass.cpp b/enginecustom/textureclass.cpp index e863139..9d70166 100644 --- a/enginecustom/textureclass.cpp +++ b/enginecustom/textureclass.cpp @@ -20,7 +20,6 @@ TextureClass::~TextureClass() bool TextureClass::Initialize(ID3D11Device * device, ID3D11DeviceContext * deviceContext, char* filename) { bool result; - int height, width; D3D11_TEXTURE2D_DESC textureDesc; HRESULT hResult; unsigned int rowPitch;