feat: rotation camera avec clic droit

This commit is contained in:
StratiX0 2024-04-08 14:34:24 +02:00
parent c5d2c0c42f
commit edc1cb63d7
5 changed files with 49 additions and 34 deletions

View File

@ -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;
}

View File

@ -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:

View File

@ -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;

View File

@ -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;
}

View File

@ -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();