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