Merge "Update comment for SetParentOrigin & SetAnchorPoint" into devel/master
[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) 2015 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 Camera enumerations.
37  * @SINCE_1_0.0
38  */
39 namespace Camera
40 {
41 /**
42  * @brief Type determines 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 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_IMPORT_API CameraActor : public Actor
90 {
91 public:
92
93   /**
94    * @brief An enumeration of properties belonging to the CameraActor class.
95    *
96    * Properties additional to Actor.
97    * @SINCE_1_0.0
98    */
99   struct Property
100   {
101     enum
102     {
103       TYPE = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "type",                  type std::string @SINCE_1_0.0
104       PROJECTION_MODE,                                   ///< name "projectionMode",        type std::string @SINCE_1_0.0
105       FIELD_OF_VIEW,                                     ///< name "fieldOfView",           type float @SINCE_1_0.0
106       ASPECT_RATIO,                                      ///< name "aspectRatio",           type float @SINCE_1_0.0
107       NEAR_PLANE_DISTANCE,                               ///< name "nearPlaneDistance",     type float @SINCE_1_0.0
108       FAR_PLANE_DISTANCE,                                ///< name "farPlaneDistance",      type float @SINCE_1_0.0
109       LEFT_PLANE_DISTANCE,                               ///< name "leftPlaneDistance",     type float @SINCE_1_0.0
110       RIGHT_PLANE_DISTANCE,                              ///< name "rightPlaneDistance",    type float @SINCE_1_0.0
111       TOP_PLANE_DISTANCE,                                ///< name "topPlaneDistance",      type float @SINCE_1_0.0
112       BOTTOM_PLANE_DISTANCE,                             ///< name "bottomPlaneDistance",   type float @SINCE_1_0.0
113       TARGET_POSITION,                                   ///< name "targetPosition",        type Vector3 @SINCE_1_0.0
114       PROJECTION_MATRIX,                                 ///< name "projectionMatrix",      type Matrix @SINCE_1_0.0
115       VIEW_MATRIX,                                       ///< name "viewMatrix",            type Matrix @SINCE_1_0.0
116       INVERT_Y_AXIS,                                     ///< name "invertYAxis",           type bool @SINCE_1_0.0
117     };
118   };
119
120   /**
121    * @brief Create an uninitialized CameraActor handle.
122    *
123    * Initialise it using CameraActor::New().
124    * Calling member functions with an uninitialized CameraActor handle is not allowed.
125    * @SINCE_1_0.0
126    */
127   CameraActor();
128
129   /**
130    * @brief Create a CameraActor object.
131    *
132    * Sets the default camera perspective projection for the stage's size. @see SetPerspectiveProjection().
133    * @SINCE_1_0.0
134    * @return The newly created camera actor.
135    */
136   static CameraActor New();
137
138   /**
139    * @brief Create a CameraActor object.
140    *
141    * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
142    *
143    * @SINCE_1_0.0
144    * @param[in] size The canvas size.
145    * @return The newly created camera actor.
146    */
147   static CameraActor New( const Size& size );
148
149   /**
150    * @brief Downcast a handle to CameraActor handle.
151    *
152    * If handle points to a CameraActor the downcast produces valid
153    * handle. If not the returned handle is left uninitialized.
154    * @SINCE_1_0.0
155    * @param[in] handle to An object
156    * @return Handle to a CameraActor or an uninitialized handle
157    */
158   static CameraActor DownCast( BaseHandle handle );
159
160   /**
161    * @brief Destructor
162    *
163    * This is non-virtual since derived Handle types must not contain data or virtual methods.
164    * @SINCE_1_0.0
165    */
166   ~CameraActor();
167
168   /**
169    * @brief Copy constructor
170    *
171    * @SINCE_1_0.0
172    * @param [in] copy The actor to copy.
173    */
174   CameraActor(const CameraActor& copy);
175
176   /**
177    * @brief Assignment operator
178    *
179    * @SINCE_1_0.0
180    * @param [in] rhs The actor to copy.
181    * @return A reference to this
182    */
183   CameraActor& operator=(const CameraActor& rhs);
184
185   /**
186    * @brief Set the camera type.
187    * The default type is Dali::Camera::FREE_LOOK
188    * @SINCE_1_0.0
189    * @param[in] type The camera type
190    */
191   void SetType( Dali::Camera::Type type );
192
193   /**
194    * @brief Get the type of the camera.
195    *
196    * @SINCE_1_0.0
197    * @return The type of camera
198    */
199   Dali::Camera::Type GetType() const;
200
201   /**
202    * @brief Set the projection mode.
203    *
204    * @SINCE_1_0.0
205    * @param[in] mode One of PERSPECTIVE_PROJECTION or ORTHOGRAPHIC_PROJECTION
206    */
207   void SetProjectionMode( Dali::Camera::ProjectionMode mode );
208
209   /**
210    * @brief Get the projection mode.
211    *
212    * @SINCE_1_0.0
213    * @return One of PERSPECTIVE_PROJECTION or ORTHOGRAPHIC_PROJECTION
214    */
215   Dali::Camera::ProjectionMode GetProjectionMode() const;
216
217   /**
218    * @brief Set the field of view.
219    *
220    * @SINCE_1_0.0
221    * @param[in] fieldOfView The field of view in radians
222    */
223   void SetFieldOfView( float fieldOfView );
224
225   /**
226    * @brief Get the field of view in Radians.
227    *
228    * The default field of view is 45 degrees.
229    * @SINCE_1_0.0
230    * @return The field of view in radians
231    */
232   float GetFieldOfView( );
233
234   /**
235    * @brief Set the aspect ratio.
236    *
237    * @SINCE_1_0.0
238    * @param[in] aspectRatio The aspect ratio
239    */
240   void SetAspectRatio( float aspectRatio );
241
242   /**
243    * @brief Get the aspect ratio of the camera.
244    *
245    * The default aspect ratio is 4.0f/3.0f.
246    * @SINCE_1_0.0
247    * @return The aspect ratio
248    */
249   float GetAspectRatio( );
250
251   /**
252    * @brief Sets the near clipping plane distance.
253    *
254    * @SINCE_1_0.0
255    * @param[in] nearClippingPlane Distance of the near clipping plane
256    */
257   void SetNearClippingPlane( float nearClippingPlane );
258
259   /**
260    * @brief Get the near clipping plane distance.
261    *
262    * The default near clipping plane is 800.0f, to match the default screen height.
263    * Reduce this value to see objects closer to the camera.
264    * @SINCE_1_0.0
265    * @return The near clipping plane value
266    */
267   float GetNearClippingPlane( );
268
269   /**
270    * @brief Sets the far clipping plane distance.
271    *
272    * @SINCE_1_0.0
273    * @param[in] farClippingPlane Distance of the far clipping plane
274    */
275   void SetFarClippingPlane( float farClippingPlane );
276
277   /**
278    * @brief Get the far clipping plane distance.
279    *
280    * The default value is the default near clipping plane + (0xFFFF>>4).
281    * @SINCE_1_0.0
282    * @return The far clipping plane value
283    */
284   float GetFarClippingPlane( );
285
286   /**
287    * @brief Set the target position of the camera.
288    *
289    * @SINCE_1_0.0
290    * @param[in] targetPosition The position of the target to look at
291    * @pre Camera type is LOOK_AT_TARGET.
292    */
293   void SetTargetPosition( const Vector3& targetPosition );
294
295   /**
296    * @brief Get Camera Target position.
297    *
298    * The default target position is Vector3::ZERO.
299    * @SINCE_1_0.0
300    * @return The target position of the camera
301    * @pre Camera type is LOOK_AT_TARGET.
302    */
303   Vector3 GetTargetPosition() const;
304
305   /**
306    * @brief Request for an inversion on the Y axis on the projection calculation.
307    *
308    * The default value is not inverted.
309    * @SINCE_1_0.0
310    * @param[in] invertYAxis True if the Y axis should be inverted
311    */
312   void SetInvertYAxis(bool invertYAxis);
313
314   /**
315    * @brief Get whether the Y axis is inverted.
316    *
317    * @SINCE_1_0.0
318    * @return True if the Y axis is inverted, false otherwise
319    */
320   bool GetInvertYAxis();
321
322   /**
323    * @brief Sets the default camera perspective projection for the given canvas size.
324    *
325    * Sets the near and far clipping planes, the field of view, the aspect ratio
326    * and the Z position of the actor based on the canvas size so that 1 unit in
327    * XY (z=0) plane is 1 pixel on screen.
328    *
329    * If the canvas size is ZERO, it sets the default camera perspective
330    * projection for the stage's size.
331    *
332    * @SINCE_1_0.0
333    * @param[in] size The canvas size.
334    * @pre If size is non ZERO, \e width and \e height must be greater than zero.
335    *
336    */
337   void SetPerspectiveProjection( const Size& size );
338
339   /**
340    * @brief Sets the camera projection to use orthographic projection.
341    *
342    * The XY plane is centered on the camera axis. The units in the X/Y
343    * plane directly equate to pixels on an equivalently sized
344    * framebuffer.
345    *
346    * The Z position of the actor, and the near and far clip planes of the
347    * bounding box match those that would be created by using
348    * SetPerspectiveProjection with the same size.
349    *
350    * @SINCE_1_0.0
351    * @param[in] size Size of XY plane (normal to camera axis)
352    */
353   void SetOrthographicProjection( const Size& size );
354
355   /**
356    * @brief Sets the camera projection to use orthographic projection with the given clip planes.
357    *
358    * This does not change the Z value of the camera actor.
359    *
360    * @SINCE_1_0.0
361    * @param[in] left Distance to left clip plane (normal to camera axis)
362    * @param[in] right Distance to right clip plane (normal to camera axis)
363    * @param[in] top Distance to top clip plane (normal to camera axis)
364    * @param[in] bottom Distance to bottom clip plane (normal to camera axis)
365    * @param[in] near Distance to the near clip plane (along camera axis)
366    * @param[in] far Distance to the far clip plane (along camera axis)
367    */
368   void SetOrthographicProjection( float left, float right, float top, float bottom, float near, float far );
369
370 public: // Not intended for use by Application developers
371   /// @cond internal
372   /**
373    * @brief This constructor is used by CameraActor::New() methods.
374    *
375    * @SINCE_1_0.0
376    * @param [in] actor A pointer to a newly allocated Dali resource
377    */
378   explicit DALI_INTERNAL CameraActor(Internal::CameraActor* actor);
379   /// @endcond
380 };
381
382 /**
383  * @}
384  */
385 } // namespace Dali
386
387 #endif // __DALI_CAMERA_ACTOR_H__