From c9e8b5b9b84f299a7776e47fedfc6020caeb770f Mon Sep 17 00:00:00 2001 From: StratiX0 Date: Fri, 12 Apr 2024 15:29:58 +0200 Subject: [PATCH] Modification scroll, fonctions en const MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat: + vitesse scroll et scroll et clic droit indépendantes refactor: + ajout de const sur certaines fonctions --- enginecustom/Cameraclass.cpp | 4 ++-- enginecustom/Cameraclass.h | 4 ++-- enginecustom/Positionclass.cpp | 14 ++++++++------ enginecustom/Positionclass.h | 6 +++--- enginecustom/inputclass.cpp | 34 +++++++++++++++++----------------- enginecustom/inputclass.h | 34 +++++++++++++++++----------------- enginecustom/object.cpp | 16 ++++++++-------- enginecustom/object.h | 16 ++++++++-------- enginecustom/physics.cpp | 2 +- enginecustom/physics.h | 2 +- 10 files changed, 67 insertions(+), 65 deletions(-) diff --git a/enginecustom/Cameraclass.cpp b/enginecustom/Cameraclass.cpp index b76598a..1160ad6 100644 --- a/enginecustom/Cameraclass.cpp +++ b/enginecustom/Cameraclass.cpp @@ -105,7 +105,7 @@ void CameraClass::Render() return; } -XMMATRIX CameraClass::GetViewMatrix(XMMATRIX& viewMatrix) +XMMATRIX CameraClass::GetViewMatrix(XMMATRIX& viewMatrix) const { viewMatrix = m_viewMatrix; return viewMatrix; @@ -164,7 +164,7 @@ void CameraClass::RenderReflection(float height) return; } -void CameraClass::GetReflectionViewMatrix(XMMATRIX& reflectionViewMatrix) +void CameraClass::GetReflectionViewMatrix(XMMATRIX& reflectionViewMatrix) const { reflectionViewMatrix = m_reflectionViewMatrix; return; diff --git a/enginecustom/Cameraclass.h b/enginecustom/Cameraclass.h index fe41bdd..0f344e9 100644 --- a/enginecustom/Cameraclass.h +++ b/enginecustom/Cameraclass.h @@ -30,10 +30,10 @@ public: void Render(); - XMMATRIX GetViewMatrix(XMMATRIX& viewMatrix); + XMMATRIX GetViewMatrix(XMMATRIX& viewMatrix) const; void RenderReflection(float); - void GetReflectionViewMatrix(XMMATRIX&); + void GetReflectionViewMatrix(XMMATRIX&) const; private: float m_positionX, m_positionY, m_positionZ; diff --git a/enginecustom/Positionclass.cpp b/enginecustom/Positionclass.cpp index c3c1877..19008d8 100644 --- a/enginecustom/Positionclass.cpp +++ b/enginecustom/Positionclass.cpp @@ -11,6 +11,7 @@ PositionClass::PositionClass() m_leftTurnSpeed = 0.0f; m_rightTurnSpeed = 0.0f; m_cameraSpeed = 4.0f; + m_speed = m_cameraSpeed; } @@ -29,14 +30,14 @@ void PositionClass::SetFrameTime(float time) return; } -void PositionClass::GetRotation(float& y, float& x) +void PositionClass::GetRotation(float& y, float& x) const { y = m_rotationY; x = m_rotationX; return; } -void PositionClass::GetPosition(float& x, float& y, float& z) +void PositionClass::GetPosition(float& x, float& y, float& z) const { x = m_positionX; y = m_positionY; @@ -172,22 +173,23 @@ void PositionClass::MoveCamera(bool forward, bool backward, bool left, bool righ if (scrollUp && !rightClick) { - speed = m_cameraSpeed * 20 * m_frameTime; + speed = m_speed * 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; + speed = m_speed * 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 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 0d73ca3..cf1b0dc 100644 --- a/enginecustom/Positionclass.h +++ b/enginecustom/Positionclass.h @@ -19,8 +19,8 @@ public: ~PositionClass(); void SetFrameTime(float); - void GetRotation(float&, float&); - void GetPosition(float&, float&, float&); + void GetRotation(float&, float&) const; + void GetPosition(float&, float&, float&) const; void TurnLeft(bool); void TurnRight(bool); @@ -31,7 +31,7 @@ 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, m_cameraSpeed; + float m_leftTurnSpeed, m_rightTurnSpeed, m_horizontalTurnSpeed, m_verticalTurnSpeed, m_cameraSpeed, m_speed; }; #endif \ No newline at end of file diff --git a/enginecustom/inputclass.cpp b/enginecustom/inputclass.cpp index 599bcac..98e36fc 100644 --- a/enginecustom/inputclass.cpp +++ b/enginecustom/inputclass.cpp @@ -123,7 +123,7 @@ void InputClass::KeyUp(unsigned int input) } -bool InputClass::IsKeyDown(unsigned int key) +bool InputClass::IsKeyDown(unsigned int key) const { // Return what state the key is in (pressed/not pressed). return m_keys[key]; @@ -244,7 +244,7 @@ void InputClass::ProcessInput() return; } -bool InputClass::IsEscapePressed() +bool InputClass::IsEscapePressed() const { // Do a bitwise and on the keyboard state to check if the escape key is currently being pressed. if (m_keyboardState[DIK_ESCAPE] & 0x80) @@ -255,7 +255,7 @@ bool InputClass::IsEscapePressed() return false; } -bool InputClass::IsLeftArrowPressed() +bool InputClass::IsLeftArrowPressed() const { if (m_keyboardState[DIK_LEFT] & 0x80) { @@ -266,7 +266,7 @@ bool InputClass::IsLeftArrowPressed() } -bool InputClass::IsRightArrowPressed() +bool InputClass::IsRightArrowPressed() const { if (m_keyboardState[DIK_RIGHT] & 0x80) { @@ -276,7 +276,7 @@ bool InputClass::IsRightArrowPressed() return false; } -bool InputClass::IsUpArrowPressed() +bool InputClass::IsUpArrowPressed() const { if (m_keyboardState[DIK_UP] & 0x80) { @@ -287,7 +287,7 @@ bool InputClass::IsUpArrowPressed() } -bool InputClass::IsDownArrowPressed() +bool InputClass::IsDownArrowPressed() const { if (m_keyboardState[DIK_DOWN] & 0x80) { @@ -301,7 +301,7 @@ bool InputClass::IsDownArrowPressed() // Les touches correspondent aux claviers QWERTY // /////////////////////////////////////////////////// -bool InputClass::IsAPressed() +bool InputClass::IsAPressed() const { // Touche A sur QWERTY, Q sur AZERTY if (m_keyboardState[DIK_A] & 0x80) @@ -312,7 +312,7 @@ bool InputClass::IsAPressed() return false; } -bool InputClass::IsDPressed() +bool InputClass::IsDPressed() const { if (m_keyboardState[DIK_D] & 0x80) { @@ -322,7 +322,7 @@ bool InputClass::IsDPressed() return false; } -bool InputClass::IsWPressed() +bool InputClass::IsWPressed() const { // Touche W sur QWERTY, Z sur AZERTY if (m_keyboardState[DIK_W] & 0x80) @@ -333,7 +333,7 @@ bool InputClass::IsWPressed() return false; } -bool InputClass::IsSPressed() +bool InputClass::IsSPressed() const { if (m_keyboardState[DIK_S] & 0x80) { @@ -343,7 +343,7 @@ bool InputClass::IsSPressed() return false; } -bool InputClass::IsQPressed() +bool InputClass::IsQPressed() const { // Touche Q sur QWERTY, A sur AZERTY if (m_keyboardState[DIK_Q] & 0x80) @@ -354,7 +354,7 @@ bool InputClass::IsQPressed() return false; } -bool InputClass::IsEPressed() +bool InputClass::IsEPressed() const { if (m_keyboardState[DIK_E] & 0x80) { @@ -364,14 +364,14 @@ bool InputClass::IsEPressed() return false; } -void InputClass::GetMouseLocation(int& mouseX, int& mouseY) +void InputClass::GetMouseLocation(int& mouseX, int& mouseY) const { mouseX = m_mouseX; mouseY = m_mouseY; return; } -bool InputClass::IsLeftMousePressed() +bool InputClass::IsLeftMousePressed() const { // Check the left mouse button state. if (m_mouseState.rgbButtons[0] & 0x80) @@ -382,7 +382,7 @@ bool InputClass::IsLeftMousePressed() return false; } -bool InputClass::IsRightMousePressed() +bool InputClass::IsRightMousePressed() const { // Check the left mouse button state. if (m_mouseState.rgbButtons[1] & 0x80) @@ -393,7 +393,7 @@ bool InputClass::IsRightMousePressed() return false; } -bool InputClass::IsScrollUp() +bool InputClass::IsScrollUp() const { if (m_mouseState.lZ > 0) { @@ -403,7 +403,7 @@ bool InputClass::IsScrollUp() return false; } -bool InputClass::IsScrollDown() +bool InputClass::IsScrollDown() const { if (m_mouseState.lZ < 0) { diff --git a/enginecustom/inputclass.h b/enginecustom/inputclass.h index e3581bd..444e51a 100644 --- a/enginecustom/inputclass.h +++ b/enginecustom/inputclass.h @@ -31,26 +31,26 @@ public: void Shutdown(); bool Frame(); - bool IsEscapePressed(); - void GetMouseLocation(int&, int&); - bool IsLeftMousePressed(); - bool IsRightMousePressed(); + bool IsEscapePressed() const; + void GetMouseLocation(int&, int&) const; + bool IsLeftMousePressed() const; + bool IsRightMousePressed() const; void KeyDown(unsigned int); void KeyUp(unsigned int); - bool IsLeftArrowPressed(); - bool IsRightArrowPressed(); - bool IsScrollUp(); - bool IsScrollDown(); - bool IsUpArrowPressed(); - bool IsDownArrowPressed(); - bool IsAPressed(); - bool IsDPressed(); - bool IsWPressed(); - bool IsSPressed(); - bool IsQPressed(); - bool IsEPressed(); + bool IsLeftArrowPressed() const; + bool IsRightArrowPressed() const; + bool IsScrollUp() const; + bool IsScrollDown() const; + bool IsUpArrowPressed() const; + bool IsDownArrowPressed() const; + bool IsAPressed() const; + bool IsDPressed() const; + bool IsWPressed() const; + bool IsSPressed() const; + bool IsQPressed() const; + bool IsEPressed()const; - bool IsKeyDown(unsigned int); + bool IsKeyDown(unsigned int) const; private: bool m_keys[256]; diff --git a/enginecustom/object.cpp b/enginecustom/object.cpp index 1ae2f60..2c37036 100644 --- a/enginecustom/object.cpp +++ b/enginecustom/object.cpp @@ -42,27 +42,27 @@ void Object::SetWorldMatrix(XMMATRIX worldMatrix) m_worldMatrix = worldMatrix; } -XMMATRIX Object::GetScaleMatrix() +XMMATRIX Object::GetScaleMatrix() const { return m_scaleMatrix; } -XMMATRIX Object::GetRotateMatrix() +XMMATRIX Object::GetRotateMatrix() const { return m_rotateMatrix; } -XMMATRIX Object::GetTranslateMatrix() +XMMATRIX Object::GetTranslateMatrix() const { return m_translateMatrix; } -XMMATRIX Object::GetSRMatrix() +XMMATRIX Object::GetSRMatrix() const { return m_srMatrix; } -XMMATRIX Object::GetWorldMatrix() +XMMATRIX Object::GetWorldMatrix() const { return m_worldMatrix; } @@ -172,7 +172,7 @@ void Object::SetVelocity(XMVECTOR velocity) m_velocity = velocity; } -XMVECTOR Object::GetVelocity() +XMVECTOR Object::GetVelocity() const { return m_velocity; } @@ -182,7 +182,7 @@ void Object::SetAcceleration(XMVECTOR acceleration) m_acceleration = acceleration; } -XMVECTOR Object::GetAcceleration() +XMVECTOR Object::GetAcceleration() const { return m_acceleration; } @@ -192,7 +192,7 @@ void Object::SetMass(float mass) m_mass = mass; } -float Object::GetMass() +float Object::GetMass() const { return m_mass; } \ No newline at end of file diff --git a/enginecustom/object.h b/enginecustom/object.h index bb98a8b..5eb6407 100644 --- a/enginecustom/object.h +++ b/enginecustom/object.h @@ -17,22 +17,22 @@ public: void SetRotation(XMVECTOR rotation); void SetScale(XMVECTOR scale); - XMMATRIX GetScaleMatrix(); - XMMATRIX GetRotateMatrix(); - XMMATRIX GetTranslateMatrix(); - XMMATRIX GetSRMatrix(); - XMMATRIX GetWorldMatrix(); + XMMATRIX GetScaleMatrix() const; + XMMATRIX GetRotateMatrix() const; + XMMATRIX GetTranslateMatrix() const; + XMMATRIX GetSRMatrix() const; + XMMATRIX GetWorldMatrix() const; XMVECTOR GetPosition(); XMVECTOR GetRotation(); XMVECTOR GetScale(); void SetVelocity(XMVECTOR); - XMVECTOR GetVelocity(); + XMVECTOR GetVelocity() const; void SetAcceleration(XMVECTOR); - XMVECTOR GetAcceleration(); + XMVECTOR GetAcceleration() const; void SetMass(float); - float GetMass(); + float GetMass() const; void UpdateWorldMatrix(); void UpdateSRMatrix(); diff --git a/enginecustom/physics.cpp b/enginecustom/physics.cpp index a7f6648..a73aad2 100644 --- a/enginecustom/physics.cpp +++ b/enginecustom/physics.cpp @@ -15,7 +15,7 @@ Physics::~Physics() } // Get the gravity value -XMVECTOR Physics::GetGravity() +XMVECTOR Physics::GetGravity() const { return m_gravity; } diff --git a/enginecustom/physics.h b/enginecustom/physics.h index 58445c3..5307551 100644 --- a/enginecustom/physics.h +++ b/enginecustom/physics.h @@ -10,7 +10,7 @@ public: explicit Physics(const Physics&); // Use explicit to avoid implicit conversion ~Physics(); - XMVECTOR GetGravity(); // Get the gravity value + XMVECTOR GetGravity() const; // Get the gravity value void SetGravity(XMVECTOR gravity); // Define the gravity value void ApplyGravity(Object*, float); // Apply gravity to an object void ApplyDrag(Object*, float, float);