diff --git a/enginecustom/Positionclass.cpp b/enginecustom/Positionclass.cpp index cf05768..c3c1877 100644 --- a/enginecustom/Positionclass.cpp +++ b/enginecustom/Positionclass.cpp @@ -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) { diff --git a/enginecustom/Positionclass.h b/enginecustom/Positionclass.h index 7123aca..0d73ca3 100644 --- a/enginecustom/Positionclass.h +++ b/enginecustom/Positionclass.h @@ -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 \ No newline at end of file diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index d9b699c..35ef870 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -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. diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index 771a0fe..d7295bb 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -3,7 +3,7 @@ Pos=60,60 Size=400,400 [Window][Khaotic Engine] -Pos=596,31 +Pos=593,31 Size=694,210 [Window][Objects] diff --git a/enginecustom/inputclass.cpp b/enginecustom/inputclass.cpp index 27840ea..599bcac 100644 --- a/enginecustom/inputclass.cpp +++ b/enginecustom/inputclass.cpp @@ -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; +} diff --git a/enginecustom/inputclass.h b/enginecustom/inputclass.h index 4354212..e3581bd 100644 --- a/enginecustom/inputclass.h +++ b/enginecustom/inputclass.h @@ -39,6 +39,8 @@ public: void KeyUp(unsigned int); bool IsLeftArrowPressed(); bool IsRightArrowPressed(); + bool IsScrollUp(); + bool IsScrollDown(); bool IsUpArrowPressed(); bool IsDownArrowPressed(); bool IsAPressed();