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_STEREO_BIAS;
60 static const float DEFAULT_LEFT_CLIPPING_PLANE;
61 static const float DEFAULT_RIGHT_CLIPPING_PLANE;
62 static const float DEFAULT_TOP_CLIPPING_PLANE;
63 static const float DEFAULT_BOTTOM_CLIPPING_PLANE;
64 static const float DEFAULT_NEAR_CLIPPING_PLANE;
65 static const float DEFAULT_FAR_CLIPPING_PLANE;
66 static const Vector3 DEFAULT_TARGET_POSITION;
69 * Construct a new CameraAttachment.
70 * @return a new camera.
72 static CameraAttachment* New();
75 * @copydoc NodeAttachment::ConnectToSceneGraph().
77 virtual void ConnectToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex );
80 * @copydoc NodeAttachment::OnDestroy().
82 virtual void OnDestroy();
87 virtual ~CameraAttachment();
90 * @copydoc NodeAttachment::GetRenderable.
91 * @return Always NULL.
93 virtual RenderableAttachment* GetRenderable();
96 * @copydoc Dali::Internal::CameraAttachment::SetType
98 void SetType( Dali::Camera::Type type );
101 * @copydoc Dali::Internal::CameraAttachment::SetInvertYAxis
103 void SetInvertYAxis( bool invertYAxis );
106 * @copydoc Dali::Internal::CameraAttachment::SetProjectionMode
108 void SetProjectionMode( Dali::Camera::ProjectionMode projectionMode );
111 * @copydoc Dali::Internal::CameraAttachment::SetFieldOfView
113 void SetFieldOfView( float fieldOfView );
116 * @copydoc Dali::Internal::CameraAttachment::SetAspectRatio
118 void SetAspectRatio( float aspectRatio );
121 * @copydoc Dali::Internal::CameraAttachment::SetStereoBias
123 void SetStereoBias(float stereoBias);
126 * @copydoc Dali::Internal::CameraAttachment::SetLeftClippingPlane
128 void SetLeftClippingPlane( float leftClippingPlane );
131 * @copydoc Dali::Internal::CameraAttachment::SetRightClippingPlane
133 void SetRightClippingPlane( float rightClippingPlane );
136 * @copydoc Dali::Internal::CameraAttachment::SetTopClippingPlane
138 void SetTopClippingPlane( float topClippingPlane );
141 * @copydoc Dali::Internal::CameraAttachment::SetBottomClippingPlane
143 void SetBottomClippingPlane( float bottomClippingPlane );
146 * @copydoc Dali::Internal::CameraAttachment::SetNearClippingPlane
148 void SetNearClippingPlane( float nearClippingPlane );
151 * @copydoc Dali::Internal::CameraAttachment::SetFarClippingPlane
153 void SetFarClippingPlane( float farClippingPlane );
156 * @copydoc Dali::Internal::CameraAttachment::SetTarget
158 void SetTargetPosition( const Vector3& targetPosition );
163 Vector3 GetTargetPosition() const;
166 * Retrieve the view-matrix; this is double buffered for input handling.
167 * @param[in] bufferIndex The buffer to read from.
168 * @return The view-matrix.
170 const Matrix& GetViewMatrix( BufferIndex bufferIndex ) const;
173 * Retrieve the projection-matrix; this is double buffered for input handling.
174 * @param[in] bufferIndex The buffer to read from.
175 * @return The projection-matrix.
177 const Matrix& GetProjectionMatrix( BufferIndex bufferIndex ) const;
180 * Retrieve the inverted view-projection-matrix; this is double buffered for input handling.
181 * @param[in] bufferIndex The buffer to read from.
182 * @return The inverse view-projection-matrix.
184 const Matrix& GetInverseViewProjectionMatrix( BufferIndex bufferIndex ) const;
187 * Retrieve the projection-matrix property querying interface.
188 * @pre The attachment is on-stage.
189 * @return The projection-matrix property querying interface.
191 const PropertyInputImpl* GetProjectionMatrix() const;
194 * Retrieve the view-matrix property querying interface.
195 * @pre The attachment is on-stage.
196 * @return The view-matrix property querying interface.
198 const PropertyInputImpl* GetViewMatrix() const;
201 * @copydoc NodeAttachment::Update
203 virtual void Update( BufferIndex updateBufferIndex, const Node& owningNode, int nodeDirtyFlags );
206 * @return true if the view matrix of camera is updated this or the previous frame
208 bool ViewMatrixUpdated();
213 * Protected constructor, see New().
220 CameraAttachment(const CameraAttachment&);
223 CameraAttachment& operator=(const CameraAttachment& rhs);
226 * Recalculates the view & projection matrices.
227 * @param[in] bufferIndex The current update buffer index.
229 void UpdateProjection( BufferIndex updateBufferIndex );
232 * Recalculates the inverse modelview matrix, which is used for hit testing
233 * @param[in] updateBufferIndex The current update buffer index.
235 void UpdateInverseViewProjection( BufferIndex updateBufferIndex );
238 unsigned int mUpdateViewFlag; ///< This is non-zero if the view matrix requires an update
239 unsigned int mUpdateProjectionFlag; ///< This is non-zero if the projection matrix requires an update
241 public: // PROPERTIES
242 Dali::Camera::Type mType; // Non-animatable
243 Dali::Camera::ProjectionMode mProjectionMode; // Non-animatable
244 bool mInvertYAxis; // Non-animatable
249 float mLeftClippingPlane;
250 float mRightClippingPlane;
251 float mTopClippingPlane;
252 float mBottomClippingPlane;
253 float mNearClippingPlane;
254 float mFarClippingPlane;
255 Vector3 mTargetPosition;
257 InheritedProperty<Matrix> mViewMatrix; ///< The view-matrix; this is double buffered for input handling.
258 InheritedProperty<Matrix> mProjectionMatrix; ///< The projection-matrix; this is double buffered for input handling.
260 DoubleBuffered< Matrix > mInverseViewProjection;///< Inverted viewprojection; double buffered for input handling
264 // Messages for CameraAttachment
266 inline void SetTypeMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, Dali::Camera::Type parameter )
268 typedef MessageValue1< CameraAttachment, Dali::Camera::Type > LocalType;
270 // Reserve some memory inside the message queue
271 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
273 // Construct message in the message queue memory; note that delete should not be called on the return value
274 new (slot) LocalType( &attachment, &CameraAttachment::SetType, parameter );
277 inline void SetProjectionModeMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, Dali::Camera::ProjectionMode parameter )
279 typedef MessageValue1< CameraAttachment, Dali::Camera::ProjectionMode > LocalProjectionMode;
281 // Reserve some memory inside the message queue
282 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalProjectionMode ) );
284 // Construct message in the message queue memory; note that delete should not be called on the return value
285 new (slot) LocalProjectionMode( &attachment, &CameraAttachment::SetProjectionMode, parameter );
289 inline void SetFieldOfViewMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
291 typedef MessageValue1< CameraAttachment, float > LocalType;
293 // Reserve some memory inside the message queue
294 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
296 // Construct message in the message queue memory; note that delete should not be called on the return value
297 new (slot) LocalType( &attachment, &CameraAttachment::SetFieldOfView, parameter );
300 inline void SetAspectRatioMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
302 typedef MessageValue1< CameraAttachment, float > LocalType;
304 // Reserve some memory inside the message queue
305 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
307 // Construct message in the message queue memory; note that delete should not be called on the return value
308 new (slot) LocalType( &attachment, &CameraAttachment::SetAspectRatio, parameter );
311 inline void SetStereoBiasMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
313 typedef MessageValue1< CameraAttachment, float > LocalType;
315 // Reserve some memory inside the message queue
316 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
318 // Construct message in the message queue memory; note that delete should not be called on the return value
319 new (slot) LocalType( &attachment, &CameraAttachment::SetStereoBias, parameter );
322 inline void SetLeftClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
324 typedef MessageValue1< CameraAttachment, float > LocalType;
326 // Reserve some memory inside the message queue
327 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
329 // Construct message in the message queue memory; note that delete should not be called on the return value
330 new (slot) LocalType( &attachment, &CameraAttachment::SetLeftClippingPlane, parameter );
333 inline void SetRightClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
335 typedef MessageValue1< CameraAttachment, float > LocalType;
337 // Reserve some memory inside the message queue
338 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
340 // Construct message in the message queue memory; note that delete should not be called on the return value
341 new (slot) LocalType( &attachment, &CameraAttachment::SetRightClippingPlane, parameter );
344 inline void SetTopClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
346 typedef MessageValue1< CameraAttachment, float > LocalType;
348 // Reserve some memory inside the message queue
349 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
351 // Construct message in the message queue memory; note that delete should not be called on the return value
352 new (slot) LocalType( &attachment, &CameraAttachment::SetTopClippingPlane, parameter );
355 inline void SetBottomClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
357 typedef MessageValue1< CameraAttachment, float > LocalType;
359 // Reserve some memory inside the message queue
360 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
362 // Construct message in the message queue memory; note that delete should not be called on the return value
363 new (slot) LocalType( &attachment, &CameraAttachment::SetBottomClippingPlane, parameter );
366 inline void SetNearClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
368 typedef MessageValue1< CameraAttachment, float > LocalType;
370 // Reserve some memory inside the message queue
371 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
373 // Construct message in the message queue memory; note that delete should not be called on the return value
374 new (slot) LocalType( &attachment, &CameraAttachment::SetNearClippingPlane, parameter );
377 inline void SetFarClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
379 typedef MessageValue1< CameraAttachment, float > LocalType;
381 // Reserve some memory inside the message queue
382 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
384 // Construct message in the message queue memory; note that delete should not be called on the return value
385 new (slot) LocalType( &attachment, &CameraAttachment::SetFarClippingPlane, parameter );
388 inline void SetTargetPositionMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, const Vector3& parameter )
390 typedef MessageValue1< CameraAttachment, Vector3 > LocalType;
392 // Reserve some memory inside the message queue
393 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
395 // Construct message in the message queue memory; note that delete should not be called on the return value
396 new (slot) LocalType( &attachment, &CameraAttachment::SetTargetPosition, parameter );
400 inline void SetInvertYAxisMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, bool parameter )
402 typedef MessageValue1< CameraAttachment, bool > LocalType;
404 // Reserve some memory inside the message queue
405 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
407 // Construct message in the message queue memory; note that delete should not be called on the return value
408 new (slot) LocalType( &attachment, &CameraAttachment::SetInvertYAxis, parameter );
412 } // namespace SceneGraph
414 } // namespace Internal
418 #endif // __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__