1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://floralicense.org/license/
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
21 #include <dali/public-api/math/rect.h>
22 #include <dali/public-api/actors/camera-actor.h>
23 #include <dali/internal/common/message.h>
24 #include <dali/internal/common/event-to-update.h>
25 #include <dali/internal/update/common/double-buffered.h>
26 #include <dali/internal/update/node-attachments/node-attachment.h>
27 #include <dali/internal/update/common/animatable-property.h>
28 #include <dali/internal/update/common/inherited-property.h>
36 // value types used by messages
37 template <> struct ParameterType< Dali::Camera::Type >
38 : public BasicType< Dali::Camera::Type > {};
39 template <> struct ParameterType< Dali::Camera::ProjectionMode >
40 : public BasicType< Dali::Camera::ProjectionMode > {};
45 class RenderableAttachment;
46 class SceneController;
49 * An attachment for camera objects and their properties.
51 class CameraAttachment : public NodeAttachment
54 static const Dali::Camera::Type DEFAULT_TYPE;
55 static const Dali::Camera::ProjectionMode DEFAULT_MODE;
56 static const bool DEFAULT_INVERT_Y_AXIS;
57 static const float DEFAULT_FIELD_OF_VIEW;
58 static const float DEFAULT_ASPECT_RATIO;
59 static const float DEFAULT_LEFT_CLIPPING_PLANE;
60 static const float DEFAULT_RIGHT_CLIPPING_PLANE;
61 static const float DEFAULT_TOP_CLIPPING_PLANE;
62 static const float DEFAULT_BOTTOM_CLIPPING_PLANE;
63 static const float DEFAULT_NEAR_CLIPPING_PLANE;
64 static const float DEFAULT_FAR_CLIPPING_PLANE;
65 static const Vector3 DEFAULT_TARGET_POSITION;
68 * Construct a new CameraAttachment.
69 * @return a new camera.
71 static CameraAttachment* New();
74 * @copydoc NodeAttachment::ConnectToSceneGraph().
76 virtual void ConnectToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex );
79 * @copydoc NodeAttachment::OnDestroy().
81 virtual void OnDestroy();
86 virtual ~CameraAttachment();
89 * @copydoc NodeAttachment::GetRenderable.
90 * @return Always NULL.
92 virtual RenderableAttachment* GetRenderable();
95 * @copydoc Dali::Internal::CameraAttachment::SetType
97 void SetType( Dali::Camera::Type type );
100 * @copydoc Dali::Internal::CameraAttachment::SetInvertYAxis
102 void SetInvertYAxis( bool invertYAxis );
105 * @copydoc Dali::Internal::CameraAttachment::SetProjectionMode
107 void SetProjectionMode( Dali::Camera::ProjectionMode projectionMode );
110 * @copydoc Dali::Internal::CameraAttachment::SetFieldOfView
112 void SetFieldOfView( float fieldOfView );
115 * @copydoc Dali::Internal::CameraAttachment::SetAspectRatio
117 void SetAspectRatio( float aspectRatio );
120 * @copydoc Dali::Internal::CameraAttachment::SetLeftClippingPlane
122 void SetLeftClippingPlane( float leftClippingPlane );
125 * @copydoc Dali::Internal::CameraAttachment::SetRightClippingPlane
127 void SetRightClippingPlane( float rightClippingPlane );
130 * @copydoc Dali::Internal::CameraAttachment::SetTopClippingPlane
132 void SetTopClippingPlane( float topClippingPlane );
135 * @copydoc Dali::Internal::CameraAttachment::SetBottomClippingPlane
137 void SetBottomClippingPlane( float bottomClippingPlane );
140 * @copydoc Dali::Internal::CameraAttachment::SetNearClippingPlane
142 void SetNearClippingPlane( float nearClippingPlane );
145 * @copydoc Dali::Internal::CameraAttachment::SetFarClippingPlane
147 void SetFarClippingPlane( float farClippingPlane );
150 * @copydoc Dali::Internal::CameraAttachment::SetTarget
152 void SetTargetPosition( const Vector3& targetPosition );
157 Vector3 GetTargetPosition() const;
160 * Retrieve the view-matrix; this is double buffered for input handling.
161 * @param[in] bufferIndex The buffer to read from.
162 * @return The view-matrix.
164 const Matrix& GetViewMatrix( BufferIndex bufferIndex ) const;
167 * Retrieve the projection-matrix; this is double buffered for input handling.
168 * @param[in] bufferIndex The buffer to read from.
169 * @return The projection-matrix.
171 const Matrix& GetProjectionMatrix( BufferIndex bufferIndex ) const;
174 * Retrieve the inverted view-projection-matrix; this is double buffered for input handling.
175 * @param[in] bufferIndex The buffer to read from.
176 * @return The inverse view-projection-matrix.
178 const Matrix& GetInverseViewProjectionMatrix( BufferIndex bufferIndex ) const;
181 * Retrieve the projection-matrix property querying interface.
182 * @pre The attachment is on-stage.
183 * @return The projection-matrix property querying interface.
185 const PropertyInputImpl* GetProjectionMatrix() const;
188 * Retrieve the view-matrix property querying interface.
189 * @pre The attachment is on-stage.
190 * @return The view-matrix property querying interface.
192 const PropertyInputImpl* GetViewMatrix() const;
195 * @copydoc NodeAttachment::Update
197 virtual void Update( BufferIndex updateBufferIndex, const Node& owningNode, int nodeDirtyFlags );
200 * @return true if the view matrix of camera is updated this or the previous frame
202 bool ViewMatrixUpdated();
207 * Protected constructor, see New().
214 CameraAttachment(const CameraAttachment&);
217 CameraAttachment& operator=(const CameraAttachment& rhs);
220 * Recalculates the view & projection matrices.
221 * @param[in] bufferIndex The current update buffer index.
223 void UpdateProjection( BufferIndex updateBufferIndex );
226 * Recalculates the inverse modelview matrix, which is used for hit testing
227 * @param[in] updateBufferIndex The current update buffer index.
229 void UpdateInverseViewProjection( BufferIndex updateBufferIndex );
232 unsigned int mUpdateViewFlag; ///< This is non-zero if the view matrix requires an update
233 unsigned int mUpdateProjectionFlag; ///< This is non-zero if the projection matrix requires an update
235 public: // PROPERTIES
236 Dali::Camera::Type mType; // Non-animatable
237 Dali::Camera::ProjectionMode mProjectionMode; // Non-animatable
238 bool mInvertYAxis; // Non-animatable
242 float mLeftClippingPlane;
243 float mRightClippingPlane;
244 float mTopClippingPlane;
245 float mBottomClippingPlane;
246 float mNearClippingPlane;
247 float mFarClippingPlane;
248 Vector3 mTargetPosition;
250 InheritedProperty<Matrix> mViewMatrix; ///< The view-matrix; this is double buffered for input handling.
251 InheritedProperty<Matrix> mProjectionMatrix; ///< The projection-matrix; this is double buffered for input handling.
253 DoubleBuffered< Matrix > mInverseViewProjection;///< Inverted viewprojection; double buffered for input handling
257 // Messages for CameraAttachment
259 inline void SetTypeMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, Dali::Camera::Type parameter )
261 typedef MessageValue1< CameraAttachment, Dali::Camera::Type > LocalType;
263 // Reserve some memory inside the message queue
264 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
266 // Construct message in the message queue memory; note that delete should not be called on the return value
267 new (slot) LocalType( &attachment, &CameraAttachment::SetType, parameter );
270 inline void SetProjectionModeMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, Dali::Camera::ProjectionMode parameter )
272 typedef MessageValue1< CameraAttachment, Dali::Camera::ProjectionMode > LocalProjectionMode;
274 // Reserve some memory inside the message queue
275 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalProjectionMode ) );
277 // Construct message in the message queue memory; note that delete should not be called on the return value
278 new (slot) LocalProjectionMode( &attachment, &CameraAttachment::SetProjectionMode, parameter );
282 inline void SetFieldOfViewMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
284 typedef MessageValue1< CameraAttachment, float > LocalType;
286 // Reserve some memory inside the message queue
287 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
289 // Construct message in the message queue memory; note that delete should not be called on the return value
290 new (slot) LocalType( &attachment, &CameraAttachment::SetFieldOfView, parameter );
293 inline void SetAspectRatioMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
295 typedef MessageValue1< CameraAttachment, float > LocalType;
297 // Reserve some memory inside the message queue
298 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
300 // Construct message in the message queue memory; note that delete should not be called on the return value
301 new (slot) LocalType( &attachment, &CameraAttachment::SetAspectRatio, parameter );
304 inline void SetLeftClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
306 typedef MessageValue1< CameraAttachment, float > LocalType;
308 // Reserve some memory inside the message queue
309 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
311 // Construct message in the message queue memory; note that delete should not be called on the return value
312 new (slot) LocalType( &attachment, &CameraAttachment::SetLeftClippingPlane, parameter );
315 inline void SetRightClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
317 typedef MessageValue1< CameraAttachment, float > LocalType;
319 // Reserve some memory inside the message queue
320 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
322 // Construct message in the message queue memory; note that delete should not be called on the return value
323 new (slot) LocalType( &attachment, &CameraAttachment::SetRightClippingPlane, parameter );
326 inline void SetTopClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
328 typedef MessageValue1< CameraAttachment, float > LocalType;
330 // Reserve some memory inside the message queue
331 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
333 // Construct message in the message queue memory; note that delete should not be called on the return value
334 new (slot) LocalType( &attachment, &CameraAttachment::SetTopClippingPlane, parameter );
337 inline void SetBottomClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
339 typedef MessageValue1< CameraAttachment, float > LocalType;
341 // Reserve some memory inside the message queue
342 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
344 // Construct message in the message queue memory; note that delete should not be called on the return value
345 new (slot) LocalType( &attachment, &CameraAttachment::SetBottomClippingPlane, parameter );
348 inline void SetNearClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
350 typedef MessageValue1< CameraAttachment, float > LocalType;
352 // Reserve some memory inside the message queue
353 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
355 // Construct message in the message queue memory; note that delete should not be called on the return value
356 new (slot) LocalType( &attachment, &CameraAttachment::SetNearClippingPlane, parameter );
359 inline void SetFarClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
361 typedef MessageValue1< CameraAttachment, float > LocalType;
363 // Reserve some memory inside the message queue
364 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
366 // Construct message in the message queue memory; note that delete should not be called on the return value
367 new (slot) LocalType( &attachment, &CameraAttachment::SetFarClippingPlane, parameter );
370 inline void SetTargetPositionMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, const Vector3& parameter )
372 typedef MessageValue1< CameraAttachment, Vector3 > LocalType;
374 // Reserve some memory inside the message queue
375 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
377 // Construct message in the message queue memory; note that delete should not be called on the return value
378 new (slot) LocalType( &attachment, &CameraAttachment::SetTargetPosition, parameter );
382 inline void SetInvertYAxisMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, bool parameter )
384 typedef MessageValue1< CameraAttachment, bool > LocalType;
386 // Reserve some memory inside the message queue
387 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
389 // Construct message in the message queue memory; note that delete should not be called on the return value
390 new (slot) LocalType( &attachment, &CameraAttachment::SetInvertYAxis, parameter );
394 } // namespace SceneGraph
396 } // namespace Internal
400 #endif // __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__