Ajout : scroll sur la camera

feat:

+ scroll fait bouger la camera en avant ou en arriere
+ scroll et clic droit, augmente ou diminue la vitesse de la camera
This commit is contained in:
StratiX0 2024-04-12 15:07:30 +02:00
parent 13729b62fc
commit d0d655781e
6 changed files with 64 additions and 9 deletions

View File

@ -10,6 +10,7 @@ PositionClass::PositionClass()
m_positionZ = 0.0f;
m_leftTurnSpeed = 0.0f;
m_rightTurnSpeed = 0.0f;
m_cameraSpeed = 4.0f;
}
@ -144,13 +145,24 @@ void PositionClass::TurnMouse(float deltaX, float deltaY, bool rightMouseDown)
return;
}
void PositionClass::MoveCamera(bool forward, bool backward, bool left, bool right, bool up, bool down)
void PositionClass::MoveCamera(bool forward, bool backward, bool left, bool right, bool up, bool down, bool scrollUp, bool scrollDown, bool rightClick)
{
float radiansY, radiansX;
float speed;
float radiansY, radiansX, speed;
// Set the speed of the camera.
speed = 2.0f * m_frameTime;
if (scrollUp && rightClick)
{
m_cameraSpeed *= 1.1f;
}
if (scrollDown && rightClick)
{
m_cameraSpeed *= 0.9f;
if (m_cameraSpeed < 0.25f)
{
m_cameraSpeed = 0.25f;
}
}
// Convert degrees to radians.
radiansY = m_rotationY * 0.0174532925f;
@ -158,6 +170,24 @@ void PositionClass::MoveCamera(bool forward, bool backward, bool left, bool righ
// Update the position.
if (scrollUp && !rightClick)
{
speed = m_cameraSpeed * 20 * m_frameTime;
m_positionX += sinf(radiansY) * cosf(radiansX) * speed;
m_positionZ += cosf(radiansY) * cosf(radiansX) * speed;
m_positionY -= sinf(radiansX) * speed;
}
speed = m_cameraSpeed * m_frameTime;
if (scrollDown && !rightClick)
{
speed = m_cameraSpeed * 20 * m_frameTime;
m_positionX -= sinf(radiansY) * cosf(radiansX) * speed;
m_positionZ -= cosf(radiansY) * cosf(radiansX) * speed;
m_positionY += sinf(radiansX) * speed;
}
// If moving forward, the position moves in the direction of the camera and accordingly to its angle.
if (forward)
{

View File

@ -25,13 +25,13 @@ public:
void TurnLeft(bool);
void TurnRight(bool);
void TurnMouse(float, float, bool);
void MoveCamera(bool, bool, bool, bool, bool, bool);
void MoveCamera(bool, bool, bool, bool, bool, bool, bool, bool, bool);
private:
float m_frameTime;
float m_rotationY, m_rotationX;
float m_positionX, m_positionY, m_positionZ;
float m_leftTurnSpeed, m_rightTurnSpeed, m_horizontalTurnSpeed, m_verticalTurnSpeed;
float m_leftTurnSpeed, m_rightTurnSpeed, m_horizontalTurnSpeed, m_verticalTurnSpeed, m_cameraSpeed;
};
#endif

View File

@ -628,7 +628,7 @@ void ApplicationClass::Shutdown()
bool ApplicationClass::Frame(InputClass* Input)
{
int mouseX, mouseY, currentMouseX, currentMouseY;
bool result, leftMouseDown, rightMouseDown, keyLeft, keyRight, keyUp, keyDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE;
bool result, leftMouseDown, rightMouseDown, keyLeft, keyRight, keyUp, keyDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE, scrollUp, scrollDown;
float rotationY, rotationX, positionX, positionY, positionZ;
float frameTime;
@ -684,6 +684,9 @@ bool ApplicationClass::Frame(InputClass* Input)
// Get the current view point rotation.
m_Position->GetRotation(rotationY, rotationX);
scrollUp = Input->IsScrollUp();
scrollDown = Input->IsScrollDown();
// Check if the a(q), d, w(z), s, q(a), e have been pressed, if so move the camera accordingly.
buttonQ = Input->IsAPressed();
buttonD = Input->IsDPressed();
@ -691,7 +694,7 @@ bool ApplicationClass::Frame(InputClass* Input)
buttonS = Input->IsSPressed();
buttonA = Input->IsQPressed();
buttonE = Input->IsEPressed();
m_Position->MoveCamera(buttonZ, buttonS, buttonQ, buttonD, buttonE, buttonA);
m_Position->MoveCamera(buttonZ, buttonS, buttonQ, buttonD, buttonE, buttonA, scrollUp, scrollDown, rightMouseDown);
m_Position->GetPosition(positionX, positionY, positionZ);
// Set the postion and rotation of the camera.

View File

@ -3,7 +3,7 @@ Pos=60,60
Size=400,400
[Window][Khaotic Engine]
Pos=596,31
Pos=593,31
Size=694,210
[Window][Objects]

View File

@ -392,3 +392,23 @@ bool InputClass::IsRightMousePressed()
return false;
}
bool InputClass::IsScrollUp()
{
if (m_mouseState.lZ > 0)
{
return true;
}
return false;
}
bool InputClass::IsScrollDown()
{
if (m_mouseState.lZ < 0)
{
return true;
}
return false;
}

View File

@ -39,6 +39,8 @@ public:
void KeyUp(unsigned int);
bool IsLeftArrowPressed();
bool IsRightArrowPressed();
bool IsScrollUp();
bool IsScrollDown();
bool IsUpArrowPressed();
bool IsDownArrowPressed();
bool IsAPressed();