ajout deplacement camera avec la souris
This commit is contained in:
parent
bbb31b1161
commit
5817867594
@ -4,6 +4,7 @@ PositionClass::PositionClass()
|
|||||||
{
|
{
|
||||||
m_frameTime = 0.0f;
|
m_frameTime = 0.0f;
|
||||||
m_rotationY = 0.0f;
|
m_rotationY = 0.0f;
|
||||||
|
m_rotationX = 0.0f;
|
||||||
m_leftTurnSpeed = 0.0f;
|
m_leftTurnSpeed = 0.0f;
|
||||||
m_rightTurnSpeed = 0.0f;
|
m_rightTurnSpeed = 0.0f;
|
||||||
}
|
}
|
||||||
@ -24,9 +25,10 @@ void PositionClass::SetFrameTime(float time)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PositionClass::GetRotation(float& y)
|
void PositionClass::GetRotation(float& y, float& x)
|
||||||
{
|
{
|
||||||
y = m_rotationY;
|
y = m_rotationY;
|
||||||
|
x = m_rotationX;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,5 +94,38 @@ void PositionClass::TurnRight(bool keydown)
|
|||||||
m_rotationY -= 360.0f;
|
m_rotationY -= 360.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PositionClass::TurnMouse(float deltaX, float deltaY)
|
||||||
|
{
|
||||||
|
// The turning speed is proportional to the horizontal mouse movement
|
||||||
|
m_horizontalTurnSpeed = deltaX * 0.1f;
|
||||||
|
|
||||||
|
// 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 * 0.1f;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
@ -19,15 +19,16 @@ public:
|
|||||||
~PositionClass();
|
~PositionClass();
|
||||||
|
|
||||||
void SetFrameTime(float);
|
void SetFrameTime(float);
|
||||||
void GetRotation(float&);
|
void GetRotation(float&, float&);
|
||||||
|
|
||||||
void TurnLeft(bool);
|
void TurnLeft(bool);
|
||||||
void TurnRight(bool);
|
void TurnRight(bool);
|
||||||
|
void TurnMouse(float, float);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float m_frameTime;
|
float m_frameTime;
|
||||||
float m_rotationY;
|
float m_rotationY, m_rotationX;
|
||||||
float m_leftTurnSpeed, m_rightTurnSpeed;
|
float m_leftTurnSpeed, m_rightTurnSpeed, m_horizontalTurnSpeed, m_verticalTurnSpeed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -572,11 +572,14 @@ void ApplicationClass::Shutdown()
|
|||||||
|
|
||||||
bool ApplicationClass::Frame(InputClass* Input)
|
bool ApplicationClass::Frame(InputClass* Input)
|
||||||
{
|
{
|
||||||
int mouseX, mouseY;
|
int mouseX, mouseY, currentMouseX, currentMouseY;
|
||||||
bool result, mouseDown, keyDown;
|
bool result, mouseDown, keyDown;
|
||||||
float rotationY;
|
float rotationY, rotationX;
|
||||||
|
|
||||||
float frameTime;
|
float frameTime;
|
||||||
|
|
||||||
|
static int lastMouseX = 0, lastMouseY = 0;
|
||||||
|
|
||||||
static float rotation = 360.0f;
|
static float rotation = 360.0f;
|
||||||
static float x = 6.f;
|
static float x = 6.f;
|
||||||
static float y = 3.f;
|
static float y = 3.f;
|
||||||
@ -594,6 +597,19 @@ bool ApplicationClass::Frame(InputClass* Input)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the location of the mouse from the input object,
|
||||||
|
Input->GetMouseLocation(mouseX, mouseY);
|
||||||
|
|
||||||
|
currentMouseX = mouseX;
|
||||||
|
|
||||||
|
float 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
|
||||||
|
lastMouseY = currentMouseY; // Mettez à jour la dernière position de la souris pour la prochaine image
|
||||||
|
|
||||||
// Set the frame time for calculating the updated position.
|
// Set the frame time for calculating the updated position.
|
||||||
m_Position->SetFrameTime(m_Timer->GetTime());
|
m_Position->SetFrameTime(m_Timer->GetTime());
|
||||||
|
|
||||||
@ -604,11 +620,13 @@ bool ApplicationClass::Frame(InputClass* Input)
|
|||||||
keyDown = Input->IsRightArrowPressed();
|
keyDown = Input->IsRightArrowPressed();
|
||||||
m_Position->TurnRight(keyDown);
|
m_Position->TurnRight(keyDown);
|
||||||
|
|
||||||
|
m_Position->TurnMouse(deltaX, deltaY);
|
||||||
|
|
||||||
// Get the current view point rotation.
|
// Get the current view point rotation.
|
||||||
m_Position->GetRotation(rotationY);
|
m_Position->GetRotation(rotationY, rotationX);
|
||||||
|
|
||||||
// Set the rotation of the camera.
|
// Set the rotation of the camera.
|
||||||
m_Camera->SetRotation(0.0f, rotationY, 0.0f);
|
m_Camera->SetRotation(rotationX, rotationY, 0.0f);
|
||||||
m_Camera->Render();
|
m_Camera->Render();
|
||||||
|
|
||||||
// Render the graphics scene.
|
// Render the graphics scene.
|
||||||
@ -648,9 +666,6 @@ bool ApplicationClass::Frame(InputClass* Input)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the location of the mouse from the input object,
|
|
||||||
Input->GetMouseLocation(mouseX, mouseY);
|
|
||||||
|
|
||||||
// Check if the mouse has been pressed.
|
// Check if the mouse has been pressed.
|
||||||
mouseDown = Input->IsMousePressed();
|
mouseDown = Input->IsMousePressed();
|
||||||
|
|
||||||
@ -661,25 +676,6 @@ bool ApplicationClass::Frame(InputClass* Input)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//// Obtenez la position de la souris
|
|
||||||
//Input->GetMouseLocation(mouseX, mouseY);
|
|
||||||
|
|
||||||
//// Calculez la distance parcourue par la souris depuis le dernier frame
|
|
||||||
//float deltaX = mouseX - m_previousMouseX;
|
|
||||||
//float deltaY = mouseY - m_previousMouseY;
|
|
||||||
|
|
||||||
//// Mettez à jour les positions précédentes de la souris
|
|
||||||
//m_previousMouseX = mouseX;
|
|
||||||
//m_previousMouseY = mouseY;
|
|
||||||
|
|
||||||
//// Utilisez deltaX et deltaY pour ajuster la rotation de la caméra
|
|
||||||
//float rotationSpeed = 0.1f; // Ajustez cette valeur pour changer la vitesse de rotation
|
|
||||||
//float rotationX = m_Camera->GetRotation().x + deltaY * rotationSpeed;
|
|
||||||
//float rotationY = m_Camera->GetRotation().y + deltaX * rotationSpeed;
|
|
||||||
|
|
||||||
//// Mettez à jour la rotation de la caméra
|
|
||||||
//m_Camera->SetRotation(rotationX, rotationY, 0.0f);
|
|
||||||
|
|
||||||
// Update the sprite object using the frame time.
|
// Update the sprite object using the frame time.
|
||||||
m_Sprite->Update(frameTime);
|
m_Sprite->Update(frameTime);
|
||||||
|
|
||||||
|
@ -87,8 +87,6 @@ private:
|
|||||||
PositionClass* m_Position;
|
PositionClass* m_Position;
|
||||||
FrustumClass* m_Frustum;
|
FrustumClass* m_Frustum;
|
||||||
XMMATRIX m_baseViewMatrix;
|
XMMATRIX m_baseViewMatrix;
|
||||||
float m_previousMouseX;
|
|
||||||
float m_previousMouseY;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user