ICameraSceneNode.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef IRR_I_CAMERA_SCENE_NODE_H_INCLUDED
  5. #define IRR_I_CAMERA_SCENE_NODE_H_INCLUDED
  6. #include "ISceneNode.h"
  7. #include "IEventReceiver.h"
  8. namespace irr
  9. {
  10. namespace scene
  11. {
  12. struct SViewFrustum;
  13. //! Scene Node which is a (controllable) camera.
  14. /** The whole scene will be rendered from the cameras point of view.
  15. Because the ICameraSceneNode is a SceneNode, it can be attached to any
  16. other scene node, and will follow its parents movement, rotation and so
  17. on.
  18. */
  19. class ICameraSceneNode : public ISceneNode, public IEventReceiver
  20. {
  21. public:
  22. //! Constructor
  23. ICameraSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
  24. const core::vector3df& position = core::vector3df(0,0,0),
  25. const core::vector3df& rotation = core::vector3df(0,0,0),
  26. const core::vector3df& scale = core::vector3df(1.0f,1.0f,1.0f))
  27. : ISceneNode(parent, mgr, id, position, rotation, scale), IsOrthogonal(false) {}
  28. //! Sets the projection matrix of the camera.
  29. /** The core::matrix4 class has some methods to build a
  30. projection matrix. e.g:
  31. core::matrix4::buildProjectionMatrixPerspectiveFovLH.
  32. Note that the matrix will only stay as set by this method until
  33. one of the following Methods are called: setNearValue,
  34. setFarValue, setAspectRatio, setFOV.
  35. NOTE: The frustum is not updated before render() is called
  36. unless you explicitly call updateMatrices()
  37. \param projection The new projection matrix of the camera.
  38. \param isOrthogonal Set this to true if the matrix is an
  39. orthogonal one (e.g. from matrix4::buildProjectionMatrixOrtho).
  40. */
  41. virtual void setProjectionMatrix(const core::matrix4& projection, bool isOrthogonal=false) =0;
  42. //! Gets the current projection matrix of the camera.
  43. /** \return The current projection matrix of the camera. */
  44. virtual const core::matrix4& getProjectionMatrix() const =0;
  45. //! Gets the current view matrix of the camera.
  46. /** \return The current view matrix of the camera. */
  47. virtual const core::matrix4& getViewMatrix() const =0;
  48. //! Sets a custom view matrix affector.
  49. /** The matrix passed here, will be multiplied with the view
  50. matrix when it gets updated. This allows for custom camera
  51. setups like, for example, a reflection camera.
  52. \param affector The affector matrix. */
  53. virtual void setViewMatrixAffector(const core::matrix4& affector) =0;
  54. //! Get the custom view matrix affector.
  55. /** \return The affector matrix. */
  56. virtual const core::matrix4& getViewMatrixAffector() const =0;
  57. //! It is possible to send mouse and key events to the camera.
  58. /** Most cameras may ignore this input, but camera scene nodes
  59. which are created for example with
  60. ISceneManager::addCameraSceneNodeMaya or
  61. ISceneManager::addCameraSceneNodeFPS, may want to get
  62. this input for changing their position, look at target or
  63. whatever. */
  64. virtual bool OnEvent(const SEvent& event) IRR_OVERRIDE =0;
  65. //! Sets the look at target of the camera
  66. /** If the camera's target and rotation are bound ( @see
  67. bindTargetAndRotation() ) then calling this will also change
  68. the camera's scene node rotation to match the target.
  69. Note that setTarget uses the current absolute position
  70. internally, so if you changed setPosition since last rendering you must
  71. call updateAbsolutePosition before using this function.
  72. \param pos Look at target of the camera, in world co-ordinates. */
  73. virtual void setTarget(const core::vector3df& pos) =0;
  74. //! Sets the rotation of the node.
  75. /** This only modifies the relative rotation of the node.
  76. If the camera's target and rotation are bound ( @see
  77. bindTargetAndRotation() ) then calling this will also change
  78. the camera's target to match the rotation.
  79. \param rotation New rotation of the node in degrees. */
  80. virtual void setRotation(const core::vector3df& rotation) IRR_OVERRIDE =0;
  81. //! Gets the current look at target of the camera
  82. /** \return The current look at target of the camera, in world co-ordinates */
  83. virtual const core::vector3df& getTarget() const =0;
  84. //! Sets the up vector of the camera.
  85. /** \param pos: New upvector of the camera. */
  86. virtual void setUpVector(const core::vector3df& pos) =0;
  87. //! Gets the up vector of the camera.
  88. /** \return The up vector of the camera, in world space. */
  89. virtual const core::vector3df& getUpVector() const =0;
  90. //! Gets the value of the near plane of the camera.
  91. /** \return The value of the near plane of the camera. */
  92. virtual f32 getNearValue() const =0;
  93. //! Gets the value of the far plane of the camera.
  94. /** \return The value of the far plane of the camera. */
  95. virtual f32 getFarValue() const =0;
  96. //! Gets the aspect ratio of the camera.
  97. /** \return The aspect ratio of the camera. */
  98. virtual f32 getAspectRatio() const =0;
  99. //! Gets the vertical field of view of the camera.
  100. /** \return The field of view of the camera in radians. */
  101. virtual f32 getFOV() const =0;
  102. //! Get the horizontal and vertical lens/projection plane shift
  103. /** \return Project plane offset */
  104. virtual core::vector2df getLensShift() const
  105. {
  106. return core::vector2df(0.f, 0.f);
  107. }
  108. //! Sets the value of the near clipping plane. (default: 1.0f)
  109. /** Also changes projection matrix and resets IsOrthogonal flag.
  110. \param zn: New z near value. */
  111. virtual void setNearValue(f32 zn) =0;
  112. //! Sets the value of the far clipping plane (default: 2000.0f)
  113. /** Also changes projection matrix and resets IsOrthogonal flag.
  114. \param zf: New z far value. */
  115. virtual void setFarValue(f32 zf) =0;
  116. //! Sets the aspect ratio (default: 4.0f / 3.0f)
  117. /** Also changes projection matrix and resets IsOrthogonal flag.
  118. \param aspect: New aspect ratio. */
  119. virtual void setAspectRatio(f32 aspect) =0;
  120. //! Sets the vertical field of view (Default: PI / 2.5f)
  121. /** Also changes projection matrix and resets IsOrthogonal flag.
  122. \param fovy: New field of view in radians. */
  123. virtual void setFOV(f32 fovy) =0;
  124. //! Set the horizontal and vertical lens/projection plane shift
  125. /** Like rendering a larger field of view and then cropping
  126. it off-center. Allows for things like 2-point perspective.
  127. \param shift: Offset by which the projection plane is moved.
  128. If you move by 1 or -1 it will move the center by half a screen.
  129. Positive X go to the left and positive Y go down.
  130. By default it will be 0,0 */
  131. virtual void setLensShift(const core::vector2df& shift)
  132. {}
  133. //! Get the view frustum.
  134. /** \return The current view frustum. */
  135. virtual const SViewFrustum* getViewFrustum() const =0;
  136. //! Disables or enables the camera to get key or mouse inputs.
  137. /** If this is set to true, the camera will respond to key
  138. inputs otherwise not. */
  139. virtual void setInputReceiverEnabled(bool enabled) =0;
  140. //! Checks if the input receiver of the camera is currently enabled.
  141. virtual bool isInputReceiverEnabled() const =0;
  142. //! Checks if a camera is orthogonal.
  143. virtual bool isOrthogonal() const
  144. {
  145. return IsOrthogonal;
  146. }
  147. //! Binds the camera scene node's rotation to its target position and vice versa, or unbinds them.
  148. /** When bound, calling setRotation() will update the camera's
  149. target position to be along its +Z axis, and likewise calling
  150. setTarget() will update its rotation so that its +Z axis will
  151. point at the target point. FPS camera use this binding by
  152. default; other cameras do not.
  153. \param bound True to bind the camera's scene node rotation
  154. and targeting, false to unbind them.
  155. @see getTargetAndRotationBinding() */
  156. virtual void bindTargetAndRotation(bool bound) =0;
  157. //! Updates the view matrix and frustum without uploading the matrix to the driver.
  158. /** You need this when you want an up-to-date camera view matrix & frustum before the render() call.
  159. Usually you should call updateAbsolutePosition() before calling this.
  160. Despite it's function name, the projection matrix is not touched. */
  161. virtual void updateMatrices() = 0;
  162. //! Queries if the camera scene node's rotation and its target position are bound together.
  163. /** @see bindTargetAndRotation() */
  164. virtual bool getTargetAndRotationBinding(void) const =0;
  165. //! Writes attributes of the camera node
  166. virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const IRR_OVERRIDE
  167. {
  168. ISceneNode::serializeAttributes(out, options);
  169. if (!out)
  170. return;
  171. out->addBool("IsOrthogonal", IsOrthogonal);
  172. }
  173. //! Reads attributes of the camera node
  174. virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) IRR_OVERRIDE
  175. {
  176. ISceneNode::deserializeAttributes(in, options);
  177. if (!in)
  178. return;
  179. if ( in->findAttribute("IsOrthogonal") )
  180. IsOrthogonal = in->getAttributeAsBool("IsOrthogonal");
  181. }
  182. protected:
  183. void cloneMembers(const ICameraSceneNode* toCopyFrom)
  184. {
  185. IsOrthogonal = toCopyFrom->IsOrthogonal;
  186. }
  187. bool IsOrthogonal;
  188. };
  189. } // end namespace scene
  190. } // end namespace irr
  191. #endif