Modification scroll, fonctions en const

feat:
+ vitesse scroll et scroll et clic droit indépendantes

refactor:

+ ajout de const sur certaines fonctions
This commit is contained in:
StratiX0 2024-04-12 15:29:58 +02:00
parent d0d655781e
commit c9e8b5b9b8
10 changed files with 67 additions and 65 deletions

View File

@ -105,7 +105,7 @@ void CameraClass::Render()
return; return;
} }
XMMATRIX CameraClass::GetViewMatrix(XMMATRIX& viewMatrix) XMMATRIX CameraClass::GetViewMatrix(XMMATRIX& viewMatrix) const
{ {
viewMatrix = m_viewMatrix; viewMatrix = m_viewMatrix;
return viewMatrix; return viewMatrix;
@ -164,7 +164,7 @@ void CameraClass::RenderReflection(float height)
return; return;
} }
void CameraClass::GetReflectionViewMatrix(XMMATRIX& reflectionViewMatrix) void CameraClass::GetReflectionViewMatrix(XMMATRIX& reflectionViewMatrix) const
{ {
reflectionViewMatrix = m_reflectionViewMatrix; reflectionViewMatrix = m_reflectionViewMatrix;
return; return;

View File

@ -30,10 +30,10 @@ public:
void Render(); void Render();
XMMATRIX GetViewMatrix(XMMATRIX& viewMatrix); XMMATRIX GetViewMatrix(XMMATRIX& viewMatrix) const;
void RenderReflection(float); void RenderReflection(float);
void GetReflectionViewMatrix(XMMATRIX&); void GetReflectionViewMatrix(XMMATRIX&) const;
private: private:
float m_positionX, m_positionY, m_positionZ; float m_positionX, m_positionY, m_positionZ;

View File

@ -11,6 +11,7 @@ PositionClass::PositionClass()
m_leftTurnSpeed = 0.0f; m_leftTurnSpeed = 0.0f;
m_rightTurnSpeed = 0.0f; m_rightTurnSpeed = 0.0f;
m_cameraSpeed = 4.0f; m_cameraSpeed = 4.0f;
m_speed = m_cameraSpeed;
} }
@ -29,14 +30,14 @@ void PositionClass::SetFrameTime(float time)
return; return;
} }
void PositionClass::GetRotation(float& y, float& x) void PositionClass::GetRotation(float& y, float& x) const
{ {
y = m_rotationY; y = m_rotationY;
x = m_rotationX; x = m_rotationX;
return; return;
} }
void PositionClass::GetPosition(float& x, float& y, float& z) void PositionClass::GetPosition(float& x, float& y, float& z) const
{ {
x = m_positionX; x = m_positionX;
y = m_positionY; y = m_positionY;
@ -172,22 +173,23 @@ void PositionClass::MoveCamera(bool forward, bool backward, bool left, bool righ
if (scrollUp && !rightClick) if (scrollUp && !rightClick)
{ {
speed = m_cameraSpeed * 20 * m_frameTime; speed = m_speed * 20 * m_frameTime;
m_positionX += sinf(radiansY) * cosf(radiansX) * speed; m_positionX += sinf(radiansY) * cosf(radiansX) * speed;
m_positionZ += cosf(radiansY) * cosf(radiansX) * speed; m_positionZ += cosf(radiansY) * cosf(radiansX) * speed;
m_positionY -= sinf(radiansX) * speed; m_positionY -= sinf(radiansX) * speed;
} }
speed = m_cameraSpeed * m_frameTime;
if (scrollDown && !rightClick) if (scrollDown && !rightClick)
{ {
speed = m_cameraSpeed * 20 * m_frameTime; speed = m_speed * 20 * m_frameTime;
m_positionX -= sinf(radiansY) * cosf(radiansX) * speed; m_positionX -= sinf(radiansY) * cosf(radiansX) * speed;
m_positionZ -= cosf(radiansY) * cosf(radiansX) * speed; m_positionZ -= cosf(radiansY) * cosf(radiansX) * speed;
m_positionY += sinf(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 moving forward, the position moves in the direction of the camera and accordingly to its angle.
if (forward) if (forward)
{ {

View File

@ -19,8 +19,8 @@ public:
~PositionClass(); ~PositionClass();
void SetFrameTime(float); void SetFrameTime(float);
void GetRotation(float&, float&); void GetRotation(float&, float&) const;
void GetPosition(float&, float&, float&); void GetPosition(float&, float&, float&) const;
void TurnLeft(bool); void TurnLeft(bool);
void TurnRight(bool); void TurnRight(bool);
@ -31,7 +31,7 @@ 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, m_cameraSpeed; float m_leftTurnSpeed, m_rightTurnSpeed, m_horizontalTurnSpeed, m_verticalTurnSpeed, m_cameraSpeed, m_speed;
}; };
#endif #endif

View File

@ -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 what state the key is in (pressed/not pressed).
return m_keys[key]; return m_keys[key];
@ -244,7 +244,7 @@ void InputClass::ProcessInput()
return; 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. // Do a bitwise and on the keyboard state to check if the escape key is currently being pressed.
if (m_keyboardState[DIK_ESCAPE] & 0x80) if (m_keyboardState[DIK_ESCAPE] & 0x80)
@ -255,7 +255,7 @@ bool InputClass::IsEscapePressed()
return false; return false;
} }
bool InputClass::IsLeftArrowPressed() bool InputClass::IsLeftArrowPressed() const
{ {
if (m_keyboardState[DIK_LEFT] & 0x80) 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) if (m_keyboardState[DIK_RIGHT] & 0x80)
{ {
@ -276,7 +276,7 @@ bool InputClass::IsRightArrowPressed()
return false; return false;
} }
bool InputClass::IsUpArrowPressed() bool InputClass::IsUpArrowPressed() const
{ {
if (m_keyboardState[DIK_UP] & 0x80) 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) if (m_keyboardState[DIK_DOWN] & 0x80)
{ {
@ -301,7 +301,7 @@ bool InputClass::IsDownArrowPressed()
// Les touches correspondent aux claviers QWERTY // // Les touches correspondent aux claviers QWERTY //
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
bool InputClass::IsAPressed() bool InputClass::IsAPressed() const
{ {
// Touche A sur QWERTY, Q sur AZERTY // Touche A sur QWERTY, Q sur AZERTY
if (m_keyboardState[DIK_A] & 0x80) if (m_keyboardState[DIK_A] & 0x80)
@ -312,7 +312,7 @@ bool InputClass::IsAPressed()
return false; return false;
} }
bool InputClass::IsDPressed() bool InputClass::IsDPressed() const
{ {
if (m_keyboardState[DIK_D] & 0x80) if (m_keyboardState[DIK_D] & 0x80)
{ {
@ -322,7 +322,7 @@ bool InputClass::IsDPressed()
return false; return false;
} }
bool InputClass::IsWPressed() bool InputClass::IsWPressed() const
{ {
// Touche W sur QWERTY, Z sur AZERTY // Touche W sur QWERTY, Z sur AZERTY
if (m_keyboardState[DIK_W] & 0x80) if (m_keyboardState[DIK_W] & 0x80)
@ -333,7 +333,7 @@ bool InputClass::IsWPressed()
return false; return false;
} }
bool InputClass::IsSPressed() bool InputClass::IsSPressed() const
{ {
if (m_keyboardState[DIK_S] & 0x80) if (m_keyboardState[DIK_S] & 0x80)
{ {
@ -343,7 +343,7 @@ bool InputClass::IsSPressed()
return false; return false;
} }
bool InputClass::IsQPressed() bool InputClass::IsQPressed() const
{ {
// Touche Q sur QWERTY, A sur AZERTY // Touche Q sur QWERTY, A sur AZERTY
if (m_keyboardState[DIK_Q] & 0x80) if (m_keyboardState[DIK_Q] & 0x80)
@ -354,7 +354,7 @@ bool InputClass::IsQPressed()
return false; return false;
} }
bool InputClass::IsEPressed() bool InputClass::IsEPressed() const
{ {
if (m_keyboardState[DIK_E] & 0x80) if (m_keyboardState[DIK_E] & 0x80)
{ {
@ -364,14 +364,14 @@ bool InputClass::IsEPressed()
return false; return false;
} }
void InputClass::GetMouseLocation(int& mouseX, int& mouseY) void InputClass::GetMouseLocation(int& mouseX, int& mouseY) const
{ {
mouseX = m_mouseX; mouseX = m_mouseX;
mouseY = m_mouseY; mouseY = m_mouseY;
return; return;
} }
bool InputClass::IsLeftMousePressed() bool InputClass::IsLeftMousePressed() const
{ {
// Check the left mouse button state. // Check the left mouse button state.
if (m_mouseState.rgbButtons[0] & 0x80) if (m_mouseState.rgbButtons[0] & 0x80)
@ -382,7 +382,7 @@ bool InputClass::IsLeftMousePressed()
return false; return false;
} }
bool InputClass::IsRightMousePressed() bool InputClass::IsRightMousePressed() const
{ {
// Check the left mouse button state. // Check the left mouse button state.
if (m_mouseState.rgbButtons[1] & 0x80) if (m_mouseState.rgbButtons[1] & 0x80)
@ -393,7 +393,7 @@ bool InputClass::IsRightMousePressed()
return false; return false;
} }
bool InputClass::IsScrollUp() bool InputClass::IsScrollUp() const
{ {
if (m_mouseState.lZ > 0) if (m_mouseState.lZ > 0)
{ {
@ -403,7 +403,7 @@ bool InputClass::IsScrollUp()
return false; return false;
} }
bool InputClass::IsScrollDown() bool InputClass::IsScrollDown() const
{ {
if (m_mouseState.lZ < 0) if (m_mouseState.lZ < 0)
{ {

View File

@ -31,26 +31,26 @@ public:
void Shutdown(); void Shutdown();
bool Frame(); bool Frame();
bool IsEscapePressed(); bool IsEscapePressed() const;
void GetMouseLocation(int&, int&); void GetMouseLocation(int&, int&) const;
bool IsLeftMousePressed(); bool IsLeftMousePressed() const;
bool IsRightMousePressed(); bool IsRightMousePressed() const;
void KeyDown(unsigned int); void KeyDown(unsigned int);
void KeyUp(unsigned int); void KeyUp(unsigned int);
bool IsLeftArrowPressed(); bool IsLeftArrowPressed() const;
bool IsRightArrowPressed(); bool IsRightArrowPressed() const;
bool IsScrollUp(); bool IsScrollUp() const;
bool IsScrollDown(); bool IsScrollDown() const;
bool IsUpArrowPressed(); bool IsUpArrowPressed() const;
bool IsDownArrowPressed(); bool IsDownArrowPressed() const;
bool IsAPressed(); bool IsAPressed() const;
bool IsDPressed(); bool IsDPressed() const;
bool IsWPressed(); bool IsWPressed() const;
bool IsSPressed(); bool IsSPressed() const;
bool IsQPressed(); bool IsQPressed() const;
bool IsEPressed(); bool IsEPressed()const;
bool IsKeyDown(unsigned int); bool IsKeyDown(unsigned int) const;
private: private:
bool m_keys[256]; bool m_keys[256];

View File

@ -42,27 +42,27 @@ void Object::SetWorldMatrix(XMMATRIX worldMatrix)
m_worldMatrix = worldMatrix; m_worldMatrix = worldMatrix;
} }
XMMATRIX Object::GetScaleMatrix() XMMATRIX Object::GetScaleMatrix() const
{ {
return m_scaleMatrix; return m_scaleMatrix;
} }
XMMATRIX Object::GetRotateMatrix() XMMATRIX Object::GetRotateMatrix() const
{ {
return m_rotateMatrix; return m_rotateMatrix;
} }
XMMATRIX Object::GetTranslateMatrix() XMMATRIX Object::GetTranslateMatrix() const
{ {
return m_translateMatrix; return m_translateMatrix;
} }
XMMATRIX Object::GetSRMatrix() XMMATRIX Object::GetSRMatrix() const
{ {
return m_srMatrix; return m_srMatrix;
} }
XMMATRIX Object::GetWorldMatrix() XMMATRIX Object::GetWorldMatrix() const
{ {
return m_worldMatrix; return m_worldMatrix;
} }
@ -172,7 +172,7 @@ void Object::SetVelocity(XMVECTOR velocity)
m_velocity = velocity; m_velocity = velocity;
} }
XMVECTOR Object::GetVelocity() XMVECTOR Object::GetVelocity() const
{ {
return m_velocity; return m_velocity;
} }
@ -182,7 +182,7 @@ void Object::SetAcceleration(XMVECTOR acceleration)
m_acceleration = acceleration; m_acceleration = acceleration;
} }
XMVECTOR Object::GetAcceleration() XMVECTOR Object::GetAcceleration() const
{ {
return m_acceleration; return m_acceleration;
} }
@ -192,7 +192,7 @@ void Object::SetMass(float mass)
m_mass = mass; m_mass = mass;
} }
float Object::GetMass() float Object::GetMass() const
{ {
return m_mass; return m_mass;
} }

View File

@ -17,22 +17,22 @@ public:
void SetRotation(XMVECTOR rotation); void SetRotation(XMVECTOR rotation);
void SetScale(XMVECTOR scale); void SetScale(XMVECTOR scale);
XMMATRIX GetScaleMatrix(); XMMATRIX GetScaleMatrix() const;
XMMATRIX GetRotateMatrix(); XMMATRIX GetRotateMatrix() const;
XMMATRIX GetTranslateMatrix(); XMMATRIX GetTranslateMatrix() const;
XMMATRIX GetSRMatrix(); XMMATRIX GetSRMatrix() const;
XMMATRIX GetWorldMatrix(); XMMATRIX GetWorldMatrix() const;
XMVECTOR GetPosition(); XMVECTOR GetPosition();
XMVECTOR GetRotation(); XMVECTOR GetRotation();
XMVECTOR GetScale(); XMVECTOR GetScale();
void SetVelocity(XMVECTOR); void SetVelocity(XMVECTOR);
XMVECTOR GetVelocity(); XMVECTOR GetVelocity() const;
void SetAcceleration(XMVECTOR); void SetAcceleration(XMVECTOR);
XMVECTOR GetAcceleration(); XMVECTOR GetAcceleration() const;
void SetMass(float); void SetMass(float);
float GetMass(); float GetMass() const;
void UpdateWorldMatrix(); void UpdateWorldMatrix();
void UpdateSRMatrix(); void UpdateSRMatrix();

View File

@ -15,7 +15,7 @@ Physics::~Physics()
} }
// Get the gravity value // Get the gravity value
XMVECTOR Physics::GetGravity() XMVECTOR Physics::GetGravity() const
{ {
return m_gravity; return m_gravity;
} }

View File

@ -10,7 +10,7 @@ public:
explicit Physics(const Physics&); // Use explicit to avoid implicit conversion explicit Physics(const Physics&); // Use explicit to avoid implicit conversion
~Physics(); ~Physics();
XMVECTOR GetGravity(); // Get the gravity value XMVECTOR GetGravity() const; // Get the gravity value
void SetGravity(XMVECTOR gravity); // Define the gravity value void SetGravity(XMVECTOR gravity); // Define the gravity value
void ApplyGravity(Object*, float); // Apply gravity to an object void ApplyGravity(Object*, float); // Apply gravity to an object
void ApplyDrag(Object*, float, float); void ApplyDrag(Object*, float, float);