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:
parent
13729b62fc
commit
d0d655781e
@ -10,6 +10,7 @@ PositionClass::PositionClass()
|
|||||||
m_positionZ = 0.0f;
|
m_positionZ = 0.0f;
|
||||||
m_leftTurnSpeed = 0.0f;
|
m_leftTurnSpeed = 0.0f;
|
||||||
m_rightTurnSpeed = 0.0f;
|
m_rightTurnSpeed = 0.0f;
|
||||||
|
m_cameraSpeed = 4.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -144,13 +145,24 @@ void PositionClass::TurnMouse(float deltaX, float deltaY, bool rightMouseDown)
|
|||||||
return;
|
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 radiansY, radiansX, speed;
|
||||||
float speed;
|
|
||||||
|
|
||||||
// Set the speed of the camera.
|
// 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.
|
// Convert degrees to radians.
|
||||||
radiansY = m_rotationY * 0.0174532925f;
|
radiansY = m_rotationY * 0.0174532925f;
|
||||||
@ -158,6 +170,24 @@ void PositionClass::MoveCamera(bool forward, bool backward, bool left, bool righ
|
|||||||
|
|
||||||
// Update the position.
|
// 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 moving forward, the position moves in the direction of the camera and accordingly to its angle.
|
||||||
if (forward)
|
if (forward)
|
||||||
{
|
{
|
||||||
|
@ -25,13 +25,13 @@ public:
|
|||||||
void TurnLeft(bool);
|
void TurnLeft(bool);
|
||||||
void TurnRight(bool);
|
void TurnRight(bool);
|
||||||
void TurnMouse(float, float, 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:
|
private:
|
||||||
float m_frameTime;
|
float m_frameTime;
|
||||||
float m_rotationY, m_rotationX;
|
float m_rotationY, m_rotationX;
|
||||||
float m_positionX, m_positionY, m_positionZ;
|
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
|
#endif
|
@ -628,7 +628,7 @@ void ApplicationClass::Shutdown()
|
|||||||
bool ApplicationClass::Frame(InputClass* Input)
|
bool ApplicationClass::Frame(InputClass* Input)
|
||||||
{
|
{
|
||||||
int mouseX, mouseY, currentMouseX, currentMouseY;
|
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 rotationY, rotationX, positionX, positionY, positionZ;
|
||||||
|
|
||||||
float frameTime;
|
float frameTime;
|
||||||
@ -684,6 +684,9 @@ bool ApplicationClass::Frame(InputClass* Input)
|
|||||||
// Get the current view point rotation.
|
// Get the current view point rotation.
|
||||||
m_Position->GetRotation(rotationY, rotationX);
|
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.
|
// Check if the a(q), d, w(z), s, q(a), e have been pressed, if so move the camera accordingly.
|
||||||
buttonQ = Input->IsAPressed();
|
buttonQ = Input->IsAPressed();
|
||||||
buttonD = Input->IsDPressed();
|
buttonD = Input->IsDPressed();
|
||||||
@ -691,7 +694,7 @@ bool ApplicationClass::Frame(InputClass* Input)
|
|||||||
buttonS = Input->IsSPressed();
|
buttonS = Input->IsSPressed();
|
||||||
buttonA = Input->IsQPressed();
|
buttonA = Input->IsQPressed();
|
||||||
buttonE = Input->IsEPressed();
|
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);
|
m_Position->GetPosition(positionX, positionY, positionZ);
|
||||||
|
|
||||||
// Set the postion and rotation of the camera.
|
// Set the postion and rotation of the camera.
|
||||||
|
@ -3,7 +3,7 @@ Pos=60,60
|
|||||||
Size=400,400
|
Size=400,400
|
||||||
|
|
||||||
[Window][Khaotic Engine]
|
[Window][Khaotic Engine]
|
||||||
Pos=596,31
|
Pos=593,31
|
||||||
Size=694,210
|
Size=694,210
|
||||||
|
|
||||||
[Window][Objects]
|
[Window][Objects]
|
||||||
|
@ -392,3 +392,23 @@ bool InputClass::IsRightMousePressed()
|
|||||||
|
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
@ -39,6 +39,8 @@ public:
|
|||||||
void KeyUp(unsigned int);
|
void KeyUp(unsigned int);
|
||||||
bool IsLeftArrowPressed();
|
bool IsLeftArrowPressed();
|
||||||
bool IsRightArrowPressed();
|
bool IsRightArrowPressed();
|
||||||
|
bool IsScrollUp();
|
||||||
|
bool IsScrollDown();
|
||||||
bool IsUpArrowPressed();
|
bool IsUpArrowPressed();
|
||||||
bool IsDownArrowPressed();
|
bool IsDownArrowPressed();
|
||||||
bool IsAPressed();
|
bool IsAPressed();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user