Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. void PositionClass::MoveLeft(bool keydown)
  2. {
  3. float radians;
  4.  
  5. // Update the left speed movement based on the frame time and whether the user is holding the key down or not.
  6. if (keydown)
  7. {
  8. m_leftSpeed += m_frameTime * 0.001f;
  9.  
  10. if (m_leftSpeed > (m_frameTime * 0.03f))
  11. {
  12. m_leftSpeed = m_frameTime * 0.03f;
  13. }
  14. }
  15. else
  16. {
  17. m_leftSpeed -= m_frameTime * 0.0007f;
  18.  
  19. if (m_leftSpeed < 0.0f)
  20. {
  21. m_leftSpeed = 0.0f;
  22. }
  23. }
  24.  
  25. // Convert degrees to radians.
  26. radians = m_rotationY * 0.0174532925f;
  27.  
  28. // Update the position.
  29. m_positionX -= sinf(radians + 90) * m_leftSpeed;
  30. m_positionZ -= cosf(radians + 90) * m_leftSpeed;
  31.  
  32. return;
  33. }
  34.  
  35. void PositionClass::MoveRight(bool keydown)
  36. {
  37. float radians;
  38.  
  39. // Update the right speed movement based on the frame time and whether the user is holding the key down or not.
  40. if (keydown)
  41. {
  42. m_rightSpeed += m_frameTime * 0.001f;
  43.  
  44. if (m_rightSpeed > (m_frameTime * 0.03f))
  45. {
  46. m_rightSpeed = m_frameTime * 0.03f;
  47. }
  48. }
  49. else
  50. {
  51. m_rightSpeed -= m_frameTime * 0.0007f;
  52.  
  53. if (m_rightSpeed < 0.0f)
  54. {
  55. m_rightSpeed = 0.0f;
  56. }
  57. }
  58.  
  59. // Convert degrees to radians.
  60. radians = m_rotationY * 0.0174532925f;
  61.  
  62. // Update the position.
  63. m_positionX += sinf(radians + 90) * m_rightSpeed;
  64. m_positionZ += cosf(radians + 90) * m_rightSpeed;
  65.  
  66. return;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement