ajout deplacement camera
This commit is contained in:
parent
5817867594
commit
ea5619e2a0
@ -5,6 +5,9 @@ PositionClass::PositionClass()
|
|||||||
m_frameTime = 0.0f;
|
m_frameTime = 0.0f;
|
||||||
m_rotationY = 0.0f;
|
m_rotationY = 0.0f;
|
||||||
m_rotationX = 0.0f;
|
m_rotationX = 0.0f;
|
||||||
|
m_positionX = 0.0f;
|
||||||
|
m_positionY = 0.0f;
|
||||||
|
m_positionZ = 0.0f;
|
||||||
m_leftTurnSpeed = 0.0f;
|
m_leftTurnSpeed = 0.0f;
|
||||||
m_rightTurnSpeed = 0.0f;
|
m_rightTurnSpeed = 0.0f;
|
||||||
}
|
}
|
||||||
@ -32,6 +35,14 @@ void PositionClass::GetRotation(float& y, float& x)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PositionClass::GetPosition(float& x, float& y, float& z)
|
||||||
|
{
|
||||||
|
x = m_positionX;
|
||||||
|
y = m_positionY;
|
||||||
|
z = m_positionZ;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void PositionClass::TurnLeft(bool keydown)
|
void PositionClass::TurnLeft(bool keydown)
|
||||||
{
|
{
|
||||||
// If the key is pressed increase the speed at which the camera turns left. If not slow down the turn speed.
|
// If the key is pressed increase the speed at which the camera turns left. If not slow down the turn speed.
|
||||||
@ -128,4 +139,53 @@ void PositionClass::TurnMouse(float deltaX, float deltaY)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PositionClass::MoveCamera(bool forward, bool backward, bool left, bool right, bool up, bool down)
|
||||||
|
{
|
||||||
|
float radians;
|
||||||
|
float speed;
|
||||||
|
|
||||||
|
// Set the speed of the camera.
|
||||||
|
speed = 0.1f;
|
||||||
|
|
||||||
|
// Convert degrees to radians.
|
||||||
|
radians = m_rotationY * 0.0174532925f;
|
||||||
|
|
||||||
|
// Update the position.
|
||||||
|
if (forward)
|
||||||
|
{
|
||||||
|
m_positionX += sinf(radians) * speed;
|
||||||
|
m_positionZ += cosf(radians) * speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (backward)
|
||||||
|
{
|
||||||
|
m_positionX -= sinf(radians) * speed;
|
||||||
|
m_positionZ -= cosf(radians) * speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (left)
|
||||||
|
{
|
||||||
|
m_positionX -= cosf(radians) * speed;
|
||||||
|
m_positionZ += sinf(radians) * speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (right)
|
||||||
|
{
|
||||||
|
m_positionX += cosf(radians) * speed;
|
||||||
|
m_positionZ -= sinf(radians) * speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (up)
|
||||||
|
{
|
||||||
|
m_positionY += speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (down)
|
||||||
|
{
|
||||||
|
m_positionY -= speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
@ -20,14 +20,17 @@ public:
|
|||||||
|
|
||||||
void SetFrameTime(float);
|
void SetFrameTime(float);
|
||||||
void GetRotation(float&, float&);
|
void GetRotation(float&, float&);
|
||||||
|
void GetPosition(float&, float&, float&);
|
||||||
|
|
||||||
void TurnLeft(bool);
|
void TurnLeft(bool);
|
||||||
void TurnRight(bool);
|
void TurnRight(bool);
|
||||||
void TurnMouse(float, float);
|
void TurnMouse(float, float);
|
||||||
|
void MoveCamera(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_leftTurnSpeed, m_rightTurnSpeed, m_horizontalTurnSpeed, m_verticalTurnSpeed;
|
float m_leftTurnSpeed, m_rightTurnSpeed, m_horizontalTurnSpeed, m_verticalTurnSpeed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -573,8 +573,8 @@ 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, mouseDown, keyDown;
|
bool result, mouseDown, keyDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE;
|
||||||
float rotationY, rotationX;
|
float rotationY, rotationX, positionX, positionY, positionZ;
|
||||||
|
|
||||||
float frameTime;
|
float frameTime;
|
||||||
|
|
||||||
@ -625,7 +625,18 @@ 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);
|
||||||
|
|
||||||
// Set the rotation of the camera.
|
// 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();
|
||||||
|
buttonZ = Input->IsWPressed();
|
||||||
|
buttonS = Input->IsSPressed();
|
||||||
|
buttonA = Input->IsQPressed();
|
||||||
|
buttonE = Input->IsEPressed();
|
||||||
|
m_Position->MoveCamera(buttonZ, buttonS, buttonQ, buttonD, buttonE, buttonA);
|
||||||
|
m_Position->GetPosition(positionX, positionY, positionZ);
|
||||||
|
|
||||||
|
// Set the postion and rotation of the camera.
|
||||||
|
m_Camera->SetPosition(positionX, positionY, positionZ);
|
||||||
m_Camera->SetRotation(rotationX, rotationY, 0.0f);
|
m_Camera->SetRotation(rotationX, rotationY, 0.0f);
|
||||||
m_Camera->Render();
|
m_Camera->Render();
|
||||||
|
|
||||||
|
@ -276,6 +276,73 @@ bool InputClass::IsRightArrowPressed()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////
|
||||||
|
// Les touches correspondent aux claviers QWERTY //
|
||||||
|
///////////////////////////////////////////////////
|
||||||
|
|
||||||
|
bool InputClass::IsAPressed()
|
||||||
|
{
|
||||||
|
// Touche A sur QWERTY, Q sur AZERTY
|
||||||
|
if (m_keyboardState[DIK_A] & 0x80)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InputClass::IsDPressed()
|
||||||
|
{
|
||||||
|
if (m_keyboardState[DIK_D] & 0x80)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InputClass::IsWPressed()
|
||||||
|
{
|
||||||
|
// Touche W sur QWERTY, Z sur AZERTY
|
||||||
|
if (m_keyboardState[DIK_W] & 0x80)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InputClass::IsSPressed()
|
||||||
|
{
|
||||||
|
if (m_keyboardState[DIK_S] & 0x80)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InputClass::IsQPressed()
|
||||||
|
{
|
||||||
|
// Touche Q sur QWERTY, A sur AZERTY
|
||||||
|
if (m_keyboardState[DIK_Q] & 0x80)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InputClass::IsEPressed()
|
||||||
|
{
|
||||||
|
if (m_keyboardState[DIK_E] & 0x80)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void InputClass::GetMouseLocation(int& mouseX, int& mouseY)
|
void InputClass::GetMouseLocation(int& mouseX, int& mouseY)
|
||||||
{
|
{
|
||||||
mouseX = m_mouseX;
|
mouseX = m_mouseX;
|
||||||
|
@ -38,6 +38,12 @@ public:
|
|||||||
void KeyUp(unsigned int);
|
void KeyUp(unsigned int);
|
||||||
bool IsLeftArrowPressed();
|
bool IsLeftArrowPressed();
|
||||||
bool IsRightArrowPressed();
|
bool IsRightArrowPressed();
|
||||||
|
bool IsAPressed();
|
||||||
|
bool IsDPressed();
|
||||||
|
bool IsWPressed();
|
||||||
|
bool IsSPressed();
|
||||||
|
bool IsQPressed();
|
||||||
|
bool IsEPressed();
|
||||||
|
|
||||||
bool IsKeyDown(unsigned int);
|
bool IsKeyDown(unsigned int);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user