Merge branch 'CameraMov'
This commit is contained in:
commit
2aa6256d7a
@ -5,6 +5,9 @@ PositionClass::PositionClass()
|
||||
m_frameTime = 0.0f;
|
||||
m_rotationY = 0.0f;
|
||||
m_rotationX = 0.0f;
|
||||
m_positionX = 0.0f;
|
||||
m_positionY = 0.0f;
|
||||
m_positionZ = 0.0f;
|
||||
m_leftTurnSpeed = 0.0f;
|
||||
m_rightTurnSpeed = 0.0f;
|
||||
}
|
||||
@ -32,6 +35,14 @@ void PositionClass::GetRotation(float& y, float& x)
|
||||
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)
|
||||
{
|
||||
// If the key is pressed increase the speed at which the camera turns left. If not slow down the turn speed.
|
||||
@ -128,4 +139,63 @@ void PositionClass::TurnMouse(float deltaX, float deltaY)
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void PositionClass::MoveCamera(bool forward, bool backward, bool left, bool right, bool up, bool down)
|
||||
{
|
||||
float radiansY, radiansX;
|
||||
float speed;
|
||||
|
||||
// Set the speed of the camera.
|
||||
speed = 0.1f;
|
||||
|
||||
// Convert degrees to radians.
|
||||
radiansY = m_rotationY * 0.0174532925f;
|
||||
radiansX = m_rotationX * 0.0174532925f;
|
||||
|
||||
// Update the position.
|
||||
|
||||
// If moving forward, the position moves in the direction of the camera and accordingly to its angle.
|
||||
if (forward)
|
||||
{
|
||||
m_positionX += sinf(radiansY) * cosf(radiansX) * speed;
|
||||
m_positionZ += cosf(radiansY) * cosf(radiansX) * speed;
|
||||
m_positionY -= sinf(radiansX) * speed;
|
||||
}
|
||||
|
||||
// If moving backward, the position moves in the opposite direction of the camera and accordingly to its angle.
|
||||
if (backward)
|
||||
{
|
||||
m_positionX -= sinf(radiansY) * cosf(radiansX) * speed;
|
||||
m_positionZ -= cosf(radiansY) * cosf(radiansX) * speed;
|
||||
m_positionY += sinf(radiansX) * speed;
|
||||
}
|
||||
|
||||
// If moving left, the position moves to the left of the camera and accordingly to its angle.
|
||||
if (left)
|
||||
{
|
||||
m_positionX -= cosf(radiansY) * speed;
|
||||
m_positionZ += sinf(radiansY) * speed;
|
||||
}
|
||||
|
||||
// If moving right, the position moves to the right of the camera and accordingly to its angle.
|
||||
if (right)
|
||||
{
|
||||
m_positionX += cosf(radiansY) * speed;
|
||||
m_positionZ -= sinf(radiansY) * speed;
|
||||
}
|
||||
|
||||
// If moving up, the position moves up.
|
||||
if (up)
|
||||
{
|
||||
m_positionY += speed;
|
||||
}
|
||||
|
||||
// If moving down, the position moves down.
|
||||
if (down)
|
||||
{
|
||||
m_positionY -= speed;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
@ -20,14 +20,17 @@ public:
|
||||
|
||||
void SetFrameTime(float);
|
||||
void GetRotation(float&, float&);
|
||||
void GetPosition(float&, float&, float&);
|
||||
|
||||
void TurnLeft(bool);
|
||||
void TurnRight(bool);
|
||||
void TurnMouse(float, float);
|
||||
void MoveCamera(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;
|
||||
};
|
||||
|
||||
|
@ -573,8 +573,8 @@ void ApplicationClass::Shutdown()
|
||||
bool ApplicationClass::Frame(InputClass* Input)
|
||||
{
|
||||
int mouseX, mouseY, currentMouseX, currentMouseY;
|
||||
bool result, mouseDown, keyDown;
|
||||
float rotationY, rotationX;
|
||||
bool result, mouseDown, keyDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE;
|
||||
float rotationY, rotationX, positionX, positionY, positionZ;
|
||||
|
||||
float frameTime;
|
||||
|
||||
@ -625,7 +625,18 @@ bool ApplicationClass::Frame(InputClass* Input)
|
||||
// Get the current view point rotation.
|
||||
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->Render();
|
||||
|
||||
|
@ -276,6 +276,73 @@ bool InputClass::IsRightArrowPressed()
|
||||
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)
|
||||
{
|
||||
mouseX = m_mouseX;
|
||||
|
@ -38,6 +38,12 @@ public:
|
||||
void KeyUp(unsigned int);
|
||||
bool IsLeftArrowPressed();
|
||||
bool IsRightArrowPressed();
|
||||
bool IsAPressed();
|
||||
bool IsDPressed();
|
||||
bool IsWPressed();
|
||||
bool IsSPressed();
|
||||
bool IsQPressed();
|
||||
bool IsEPressed();
|
||||
|
||||
bool IsKeyDown(unsigned int);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user