Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Camera.cpp 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*!
  2. * \file src/Camera.cpp
  3. * \brief Camera class
  4. *
  5. * \author Mongoose
  6. * \author xythobuz
  7. */
  8. #include "glm/gtc/matrix_transform.hpp"
  9. #include "global.h"
  10. #include "Camera.h"
  11. glm::vec3 Camera::pos(0.0f, 0.0f, 0.0f);
  12. float Camera::thetaX = glm::pi<float>();
  13. float Camera::thetaY = 0.0f;
  14. float Camera::rotationDeltaX = 0.75f;
  15. float Camera::rotationDeltaY = 0.75f;
  16. void Camera::handleMouseMotion(int x, int y) {
  17. while (x > 0) {
  18. if (thetaX < (glm::pi<float>() / 2.0f)) {
  19. thetaX += rotationDeltaX;
  20. }
  21. x--;
  22. }
  23. while (x < 0) {
  24. if (thetaX > -(glm::pi<float>() / 2.0f)) {
  25. thetaX -= rotationDeltaX;
  26. }
  27. x++;
  28. }
  29. while (y > 0) {
  30. if (thetaY < (glm::pi<float>() / 2.0f)) {
  31. thetaY += rotationDeltaY;
  32. }
  33. y--;
  34. }
  35. while (y < 0) {
  36. if (thetaY > -(glm::pi<float>() / 2.0f)) {
  37. thetaY -= rotationDeltaY;
  38. }
  39. y++;
  40. }
  41. }
  42. glm::mat4 Camera::getViewMatrix() {
  43. glm::vec3 dir(
  44. glm::cos(thetaY) * glm::sin(thetaX),
  45. glm::sin(thetaY),
  46. glm::cos(thetaY) * glm::cos(thetaX)
  47. );
  48. glm::vec3 right(
  49. glm::sin(thetaX - glm::pi<float>() / 2.0f),
  50. 0.0f,
  51. glm::cos(thetaX - glm::pi<float>() / 2.0f)
  52. );
  53. glm::vec3 up = glm::cross(right, dir);
  54. return glm::lookAt(pos, pos + dir, up);
  55. }