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/applicationclass.cpp b/enginecustom/applicationclass.cpp index 989ca9a..9b42dde 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -618,7 +618,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; @@ -645,6 +645,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 @@ -665,7 +669,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); @@ -721,11 +725,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; @@ -1031,7 +1032,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) { @@ -1078,7 +1079,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z) diffuseColor, lightPosition); if (!result) - { + { return false; } } @@ -1097,7 +1098,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();