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.

118 lines
3.4 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #ifndef EIGEN_CAMERA_H
  10. #define EIGEN_CAMERA_H
  11. #include <Eigen/Geometry>
  12. #include <QObject>
  13. // #include <frame.h>
  14. class Frame
  15. {
  16. public:
  17. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  18. inline Frame(const Eigen::Vector3f& pos = Eigen::Vector3f::Zero(),
  19. const Eigen::Quaternionf& o = Eigen::Quaternionf())
  20. : orientation(o), position(pos)
  21. {}
  22. Frame lerp(float alpha, const Frame& other) const
  23. {
  24. return Frame((1.f-alpha)*position + alpha * other.position,
  25. orientation.slerp(alpha,other.orientation));
  26. }
  27. Eigen::Quaternionf orientation;
  28. Eigen::Vector3f position;
  29. };
  30. class Camera
  31. {
  32. public:
  33. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  34. Camera(void);
  35. Camera(const Camera& other);
  36. virtual ~Camera();
  37. Camera& operator=(const Camera& other);
  38. void setViewport(uint offsetx, uint offsety, uint width, uint height);
  39. void setViewport(uint width, uint height);
  40. inline uint vpX(void) const { return mVpX; }
  41. inline uint vpY(void) const { return mVpY; }
  42. inline uint vpWidth(void) const { return mVpWidth; }
  43. inline uint vpHeight(void) const { return mVpHeight; }
  44. inline float fovY(void) const { return mFovY; }
  45. void setFovY(float value);
  46. void setPosition(const Eigen::Vector3f& pos);
  47. inline const Eigen::Vector3f& position(void) const { return mFrame.position; }
  48. void setOrientation(const Eigen::Quaternionf& q);
  49. inline const Eigen::Quaternionf& orientation(void) const { return mFrame.orientation; }
  50. void setFrame(const Frame& f);
  51. const Frame& frame(void) const { return mFrame; }
  52. void setDirection(const Eigen::Vector3f& newDirection);
  53. Eigen::Vector3f direction(void) const;
  54. void setUp(const Eigen::Vector3f& vectorUp);
  55. Eigen::Vector3f up(void) const;
  56. Eigen::Vector3f right(void) const;
  57. void setTarget(const Eigen::Vector3f& target);
  58. inline const Eigen::Vector3f& target(void) { return mTarget; }
  59. const Eigen::Affine3f& viewMatrix(void) const;
  60. const Eigen::Matrix4f& projectionMatrix(void) const;
  61. void rotateAroundTarget(const Eigen::Quaternionf& q);
  62. void localRotate(const Eigen::Quaternionf& q);
  63. void zoom(float d);
  64. void localTranslate(const Eigen::Vector3f& t);
  65. /** Setup OpenGL matrices and viewport */
  66. void activateGL(void);
  67. Eigen::Vector3f unProject(const Eigen::Vector2f& uv, float depth, const Eigen::Matrix4f& invModelview) const;
  68. Eigen::Vector3f unProject(const Eigen::Vector2f& uv, float depth) const;
  69. protected:
  70. void updateViewMatrix(void) const;
  71. void updateProjectionMatrix(void) const;
  72. protected:
  73. uint mVpX, mVpY;
  74. uint mVpWidth, mVpHeight;
  75. Frame mFrame;
  76. mutable Eigen::Affine3f mViewMatrix;
  77. mutable Eigen::Matrix4f mProjectionMatrix;
  78. mutable bool mViewIsUptodate;
  79. mutable bool mProjIsUptodate;
  80. // used by rotateAroundTarget
  81. Eigen::Vector3f mTarget;
  82. float mFovY;
  83. float mNearDist;
  84. float mFarDist;
  85. };
  86. #endif // EIGEN_CAMERA_H