Simple game engine with complete export to scripting language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Camera.cpp 1.2KB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "Camera.h"
  2. #include "Math/Matrix.h"
  3. #include "GL/glfw.h"
  4. namespace BlueCore
  5. {
  6. Camera::Camera() :
  7. _LookAt (false), _FoV(45.0), _NearPlane(1.0), _FarPlane(15000.0)
  8. {
  9. }
  10. Camera::~Camera()
  11. {
  12. }
  13. void Camera::setFoV(Scalar fov)
  14. {
  15. _FoV = fov;
  16. }
  17. void Camera::setNearPlane(Scalar near)
  18. {
  19. _NearPlane = near;
  20. }
  21. void Camera::setFarPlane(Scalar far)
  22. {
  23. _FarPlane = far;
  24. }
  25. void Camera::setPosition(const Vector3& position)
  26. {
  27. _Position = position;
  28. if (_LookAt)
  29. updateLookAtRotation();
  30. }
  31. const Vector3& Camera::getPosition()
  32. {
  33. return _Position;
  34. }
  35. void Camera::setRotation(const Quaternion& rotation)
  36. {
  37. _Rotation = rotation;
  38. }
  39. const Quaternion& Camera::getRotation()
  40. {
  41. return _Rotation;
  42. }
  43. Scalar Camera::getNearPlane() const
  44. {
  45. return _NearPlane;
  46. }
  47. Scalar Camera::getFarPlane() const
  48. {
  49. return _FarPlane;
  50. }
  51. Scalar Camera::getFov() const
  52. {
  53. return _FoV;
  54. }
  55. void Camera::lookAt(const Vector3 &point)
  56. {
  57. _LookAt = true;
  58. _LookAtPoint = point;
  59. _LookAtUp = Vector3(0.0, 1.0, 0.0);
  60. updateLookAtRotation();
  61. }
  62. void Camera::updateLookAtRotation()
  63. {
  64. Matrix3x3 m (_LookAtPoint - _Position, _LookAtUp);
  65. _Rotation = m.toQuaternion().inversed();
  66. }
  67. } // namespace BlueCore