CAPI removal
[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) 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 #include <dali/public-api/actors/actor.h>
22
23 namespace Dali DALI_IMPORT_API
24 {
25
26 namespace Internal DALI_INTERNAL
27 {
28 class CameraActor;
29 }
30
31
32 namespace Camera
33 {
34 /**
35  * @brief Type determines how camera operates.
36  */
37 enum Type
38 {
39   FREE_LOOK,      ///< Camera orientation is taken from CameraActor
40   LOOK_AT_TARGET, ///< Camera is oriented to always look at a target
41 };
42
43 /**
44  * @brief Projection modes.
45  */
46 enum ProjectionMode
47 {
48   PERSPECTIVE_PROJECTION,    ///< Distance causes foreshortening; objects further from the camera appear smaller
49   ORTHOGRAPHIC_PROJECTION,    ///< Relative distance from the camera does not affect the size of objects
50 };
51
52 } // namespace Camera
53
54 /**
55  * @brief Controls a camera.
56  *
57  * Allows the developer to use actor semantics to control a camera.
58  *
59  * There are two types of camera actor, LookAt and FreeLook. A LookAt
60  * camera actor ignores the actor rotation, and instead points towards
61  * TargetPosition in world coordinates. This is the default behaviour.
62  *
63  * A FreeLook camera uses the camera actor's world rotation to control
64  * where the camera is looking. If no rotation is specified, then the camera
65  * looks along the negative Z axis.
66  *
67  */
68 class CameraActor : public Actor
69 {
70 public:
71
72   // Default Properties; additional to Actor properties
73   static const Property::Index TYPE;                         ///< Property::STRING,   // "type"                 // Not animatable
74   static const Property::Index PROJECTION_MODE;              ///< Property::STRING,   // "projection-mode"      // Not animatable
75   static const Property::Index FIELD_OF_VIEW;                ///< Property::FLOAT,    // "field-of-view"        // Not animatable
76   static const Property::Index ASPECT_RATIO;                 ///< Property::FLOAT,    // "aspect-ratio"         // Not animatable
77   static const Property::Index NEAR_PLANE_DISTANCE;          ///< Property::FLOAT,    // "near-plane-distance"  // Not animatable
78   static const Property::Index FAR_PLANE_DISTANCE;           ///< Property::FLOAT,    // "far-plane-distance"   // Not animatable
79   static const Property::Index LEFT_PLANE_DISTANCE;          ///< Property::FLOAT,    // "left-plane-distance"  // Not animatable
80   static const Property::Index RIGHT_PLANE_DISTANCE;         ///< Property::FLOAT,    // "right-plane-distance" // Not animatable
81   static const Property::Index TOP_PLANE_DISTANCE;           ///< Property::FLOAT,    // "top-plane-distance"   // Not animatable
82   static const Property::Index BOTTOM_PLANE_DISTANCE;        ///< Property::FLOAT,    // "bottom-plane-distance"// Not animatable
83   static const Property::Index TARGET_POSITION;              ///< Property::VECTOR3,  // "target"               // Not animatable
84   static const Property::Index PROJECTION_MATRIX;            ///< Property::MATRIX,   // "projection-matrix"    // Constraint input, not animatable
85   static const Property::Index VIEW_MATRIX;                  ///< Property::MATRIX,   // "view-matrix"          // constraint input, not abimatable
86   static const Property::Index INVERT_Y_AXIS;                ///< Property::BOOLEAN,  // "invert-y-axis"        // Not animatable
87
88   /**
89    * @brief Create an uninitialized CameraActor handle.
90    *
91    * Initialise it using CameraActor::New().  Calling member functions
92    * with an uninitialized Dali::Object is not allowed.
93    */
94   CameraActor();
95
96   /**
97    * @brief Create a CameraActor object.
98    *
99    * Sets the default camera perspective projection for the stage's size. @see SetPerspectiveProjection().
100    * @return the newly created camera actor.
101    */
102   static CameraActor New();
103
104   /**
105    * @brief Create a CameraActor object.
106    *
107    * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
108    *
109    * @param[in] size The canvas size.
110    * @return the newly created camera actor.
111    */
112   static CameraActor New( const Size& size );
113
114   /**
115    * @brief Downcast an Object handle to CameraActor.
116    *
117    * If handle points to a CameraActor the downcast produces valid
118    * handle. If not the returned handle is left uninitialized.
119    * @param[in] handle to An object
120    * @return handle to a CameraActor or an uninitialized handle
121    */
122   static CameraActor DownCast( BaseHandle handle );
123
124   /**
125    * @brief Destructor
126    *
127    * This is non-virtual since derived Handle types must not contain data or virtual methods.
128    */
129   ~CameraActor();
130
131   /**
132    * @copydoc Dali::BaseHandle::operator=
133    */
134   using BaseHandle::operator=;
135
136   /**
137    * @brief Set the camera type.
138    * The default type is Dali::Camera::LookAtTarget
139    * @param[in] type The camera type
140    */
141   void SetType( Dali::Camera::Type type );
142
143   /**
144    * @brief Get the type of the camera.
145    *
146    * @return the type of camera
147    */
148   Dali::Camera::Type GetType() const;
149
150   /**
151    * @brief Set the projection mode.
152    *
153    * @param[in] mode One of PerspectiveProjection or OrthographicProjection
154    */
155   void SetProjectionMode( Dali::Camera::ProjectionMode mode );
156
157   /**
158    * @brief Get the projection mode.
159    *
160    * @return One of PerspectiveProjection or OrthographicProjection
161    */
162   Dali::Camera::ProjectionMode GetProjectionMode() const;
163
164   /**
165    * @brief Set the field of view.
166    *
167    * @param[in] fieldOfView The field of view in radians
168    */
169   void SetFieldOfView( float fieldOfView );
170
171   /**
172    * @brief Get the field of view in Radians.
173    *
174    * The default field of view is 45 degrees
175    * @return The field of view in radians
176    */
177   float GetFieldOfView( );
178
179   /**
180    * @brief Set the aspect ratio.
181    *
182    * @param[in] aspectRatio The aspect ratio
183    */
184   void SetAspectRatio( float aspectRatio );
185
186   /**
187    * @brief Get the aspect ratio of the camera.
188    *
189    * The default aspect ratio is 4.0f/3.0f
190    * @return the aspect ratio
191    */
192   float GetAspectRatio( );
193
194   /**
195    * @brief Sets the near clipping plane distance.
196    *
197    * @param[in] nearClippingPlane distance of the near clipping plane
198    */
199   void SetNearClippingPlane( float nearClippingPlane );
200
201   /**
202    * @brief Get the near clipping plane distance.
203    *
204    * The default near clipping plane is 800.0f, to match the default screen height
205    * Reduce this value to see objects closer to the camera
206    * @return the near clipping plane value
207    */
208   float GetNearClippingPlane( );
209
210   /**
211    * @brief Sets the far clipping plane distance.
212    *
213    * @param[in] farClippingPlane distance of the far clipping plane
214    */
215   void SetFarClippingPlane( float farClippingPlane );
216
217   /**
218    * @brief Get the far clipping plane distance.
219    *
220    * The default value is the default near clipping plane + (0xFFFF>>4)
221    * @return the far clipping plane value
222    */
223   float GetFarClippingPlane( );
224
225   /**
226    * @brief Set the target position of the camera.
227    *
228    * @pre Camera type is LookAtTarget
229    * @param[in] targetPosition The position of the target to look at
230    */
231   void SetTargetPosition( const Vector3& targetPosition );
232
233   /**
234    * @brief Get Camera Target position.
235    *
236    * The target position is Vector3::ZERO
237    * @pre Camera type is LookAtTarget
238    * @return The target position of the camera
239    */
240   Vector3 GetTargetPosition() const;
241
242   /**
243    * @brief Request for an inversion on the Y axis on the projection calculation.
244    *
245    * The default value is not inverted.
246    * @param[in] invertYAxis True if the Y axis should be inverted
247    */
248   void SetInvertYAxis(bool invertYAxis);
249
250   /**
251    * @brief Get whether the Y axis is inverted.
252    *
253    * @return True if the Y axis is inverted, false otherwise
254    */
255   bool GetInvertYAxis();
256
257   /**
258    * @brief Sets the default camera perspective projection for the given canvas size.
259    *
260    * Sets the near and far clipping planes, the field of view, the aspect ratio
261    * and the Z position of the actor based on the canvas size so that 1 unit in
262    * XY (z=0) plane is 1 pixel on screen.
263    *
264    * If the canvas size is ZERO, it sets the default camera perspective
265    * projection for the stage's size.
266    *
267    * @pre If size is non ZERO, \e width and \e height must be greater than zero.
268    *
269    * @param[in] size The canvas size.
270    */
271   void SetPerspectiveProjection( const Size& size );
272
273   /**
274    * @brief Sets the camera projection to use orthographic projection.
275    *
276    * The XY plane is centered on the camera axis. The units in the X/Y
277    * plane directly equate to pixels on an equivalently sized
278    * framebuffer.
279    *
280    * The Z position of the actor, and the near and far clip planes of the
281    * bounding box match those that would be created by using
282    * SetPerspectiveProjection with the same size.
283    *
284    * @param[in] size Size of XY plane (normal to camera axis)
285    */
286   void SetOrthographicProjection( const Size& size );
287
288   /**
289    * @brief Sets the camera projection to use orthographic projection with the given clip planes.
290    *
291    * This does not change the Z value of the camera actor.
292    *
293    * @param[in] left Distance to left clip plane (normal to camera axis)
294    * @param[in] right Distance to right clip plane (normal to camera axis)
295    * @param[in] top Distance to top clip plane (normal to camera axis)
296    * @param[in] bottom Distance to bottom clip plane (normal to camera axis)
297    * @param[in] near Distance to the near clip plane (along camera axis)
298    * @param[in] far Distance to the far clip plane (along camera axis)
299    */
300   void SetOrthographicProjection( float left, float right, float top, float bottom, float near, float far );
301
302 public: // Not intended for use by Application developers
303   /**
304    * @brief This constructor is used by Dali New() methods.
305    *
306    * @param [in] actor A pointer to a newly allocated Dali resource
307    */
308   explicit DALI_INTERNAL CameraActor(Internal::CameraActor* actor);
309 };
310
311 } // namespace Dali
312
313 #endif // __DALI_CAMERA_ACTOR_H__