CameraView 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSG_CAMERAVIEW
  14. #define OSG_CAMERAVIEW 1
  15. #include <osg/Group>
  16. #include <osg/Transform>
  17. #include <osg/AnimationPath>
  18. #include <osg/Vec3d>
  19. #include <osg/Quat>
  20. namespace osg {
  21. /** CameraView - is a Transform that is used to specify camera views from within the scene graph.
  22. * The application must attach a camera to a CameraView via the NodePath from the top of the scene graph
  23. * to the CameraView node itself, and accumulate the view matrix from this NodePath.
  24. */
  25. class OSG_EXPORT CameraView : public Transform
  26. {
  27. public :
  28. CameraView();
  29. CameraView(const CameraView& pat,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  30. Transform(pat,copyop),
  31. _position(pat._position),
  32. _attitude(pat._attitude),
  33. _fieldOfView(pat._fieldOfView),
  34. _fieldOfViewMode(pat._fieldOfViewMode),
  35. _focalLength(pat._focalLength) {}
  36. META_Node(osg, CameraView);
  37. /** Set the position of the camera view.*/
  38. inline void setPosition(const Vec3d& pos) { _position = pos; dirtyBound(); }
  39. /** Get the position of the camera view.*/
  40. inline const Vec3d& getPosition() const { return _position; }
  41. /** Set the attitude of the camera view.*/
  42. inline void setAttitude(const Quat& quat) { _attitude = quat; dirtyBound(); }
  43. /** Get the attitude of the camera view.*/
  44. inline const Quat& getAttitude() const { return _attitude; }
  45. /** Set the field of view.
  46. * The camera's field of view can be constrained to either the horizontal or vertical axis of the camera, or unconstrained
  47. * in which case the camera/application are left to choose an appropriate field of view.
  48. * The default value if 60 degrees. */
  49. inline void setFieldOfView(double fieldOfView) { _fieldOfView = fieldOfView; }
  50. /** Get the field of view.*/
  51. inline double getFieldOfView() const { return _fieldOfView; }
  52. enum FieldOfViewMode
  53. {
  54. UNCONSTRAINED,
  55. HORIZONTAL,
  56. VERTICAL
  57. };
  58. /** Set the field of view mode - controlling how the field of view of the camera is constrained by the CameraView settings.*/
  59. inline void setFieldOfViewMode(FieldOfViewMode mode) { _fieldOfViewMode = mode; }
  60. /** Get the field of view mode.*/
  61. inline FieldOfViewMode getFieldOfViewMode() const { return _fieldOfViewMode; }
  62. /** Set the focal length of the camera.
  63. * A focal length of 0.0 indicates that the camera/application should determine the focal length.
  64. * The default value is 0.0. */
  65. inline void setFocalLength(double focalLength) { _focalLength = focalLength; }
  66. /** Get the focal length of the camera.*/
  67. inline double getFocalLength() const { return _focalLength; }
  68. virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const;
  69. virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const;
  70. protected :
  71. virtual ~CameraView() {}
  72. Vec3d _position;
  73. Quat _attitude;
  74. double _fieldOfView;
  75. FieldOfViewMode _fieldOfViewMode;
  76. double _focalLength;
  77. };
  78. }
  79. #endif