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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/math/rect.h>
23 #include <dali/public-api/actors/camera-actor.h>
24 #include <dali/internal/common/message.h>
25 #include <dali/internal/common/event-to-update.h>
26 #include <dali/internal/update/common/double-buffered.h>
27 #include <dali/internal/update/node-attachments/node-attachment.h>
28 #include <dali/internal/update/common/animatable-property.h>
29 #include <dali/internal/update/common/inherited-property.h>
37 // value types used by messages
38 template <> struct ParameterType< Dali::Camera::Type >
39 : public BasicType< Dali::Camera::Type > {};
40 template <> struct ParameterType< Dali::Camera::ProjectionMode >
41 : public BasicType< Dali::Camera::ProjectionMode > {};
46 class RenderableAttachment;
47 class SceneController;
50 * An attachment for camera objects and their properties.
52 class CameraAttachment : public NodeAttachment
55 static const Dali::Camera::Type DEFAULT_TYPE;
56 static const Dali::Camera::ProjectionMode DEFAULT_MODE;
57 static const bool DEFAULT_INVERT_Y_AXIS;
58 static const float DEFAULT_FIELD_OF_VIEW;
59 static const float DEFAULT_ASPECT_RATIO;
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 Vector2 DEFAULT_STEREO_BIAS;
67 static const Vector3 DEFAULT_TARGET_POSITION;
70 * Construct a new CameraAttachment.
71 * @return a new camera.
73 static CameraAttachment* New();
76 * @copydoc NodeAttachment::ConnectToSceneGraph().
78 virtual void ConnectToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex );
81 * @copydoc NodeAttachment::OnDestroy().
83 virtual void OnDestroy();
88 virtual ~CameraAttachment();
91 * @copydoc NodeAttachment::GetRenderable.
92 * @return Always NULL.
94 virtual RenderableAttachment* GetRenderable();
97 * @copydoc Dali::Internal::CameraAttachment::SetType
99 void SetType( Dali::Camera::Type type );
102 * @copydoc Dali::Internal::CameraAttachment::SetInvertYAxis
104 void SetInvertYAxis( bool invertYAxis );
107 * @copydoc Dali::Internal::CameraAttachment::SetProjectionMode
109 void SetProjectionMode( Dali::Camera::ProjectionMode projectionMode );
112 * @copydoc Dali::Internal::CameraAttachment::SetFieldOfView
114 void SetFieldOfView( float fieldOfView );
117 * @copydoc Dali::Internal::CameraAttachment::SetAspectRatio
119 void SetAspectRatio( float aspectRatio );
122 * @copydoc Dali::Internal::CameraAttachment::SetStereoBias
124 void SetStereoBias(const Vector2& stereoBias);
127 * @copydoc Dali::Internal::CameraAttachment::SetLeftClippingPlane
129 void SetLeftClippingPlane( float leftClippingPlane );
132 * @copydoc Dali::Internal::CameraAttachment::SetRightClippingPlane
134 void SetRightClippingPlane( float rightClippingPlane );
137 * @copydoc Dali::Internal::CameraAttachment::SetTopClippingPlane
139 void SetTopClippingPlane( float topClippingPlane );
142 * @copydoc Dali::Internal::CameraAttachment::SetBottomClippingPlane
144 void SetBottomClippingPlane( float bottomClippingPlane );
147 * @copydoc Dali::Internal::CameraAttachment::SetNearClippingPlane
149 void SetNearClippingPlane( float nearClippingPlane );
152 * @copydoc Dali::Internal::CameraAttachment::SetFarClippingPlane
154 void SetFarClippingPlane( float farClippingPlane );
157 * @copydoc Dali::Internal::CameraAttachment::SetTarget
159 void SetTargetPosition( const Vector3& targetPosition );
164 Vector3 GetTargetPosition() const;
167 * Retrieve the view-matrix; this is double buffered for input handling.
168 * @param[in] bufferIndex The buffer to read from.
169 * @return The view-matrix.
171 const Matrix& GetViewMatrix( BufferIndex bufferIndex ) const;
174 * Retrieve the projection-matrix; this is double buffered for input handling.
175 * @param[in] bufferIndex The buffer to read from.
176 * @return The projection-matrix.
178 const Matrix& GetProjectionMatrix( BufferIndex bufferIndex ) const;
181 * Retrieve the inverted view-projection-matrix; this is double buffered for input handling.
182 * @param[in] bufferIndex The buffer to read from.
183 * @return The inverse view-projection-matrix.
185 const Matrix& GetInverseViewProjectionMatrix( BufferIndex bufferIndex ) const;
188 * Retrieve the projection-matrix property querying interface.
189 * @pre The attachment is on-stage.
190 * @return The projection-matrix property querying interface.
192 const PropertyInputImpl* GetProjectionMatrix() const;
195 * Retrieve the view-matrix property querying interface.
196 * @pre The attachment is on-stage.
197 * @return The view-matrix property querying interface.
199 const PropertyInputImpl* GetViewMatrix() const;
202 * @copydoc NodeAttachment::Update
204 virtual void Update( BufferIndex updateBufferIndex, const Node& owningNode, int nodeDirtyFlags );
207 * @return true if the view matrix of camera is updated this or the previous frame
209 bool ViewMatrixUpdated();
214 * Protected constructor, see New().
221 CameraAttachment(const CameraAttachment&);
224 CameraAttachment& operator=(const CameraAttachment& rhs);
227 * Recalculates the view & projection matrices.
228 * @param[in] bufferIndex The current update buffer index.
230 void UpdateProjection( BufferIndex updateBufferIndex );
233 * Recalculates the inverse modelview matrix, which is used for hit testing
234 * @param[in] updateBufferIndex The current update buffer index.
236 void UpdateInverseViewProjection( BufferIndex updateBufferIndex );
239 unsigned int mUpdateViewFlag; ///< This is non-zero if the view matrix requires an update
240 unsigned int mUpdateProjectionFlag; ///< This is non-zero if the projection matrix requires an update
242 public: // PROPERTIES
243 Dali::Camera::Type mType; // Non-animatable
244 Dali::Camera::ProjectionMode mProjectionMode; // Non-animatable
245 bool mInvertYAxis; // Non-animatable
249 float mLeftClippingPlane;
250 float mRightClippingPlane;
251 float mTopClippingPlane;
252 float mBottomClippingPlane;
253 float mNearClippingPlane;
254 float mFarClippingPlane;
256 Vector3 mTargetPosition;
258 InheritedProperty<Matrix> mViewMatrix; ///< The view-matrix; this is double buffered for input handling.
259 InheritedProperty<Matrix> mProjectionMatrix; ///< The projection-matrix; this is double buffered for input handling.
261 DoubleBuffered< Matrix > mInverseViewProjection;///< Inverted viewprojection; double buffered for input handling
265 // Messages for CameraAttachment
267 inline void SetTypeMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, Dali::Camera::Type parameter )
269 typedef MessageValue1< CameraAttachment, Dali::Camera::Type > LocalType;
271 // Reserve some memory inside the message queue
272 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
274 // Construct message in the message queue memory; note that delete should not be called on the return value
275 new (slot) LocalType( &attachment, &CameraAttachment::SetType, parameter );
278 inline void SetProjectionModeMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, Dali::Camera::ProjectionMode parameter )
280 typedef MessageValue1< CameraAttachment, Dali::Camera::ProjectionMode > LocalProjectionMode;
282 // Reserve some memory inside the message queue
283 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalProjectionMode ) );
285 // Construct message in the message queue memory; note that delete should not be called on the return value
286 new (slot) LocalProjectionMode( &attachment, &CameraAttachment::SetProjectionMode, parameter );
290 inline void SetFieldOfViewMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
292 typedef MessageValue1< CameraAttachment, float > LocalType;
294 // Reserve some memory inside the message queue
295 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
297 // Construct message in the message queue memory; note that delete should not be called on the return value
298 new (slot) LocalType( &attachment, &CameraAttachment::SetFieldOfView, parameter );
301 inline void SetAspectRatioMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
303 typedef MessageValue1< CameraAttachment, float > LocalType;
305 // Reserve some memory inside the message queue
306 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
308 // Construct message in the message queue memory; note that delete should not be called on the return value
309 new (slot) LocalType( &attachment, &CameraAttachment::SetAspectRatio, parameter );
312 inline void SetStereoBiasMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, const Vector2& parameter )
314 typedef MessageValue1< CameraAttachment, Vector2 > LocalType;
316 // Reserve some memory inside the message queue
317 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
319 // Construct message in the message queue memory; note that delete should not be called on the return value
320 new (slot) LocalType( &attachment, &CameraAttachment::SetStereoBias, parameter );
323 inline void SetLeftClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
325 typedef MessageValue1< CameraAttachment, float > LocalType;
327 // Reserve some memory inside the message queue
328 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
330 // Construct message in the message queue memory; note that delete should not be called on the return value
331 new (slot) LocalType( &attachment, &CameraAttachment::SetLeftClippingPlane, parameter );
334 inline void SetRightClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
336 typedef MessageValue1< CameraAttachment, float > LocalType;
338 // Reserve some memory inside the message queue
339 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
341 // Construct message in the message queue memory; note that delete should not be called on the return value
342 new (slot) LocalType( &attachment, &CameraAttachment::SetRightClippingPlane, parameter );
345 inline void SetTopClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
347 typedef MessageValue1< CameraAttachment, float > LocalType;
349 // Reserve some memory inside the message queue
350 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
352 // Construct message in the message queue memory; note that delete should not be called on the return value
353 new (slot) LocalType( &attachment, &CameraAttachment::SetTopClippingPlane, parameter );
356 inline void SetBottomClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
358 typedef MessageValue1< CameraAttachment, float > LocalType;
360 // Reserve some memory inside the message queue
361 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
363 // Construct message in the message queue memory; note that delete should not be called on the return value
364 new (slot) LocalType( &attachment, &CameraAttachment::SetBottomClippingPlane, parameter );
367 inline void SetNearClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
369 typedef MessageValue1< CameraAttachment, float > LocalType;
371 // Reserve some memory inside the message queue
372 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
374 // Construct message in the message queue memory; note that delete should not be called on the return value
375 new (slot) LocalType( &attachment, &CameraAttachment::SetNearClippingPlane, parameter );
378 inline void SetFarClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
380 typedef MessageValue1< CameraAttachment, float > LocalType;
382 // Reserve some memory inside the message queue
383 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
385 // Construct message in the message queue memory; note that delete should not be called on the return value
386 new (slot) LocalType( &attachment, &CameraAttachment::SetFarClippingPlane, parameter );
389 inline void SetTargetPositionMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, const Vector3& parameter )
391 typedef MessageValue1< CameraAttachment, Vector3 > LocalType;
393 // Reserve some memory inside the message queue
394 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
396 // Construct message in the message queue memory; note that delete should not be called on the return value
397 new (slot) LocalType( &attachment, &CameraAttachment::SetTargetPosition, parameter );
401 inline void SetInvertYAxisMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, bool parameter )
403 typedef MessageValue1< CameraAttachment, bool > LocalType;
405 // Reserve some memory inside the message queue
406 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
408 // Construct message in the message queue memory; note that delete should not be called on the return value
409 new (slot) LocalType( &attachment, &CameraAttachment::SetInvertYAxis, parameter );
413 } // namespace SceneGraph
415 } // namespace Internal
419 #endif // __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__