3cd8d599ff20e250174063a12dece11e63f600f9
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / camera-actor-impl.h
1 #ifndef __DALI_INTERNAL_CAMERA_ACTOR_H__
2 #define __DALI_INTERNAL_CAMERA_ACTOR_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUES
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/public-api/actors/camera-actor.h>
24 #include <dali/internal/event/actors/actor-impl.h>
25 #include <dali/internal/event/actors/actor-declarations.h>
26 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 /**
35  * An actor with a conveniently pre-attached CameraAttachment.
36  */
37 class CameraActor : public Actor
38 {
39 public:
40
41   /**
42    * Create an initialised camera actor.
43    *
44    * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
45    *
46    * @param[in] size The canvas size.
47    *
48    * @return A smart-pointer to a newly allocated camera actor.
49    */
50   static CameraActorPtr New( const Size& size );
51
52   /**
53    * @copydoc Dali::Actor::OnInitialize
54    */
55   void OnInitialize();
56
57   /**
58    * Retrieve the camera attachment.
59    * @return The attachment.
60    */
61   CameraAttachment& GetCameraAttachment()
62   {
63     return *mCameraAttachment;
64   }
65
66   /**
67    * @copydoc Dali::CameraActor::SetType
68    */
69   void SetType( Dali::Camera::Type type );
70
71   /**
72    * @copydoc Dali::CameraActor::GetType
73    */
74   Dali::Camera::Type GetType() const;
75
76   /**
77    * @copydoc Dali::CameraActor::SetProjectionMode
78    */
79   void SetProjectionMode( Dali::Camera::ProjectionMode mode );
80
81   /**
82    * @copydoc Dali::CameraActor::GetProjectionMode
83    */
84   Dali::Camera::ProjectionMode GetProjectionMode() const;
85
86   /**
87    * @copydoc Dali::CameraActor::SetFieldOfView
88    */
89   void SetFieldOfView( float fieldOfView );
90
91   /**
92    * @copydoc Dali::CameraActor::GetFieldOfView
93    */
94   float GetFieldOfView( ) const;
95
96   /**
97    * @copydoc Dali::CameraActor::SetAspectRatio
98    */
99   void SetAspectRatio( float aspectRatio );
100
101   /**
102    * @copydoc Dali::CameraActor::GetAspectRatio
103    */
104   float GetAspectRatio( ) const;
105
106   /**
107    * @copydoc Dali::CameraActor::SetNearClippingPlane
108    */
109   void SetNearClippingPlane( float nearClippingPlane );
110
111   /**
112    * @copydoc Dali::CameraActor::GetNearClippingPlane
113    */
114   float GetNearClippingPlane( ) const;
115
116   /**
117    * @copydoc Dali::CameraActor::SetFarClippingPlane
118    */
119   void SetFarClippingPlane( float farClippingPlane );
120
121   /**
122    * @copydoc Dali::CameraActor::GetFarClippingPlane
123    */
124   float GetFarClippingPlane( ) const;
125
126   /**
127    * @copydoc Dali::CameraActor::SetTargetPosition
128    */
129   void SetTargetPosition( const Vector3& targetPosition );
130
131   /**
132    * @copydoc Dali::CameraActor::GetTargetPosition
133    */
134   Vector3 GetTargetPosition() const;
135
136   /**
137    * @copydoc Dali::CameraActor::SetInvertYAxis
138    */
139   void SetInvertYAxis(bool invertYAxis);
140
141   /**
142    * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
143    */
144   bool GetInvertYAxis() const;
145
146   /**
147    * @copydoc Dali::CameraActor::SetPerspectiveProjection()
148    * @param[in] stereoBias The frustum horizontal and vertical offset for stereoscopic cameras
149    */
150   void SetPerspectiveProjection( const Size& size, const Vector2& stereoBias = Vector2::ZERO );
151
152   /**
153    * @copydoc Dali::CameraActor::SetOrthographicProjection(const Vector2& size);
154    */
155   void SetOrthographicProjection( const Vector2& size );
156
157   /**
158    * @copydoc Dali::CameraActor::SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
159    */
160   void SetOrthographicProjection( float left, float right, float top, float bottom, float near, float far );
161
162   /**
163    * Build a picking ray with this camera and given screen coordinates
164    * @param [in] screenCoordinates the ray passed through
165    * @param [in] viewport to use
166    * @param [out] rayOrigin for the picking ray
167    * @param [out] rayDirection for the picking ray
168    * @return true if the building was successful, false if its not possible (camera is not valid for hit testing)
169    */
170   bool BuildPickingRay( const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection );
171
172   /**
173    * Retrieve the view-matrix; This will only be valid when the actor is on-stage.
174    * @return The view-matrix.
175    */
176   const Matrix& GetViewMatrix() const;
177
178   /**
179    * Retrieve the projection-matrix; This will only be valid when the actor is on-stage.
180    * @return The projection-matrix.
181    */
182   const Matrix& GetProjectionMatrix() const;
183
184 public: // properties
185
186   /**
187    * copydoc Dali::Internal::Object
188    */
189   virtual unsigned int GetDefaultPropertyCount() const;
190
191   /**
192    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
193    */
194   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
195
196   /**
197    * copydoc Dali::Internal::Object
198    */
199   virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
200
201   /**
202    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
203    */
204   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
205
206   /**
207    * copydoc Dali::Internal::Object
208    */
209   virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
210
211   /**
212    * copydoc Dali::Internal::Object
213    */
214   virtual const char* GetDefaultPropertyName( Property::Index index ) const;
215
216   /**
217    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
218    */
219   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
220
221   /**
222    * copydoc Dali::Internal::Object
223    */
224   virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
225
226   /**
227    * copydoc Dali::Internal::Object
228    */
229   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
230
231   /**
232    * copydoc Dali::Internal::Object
233    */
234   virtual bool IsDefaultPropertyWritable( Property::Index index ) const ;
235
236   /**
237    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
238    */
239   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
240
241   /**
242    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
243    */
244   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
245
246 protected:
247
248   /**
249    * Protected constructor; see also CameraActor::New()
250    */
251   CameraActor();
252
253   /**
254    * A reference counted object may only be deleted by calling Unreference()
255    */
256   virtual ~CameraActor();
257
258 private:
259
260   CameraAttachmentPtr mCameraAttachment;
261
262 };
263
264 } // namespace Internal
265
266 // Helpers for public-api forwarding methods
267
268 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
269 {
270   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
271
272   BaseObject& handle = camera.GetBaseObject();
273
274   return static_cast<Internal::CameraActor&>(handle);
275 }
276
277 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
278 {
279   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
280
281   const BaseObject& handle = camera.GetBaseObject();
282
283   return static_cast<const Internal::CameraActor&>(handle);
284 }
285
286 } // namespace Dali
287
288 #endif // __DALI_INTERNAL_CAMERA_ACTOR_H__