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;
}
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;

View File

@ -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;

View File

@ -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)
{

View File

@ -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

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 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)
{

View File

@ -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];

View File

@ -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;
}

View File

@ -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();

View File

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

View File

@ -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);