DALi Version 1.4.8
[platform/core/uifw/dali-core.git] / dali / public-api / actors / camera-actor.h
1 #ifndef __DALI_CAMERA_ACTOR_H__
2 #define __DALI_CAMERA_ACTOR_H__
3
4 /*
5  * Copyright (c) 2018 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 #include <dali/public-api/actors/actor.h>
22
23 namespace Dali
24 {
25 /**
26  * @addtogroup dali_core_actors
27  * @{
28  */
29
30 namespace Internal DALI_INTERNAL
31 {
32 class CameraActor;
33 }
34
35 /**
36  * @brief Enumeration for camera.
37  * @SINCE_1_0.0
38  */
39 namespace Camera
40 {
41 /**
42  * @brief Enumeration for type determination of how camera operates.
43  * @SINCE_1_0.0
44  */
45 enum Type
46 {
47   FREE_LOOK,      ///< Camera orientation is taken from CameraActor @SINCE_1_0.0
48   LOOK_AT_TARGET, ///< Camera is oriented to always look at a target @SINCE_1_0.0
49 };
50
51 /**
52  * @brief Enumeration for projection modes.
53  * @SINCE_1_0.0
54  */
55 enum ProjectionMode
56 {
57   PERSPECTIVE_PROJECTION,    ///< Distance causes foreshortening; objects further from the camera appear smaller @SINCE_1_0.0
58   ORTHOGRAPHIC_PROJECTION,    ///< Relative distance from the camera does not affect the size of objects @SINCE_1_0.0
59 };
60
61 } // namespace Camera
62
63 /**
64  * @brief CameraActor controls a camera.
65  *
66  * Allows the developer to use actor semantics to control a camera.
67  *
68  * DALi has a concept of a camera to display its virtual 3D world to a 2D screen.
69  * There are 2 ways of using the camera in DALi:
70  *
71  * - For 2D applications, you do not need to care about the camera at all. The default camera is already best suited for 2D applications
72  *   (configured to have the origin of the coordinate system at the top-left corner of the screen, and unit 1 as 1 pixel of the screen).
73  *   This is a typical way.
74  *
75  * - For 3D applications, you can change the view by manipulating the camera. You can translate or rotate the camera in this case.
76  *   Note that the top-left corner of the screen and unit 1 no longer are (0,0,0) and 1 pixel after manipulating the camera.
77  *
78  * There are two types of camera actor, FREE_LOOK and LOOK_AT_TARGET. By default,
79  * the camera actor will be FREE_LOOK.
80  *
81  * - A FREE_LOOK camera uses actor's orientation to control where the camera is looking.
82  *   If no additional rotations are specified, the camera looks in the negative Z direction.
83  *
84  * - For LOOK_AT_TARGET, the actor's orientation is ignored, instead the camera looks at TARGET_POSITION
85  *   in world coordinates.
86  *
87  * @SINCE_1_0.0
88  */
89 class DALI_CORE_API CameraActor : public Actor
90 {
91 public:
92
93   /**
94    * @brief Enumeration for the instance of properties belonging to the CameraActor class.
95    *
96    * Properties additional to Actor.
97    * @SINCE_1_0.0
98    */
99   struct Property
100   {
101     /**
102      * @brief Enumeration for the instance of properties belonging to the CameraActor class.
103      *
104      * Properties additional to Actor.
105      * @SINCE_1_0.0
106      */
107     enum
108     {
109       TYPE = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "type",                  type std::string @SINCE_1_0.0
110       PROJECTION_MODE,                                   ///< name "projectionMode",        type std::string @SINCE_1_0.0
111       FIELD_OF_VIEW,                                     ///< name "fieldOfView",           type float @SINCE_1_0.0
112       ASPECT_RATIO,                                      ///< name "aspectRatio",           type float @SINCE_1_0.0
113       NEAR_PLANE_DISTANCE,                               ///< name "nearPlaneDistance",     type float @SINCE_1_0.0
114       FAR_PLANE_DISTANCE,                                ///< name "farPlaneDistance",      type float @SINCE_1_0.0
115       LEFT_PLANE_DISTANCE,                               ///< name "leftPlaneDistance",     type float @SINCE_1_0.0
116       RIGHT_PLANE_DISTANCE,                              ///< name "rightPlaneDistance",    type float @SINCE_1_0.0
117       TOP_PLANE_DISTANCE,                                ///< name "topPlaneDistance",      type float @SINCE_1_0.0
118       BOTTOM_PLANE_DISTANCE,                             ///< name "bottomPlaneDistance",   type float @SINCE_1_0.0
119       TARGET_POSITION,                                   ///< name "targetPosition",        type Vector3 @SINCE_1_0.0
120       PROJECTION_MATRIX,                                 ///< name "projectionMatrix",      type Matrix @SINCE_1_0.0
121       VIEW_MATRIX,                                       ///< name "viewMatrix",            type Matrix @SINCE_1_0.0
122       INVERT_Y_AXIS,                                     ///< name "invertYAxis",           type bool @SINCE_1_0.0
123     };
124   };
125
126   /**
127    * @brief Creates an uninitialized CameraActor handle.
128    *
129    * Initialize it using CameraActor::New().
130    * Calling member functions with an uninitialized CameraActor handle is not allowed.
131    * @SINCE_1_0.0
132    */
133   CameraActor();
134
135   /**
136    * @brief Creates a CameraActor object.
137    *
138    * Sets the default camera perspective projection for the stage's size. @see SetPerspectiveProjection().
139    * @SINCE_1_0.0
140    * @return The newly created camera actor
141    */
142   static CameraActor New();
143
144   /**
145    * @brief Creates a CameraActor object.
146    *
147    * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
148    *
149    * @SINCE_1_0.0
150    * @param[in] size The canvas size
151    * @return The newly created camera actor
152    */
153   static CameraActor New( const Size& size );
154
155   /**
156    * @brief Downcasts a handle to CameraActor handle.
157    *
158    * If handle points to a CameraActor, the downcast produces valid handle.
159    * If not, the returned handle is left uninitialized.
160    * @SINCE_1_0.0
161    * @param[in] handle to An object
162    * @return Handle to a CameraActor or an uninitialized handle
163    */
164   static CameraActor DownCast( BaseHandle handle );
165
166   /**
167    * @brief Destructor.
168    *
169    * This is non-virtual, since derived Handle types must not contain data or virtual methods.
170    * @SINCE_1_0.0
171    */
172   ~CameraActor();
173
174   /**
175    * @brief Copy constructor.
176    *
177    * @SINCE_1_0.0
178    * @param[in] copy The actor to copy
179    */
180   CameraActor(const CameraActor& copy);
181
182   /**
183    * @brief Assignment operator.
184    *
185    * @SINCE_1_0.0
186    * @param[in] rhs The actor to copy
187    * @return A reference to this
188    */
189   CameraActor& operator=(const CameraActor& rhs);
190
191   /**
192    * @brief Sets the camera type.
193    * The default type is Dali::Camera::FREE_LOOK
194    * @SINCE_1_0.0
195    * @param[in] type The camera type
196    */
197   void SetType( Dali::Camera::Type type );
198
199   /**
200    * @brief Gets the type of the camera.
201    *
202    * @SINCE_1_0.0
203    * @return The type of camera
204    */
205   Dali::Camera::Type GetType() const;
206
207   /**
208    * @brief Sets the projection mode.
209    *
210    * @SINCE_1_0.0
211    * @param[in] mode One of PERSPECTIVE_PROJECTION or ORTHOGRAPHIC_PROJECTION
212    */
213   void SetProjectionMode( Dali::Camera::ProjectionMode mode );
214
215   /**
216    * @brief Gets the projection mode.
217    *
218    * @SINCE_1_0.0
219    * @return One of PERSPECTIVE_PROJECTION or ORTHOGRAPHIC_PROJECTION
220    */
221   Dali::Camera::ProjectionMode GetProjectionMode() const;
222
223   /**
224    * @brief Sets the field of view.
225    *
226    * @SINCE_1_0.0
227    * @param[in] fieldOfView The field of view in radians
228    */
229   void SetFieldOfView( float fieldOfView );
230
231   /**
232    * @brief Gets the field of view in Radians.
233    *
234    * The default field of view is 45 degrees.
235    * @SINCE_1_0.0
236    * @return The field of view in radians
237    */
238   float GetFieldOfView( );
239
240   /**
241    * @brief Sets the aspect ratio.
242    *
243    * @SINCE_1_0.0
244    * @param[in] aspectRatio The aspect ratio
245    */
246   void SetAspectRatio( float aspectRatio );
247
248   /**
249    * @brief Gets the aspect ratio of the camera.
250    *
251    * The default aspect ratio is 4.0f/3.0f.
252    * @SINCE_1_0.0
253    * @return The aspect ratio
254    */
255   float GetAspectRatio( );
256
257   /**
258    * @brief Sets the near clipping plane distance.
259    *
260    * @SINCE_1_0.0
261    * @param[in] nearClippingPlane Distance of the near clipping plane
262    */
263   void SetNearClippingPlane( float nearClippingPlane );
264
265   /**
266    * @brief Gets the near clipping plane distance.
267    *
268    * The default near clipping plane is 800.0f, to match the default screen height.
269    * Reduce this value to see objects closer to the camera.
270    * @SINCE_1_0.0
271    * @return The near clipping plane value
272    */
273   float GetNearClippingPlane( );
274
275   /**
276    * @brief Sets the far clipping plane distance.
277    *
278    * @SINCE_1_0.0
279    * @param[in] farClippingPlane Distance of the far clipping plane
280    */
281   void SetFarClippingPlane( float farClippingPlane );
282
283   /**
284    * @brief Gets the far clipping plane distance.
285    *
286    * The default value is the default near clipping plane + (0xFFFF>>4).
287    * @SINCE_1_0.0
288    * @return The far clipping plane value
289    */
290   float GetFarClippingPlane( );
291
292   /**
293    * @brief Sets the target position of the camera.
294    *
295    * @SINCE_1_0.0
296    * @param[in] targetPosition The position of the target to look at
297    * @pre Camera type is LOOK_AT_TARGET.
298    */
299   void SetTargetPosition( const Vector3& targetPosition );
300
301   /**
302    * @brief Gets the Camera Target position.
303    *
304    * The default target position is Vector3::ZERO.
305    * @SINCE_1_0.0
306    * @return The target position of the camera
307    * @pre Camera type is LOOK_AT_TARGET.
308    */
309   Vector3 GetTargetPosition() const;
310
311   /**
312    * @brief Requests for an inversion on the Y axis on the projection calculation.
313    *
314    * The default value is not inverted.
315    * @SINCE_1_0.0
316    * @param[in] invertYAxis True if the Y axis should be inverted
317    */
318   void SetInvertYAxis(bool invertYAxis);
319
320   /**
321    * @brief Gets whether the Y axis is inverted.
322    *
323    * @SINCE_1_0.0
324    * @return @c True if the Y axis is inverted, @c false otherwise
325    */
326   bool GetInvertYAxis();
327
328   /**
329    * @brief Sets the default camera perspective projection for the given canvas size.
330    *
331    * Sets the near and far clipping planes, the field of view, the aspect ratio,
332    * and the Z position of the actor based on the canvas size so that 1 unit in
333    * XY (z=0) plane is 1 pixel on screen.
334    *
335    * If the canvas size is ZERO, it sets the default camera perspective
336    * projection for the stage's size.
337    *
338    * @SINCE_1_0.0
339    * @param[in] size The canvas size
340    * @pre If size is non ZERO, \e width and \e height must be greater than zero.
341    *
342    */
343   void SetPerspectiveProjection( const Size& size );
344
345   /**
346    * @brief Sets the camera projection to use orthographic projection.
347    *
348    * The XY plane is centered on the camera axis. The units in the X/Y
349    * plane directly equate to pixels on an equivalently sized
350    * framebuffer.
351    *
352    * The Z position of the actor, and the near and far clip planes of the
353    * bounding box match those that would be created by using
354    * SetPerspectiveProjection with the same size.
355    *
356    * @SINCE_1_0.0
357    * @param[in] size Size of XY plane (normal to camera axis)
358    */
359   void SetOrthographicProjection( const Size& size );
360
361   /**
362    * @brief Sets the camera projection to use orthographic projection with the given clip planes.
363    *
364    * This does not change the Z value of the camera actor.
365    *
366    * @SINCE_1_0.0
367    * @param[in] left Distance to left clip plane (normal to camera axis)
368    * @param[in] right Distance to right clip plane (normal to camera axis)
369    * @param[in] top Distance to top clip plane (normal to camera axis)
370    * @param[in] bottom Distance to bottom clip plane (normal to camera axis)
371    * @param[in] near Distance to the near clip plane (along camera axis)
372    * @param[in] far Distance to the far clip plane (along camera axis)
373    */
374   void SetOrthographicProjection( float left, float right, float top, float bottom, float near, float far );
375
376 public: // Not intended for use by Application developers
377   /// @cond internal
378   /**
379    * @brief This constructor is used by CameraActor::New() methods.
380    *
381    * @SINCE_1_0.0
382    * @param[in] actor A pointer to a newly allocated Dali resource
383    */
384   explicit DALI_INTERNAL CameraActor(Internal::CameraActor* actor);
385   /// @endcond
386 };
387
388 /**
389  * @}
390  */
391 } // namespace Dali
392
393 #endif // __DALI_CAMERA_ACTOR_H__