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 0471393..c5ebe29 100644 --- a/enginecustom/Systemclass.cpp +++ b/enginecustom/Systemclass.cpp @@ -218,25 +218,33 @@ LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam } case WM_DROPFILES: { - if (!m_isResizing) - { - HDROP hDrop = reinterpret_cast(wparam); - UINT numFiles = DragQueryFile(hDrop, 0xFFFFFFFF, nullptr, 0); + HDROP hDrop = reinterpret_cast(wparam); + UINT numFiles = DragQueryFile(hDrop, 0xFFFFFFFF, nullptr, 0); - if (numFiles > 0 && m_Application != nullptr) { - // Handle dropped files here - for (UINT i = 0; i < numFiles; ++i) { - // Get the file name - WCHAR filePath[MAX_PATH]; - DragQueryFile(hDrop, i, filePath, MAX_PATH); + 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; + + DragFinish(hDrop); + return 0; } // Any other messages send to the default message handler as our application won't make use of them. default: diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index 7746c44..4d78082 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -622,7 +622,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; float frameTime; @@ -649,6 +649,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 @@ -669,7 +673,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); @@ -725,11 +729,8 @@ bool ApplicationClass::Frame(InputClass* Input) return false; } - // Check if the mouse has been pressed. - mouseDown = Input->IsMousePressed(); - // Update the mouse strings each frame. - result = UpdateMouseStrings(mouseX, mouseY, mouseDown); + result = UpdateMouseStrings(mouseX, mouseY, leftMouseDown); if (!result) { return false; @@ -1035,7 +1036,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z) // 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) { @@ -1082,7 +1083,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z) diffuseColor, lightPosition); if (!result) - { + { return false; } } @@ -1101,7 +1102,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z) chunk->Render(m_Direct3D->GetDeviceContext()); result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), - diffuseColor, lightPosition); + diffuseColor, lightPosition); if (!result) { return false; diff --git a/enginecustom/inputclass.cpp b/enginecustom/inputclass.cpp index 2a2c91f..e6944fd 100644 --- a/enginecustom/inputclass.cpp +++ b/enginecustom/inputclass.cpp @@ -350,7 +350,7 @@ void InputClass::GetMouseLocation(int& mouseX, int& mouseY) return; } -bool InputClass::IsMousePressed() +bool InputClass::IsLeftMousePressed() { // Check the left mouse button state. if (m_mouseState.rgbButtons[0] & 0x80) @@ -360,3 +360,14 @@ bool InputClass::IsMousePressed() return false; } + +bool InputClass::IsRightMousePressed() +{ + // Check the left mouse button state. + if (m_mouseState.rgbButtons[1] & 0x80) + { + return true; + } + + return false; +} diff --git a/enginecustom/inputclass.h b/enginecustom/inputclass.h index d559872..6aa5955 100644 --- a/enginecustom/inputclass.h +++ b/enginecustom/inputclass.h @@ -33,7 +33,8 @@ public: bool IsEscapePressed(); void GetMouseLocation(int&, int&); - bool IsMousePressed(); + bool IsLeftMousePressed(); + bool IsRightMousePressed(); void KeyDown(unsigned int); void KeyUp(unsigned int); bool IsLeftArrowPressed();