Simple game engine with complete export to scripting language
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

88 行
1.2 KiB

  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