Guest User

Untitled

a guest
Feb 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #include "Camera2.h"
  2. #include "Player.h"
  3.  
  4. Camera2::Camera2()
  5. {
  6. }
  7.  
  8. Camera2::~Camera2()
  9. {
  10. }
  11.  
  12. void Camera2::Position_Camera(float pos_x, float pos_y, float pos_z, float view_x, float view_y, float view_z, float up_x, float up_y, float up_z)
  13. {
  14. mPos = Vector3(pos_x, pos_y, pos_z);
  15. mView = Vector3(view_x, view_y, view_z);
  16. mUp = Vector3(up_x, up_y, up_z);
  17. }
  18.  
  19. void Camera2::Move_Camera(float speed)
  20. {
  21. Vector3 vVector;
  22. vVector.x = mView.x - mPos.x;
  23. vVector.y = mView.y - mPos.y;
  24. vVector.z = mView.z - mPos.z; //The view vector
  25.  
  26. //forwards and backwards camera speed
  27. mPos.x = mPos.x + vVector.x * speed;
  28. mPos.z = mPos.z + vVector.z * speed;
  29. mView.x = mView.x + vVector.x * speed;
  30. mView.z = mView.z + vVector.z * speed;
  31. }
  32.  
  33.  
  34. void Camera2::Rotate_View(float speed) //Rotates the camera view
  35. {
  36. Vector3 vVector;
  37. vVector.x = mView.x - mPos.x;
  38. vVector.y = mView.y - mPos.y;
  39. vVector.z = mView.z - mPos.z; //The view vector
  40.  
  41. mView.z = (float)(mPos.z + sin(speed)*vVector.x + cos(speed)*vVector.z);
  42. mView.x = (float)(mPos.x + cos(speed)*vVector.x - sin(speed)*vVector.z);
  43. }
  44.  
  45. void Camera2::Rotate_Position(float speed)
  46. {
  47. Vector3 vVector;
  48. vVector.x = mPos.x - mView.x;
  49. vVector.y = mPos.y - mView.y;
  50. vVector.z = mPos.z - mView.z;
  51.  
  52. mPos.z = (float)(mView.z + sin(speed)*vVector.x + cos(speed)*vVector.z);
  53. mPos.x = (float)(mView.x + cos(speed)*vVector.x - sin(speed)*vVector.z);
  54. }
  55.  
  56. void Camera2::Mouse_Move(int wndWidth, int wndHieght)
  57. {
  58. //MouseInfo mousePos;
  59. POINT mousePos;
  60. int mid_X = wndWidth >> 1;
  61. int mid_Y = wndHieght >> 1;
  62. float angle_Y = 0.0f;
  63. float angle_Z = 0.0f;
  64.  
  65. GetCursorPos(&mousePos); //built in Microsoft function which gets the mouse curose 2D position (x, y)
  66.  
  67. if ((mousePos.x == mid_X) && (mousePos.y == mid_Y))
  68. {
  69. return;
  70. }
  71.  
  72. SetCursorPos(mid_X, mid_Y); //Another microsoft function
  73.  
  74. //Get the direction from the mouse curose, set a manevering speed
  75. angle_Y = (float) ( (mid_X - mousePos.x) ) / 1000;
  76. angle_Z = (float) ( (mid_Y - mousePos.y) ) / 1000;
  77.  
  78. //This speed determines the cameras looks speed
  79. mView.y += angle_Z * 2;
  80.  
  81. if (mView.y > 3.5f)
  82. {
  83. mView.y = 3.5f;
  84. }
  85.  
  86. if (mView.y < -5.4f)
  87. {
  88. mView.y = -5.4f;
  89. }
  90.  
  91. Rotate_Position(-angle_Y);
  92. }
Add Comment
Please, Sign In to add comment