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