1 #ifndef __DALI_CAMERA_ACTOR_H__
2 #define __DALI_CAMERA_ACTOR_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/actors/actor.h>
26 namespace Internal DALI_INTERNAL
35 * @brief Type determines how camera operates.
39 FREE_LOOK, ///< Camera orientation is taken from CameraActor
40 LOOK_AT_TARGET, ///< Camera is oriented to always look at a target
44 * @brief Projection modes.
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
55 * @brief Controls a camera.
57 * Allows the developer to use actor semantics to control a camera.
59 * There are two types of camera actor, FREE_LOOK and LOOK_AT_TARGET. By default
60 * the camera actor will be FREE_LOOK.
62 * A FREE_LOOK camera uses actor's rotation to control where the camera is looking.
63 * If no additional rotations are specified, the camera looks in the negative Z direction.
65 * For LOOK_AT_TARGET the actor's rotation is ignored, instead the camera looks at TARGET_POSITION
66 * in world coordinates.
69 class DALI_IMPORT_API CameraActor : public Actor
73 // Default Properties; additional to Actor properties
74 static const Property::Index TYPE; ///< Property::STRING, // "type" // Not animatable
75 static const Property::Index PROJECTION_MODE; ///< Property::STRING, // "projection-mode" // Not animatable
76 static const Property::Index FIELD_OF_VIEW; ///< Property::FLOAT, // "field-of-view" // Not animatable
77 static const Property::Index ASPECT_RATIO; ///< Property::FLOAT, // "aspect-ratio" // Not animatable
78 static const Property::Index NEAR_PLANE_DISTANCE; ///< Property::FLOAT, // "near-plane-distance" // Not animatable
79 static const Property::Index FAR_PLANE_DISTANCE; ///< Property::FLOAT, // "far-plane-distance" // Not animatable
80 static const Property::Index LEFT_PLANE_DISTANCE; ///< Property::FLOAT, // "left-plane-distance" // Not animatable
81 static const Property::Index RIGHT_PLANE_DISTANCE; ///< Property::FLOAT, // "right-plane-distance" // Not animatable
82 static const Property::Index TOP_PLANE_DISTANCE; ///< Property::FLOAT, // "top-plane-distance" // Not animatable
83 static const Property::Index BOTTOM_PLANE_DISTANCE; ///< Property::FLOAT, // "bottom-plane-distance" // Not animatable
84 static const Property::Index TARGET_POSITION; ///< Property::VECTOR3, // "target-position" // Not animatable
85 static const Property::Index PROJECTION_MATRIX; ///< Property::MATRIX, // "projection-matrix" // Constraint input, not animatable
86 static const Property::Index VIEW_MATRIX; ///< Property::MATRIX, // "view-matrix" // Constraint input, not animatable
87 static const Property::Index INVERT_Y_AXIS; ///< Property::BOOLEAN, // "invert-y-axis" // Not animatable
90 * @brief Create an uninitialized CameraActor handle.
92 * Initialise it using CameraActor::New(). Calling member functions
93 * with an uninitialized Dali::Object is not allowed.
98 * @brief Create a CameraActor object.
100 * Sets the default camera perspective projection for the stage's size. @see SetPerspectiveProjection().
101 * @return the newly created camera actor.
103 static CameraActor New();
106 * @brief Create a CameraActor object.
108 * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
110 * @param[in] size The canvas size.
111 * @return the newly created camera actor.
113 static CameraActor New( const Size& size );
116 * @brief Downcast an Object handle to CameraActor.
118 * If handle points to a CameraActor the downcast produces valid
119 * handle. If not the returned handle is left uninitialized.
120 * @param[in] handle to An object
121 * @return handle to a CameraActor or an uninitialized handle
123 static CameraActor DownCast( BaseHandle handle );
128 * This is non-virtual since derived Handle types must not contain data or virtual methods.
133 * @brief Copy constructor
135 * @param [in] copy The actor to copy.
137 CameraActor(const CameraActor& copy);
140 * @brief Assignment operator
142 * @param [in] rhs The actor to copy.
144 CameraActor& operator=(const CameraActor& rhs);
147 * @brief This method is defined to allow assignment of the NULL value,
148 * and will throw an exception if passed any other value.
150 * Assigning to NULL is an alias for Reset().
151 * @param [in] rhs A NULL pointer
152 * @return A reference to this handle
154 CameraActor& operator=(BaseHandle::NullType* rhs);
157 * @brief Set the camera type.
158 * The default type is Dali::Camera::FREE_LOOK
159 * @param[in] type The camera type
161 void SetType( Dali::Camera::Type type );
164 * @brief Get the type of the camera.
166 * @return the type of camera
168 Dali::Camera::Type GetType() const;
171 * @brief Set the projection mode.
173 * @param[in] mode One of PERSPECTIVE_PROJECTION or ORTHOGRAPHIC_PROJECTION
175 void SetProjectionMode( Dali::Camera::ProjectionMode mode );
178 * @brief Get the projection mode.
180 * @return One of PERSPECTIVE_PROJECTION or ORTHOGRAPHIC_PROJECTION
182 Dali::Camera::ProjectionMode GetProjectionMode() const;
185 * @brief Set the field of view.
187 * @param[in] fieldOfView The field of view in radians
189 void SetFieldOfView( float fieldOfView );
192 * @brief Get the field of view in Radians.
194 * The default field of view is 45 degrees
195 * @return The field of view in radians
197 float GetFieldOfView( );
200 * @brief Set the aspect ratio.
202 * @param[in] aspectRatio The aspect ratio
204 void SetAspectRatio( float aspectRatio );
207 * @brief Get the aspect ratio of the camera.
209 * The default aspect ratio is 4.0f/3.0f
210 * @return the aspect ratio
212 float GetAspectRatio( );
215 * @brief Sets the near clipping plane distance.
217 * @param[in] nearClippingPlane distance of the near clipping plane
219 void SetNearClippingPlane( float nearClippingPlane );
222 * @brief Get the near clipping plane distance.
224 * The default near clipping plane is 800.0f, to match the default screen height
225 * Reduce this value to see objects closer to the camera
226 * @return the near clipping plane value
228 float GetNearClippingPlane( );
231 * @brief Sets the far clipping plane distance.
233 * @param[in] farClippingPlane distance of the far clipping plane
235 void SetFarClippingPlane( float farClippingPlane );
238 * @brief Get the far clipping plane distance.
240 * The default value is the default near clipping plane + (0xFFFF>>4)
241 * @return the far clipping plane value
243 float GetFarClippingPlane( );
246 * @brief Set the target position of the camera.
248 * @pre Camera type is LOOK_AT_TARGET
249 * @param[in] targetPosition The position of the target to look at
251 void SetTargetPosition( const Vector3& targetPosition );
254 * @brief Get Camera Target position.
256 * The target position is Vector3::ZERO
257 * @pre Camera type is LOOK_AT_TARGET
258 * @return The target position of the camera
260 Vector3 GetTargetPosition() const;
263 * @brief Request for an inversion on the Y axis on the projection calculation.
265 * The default value is not inverted.
266 * @param[in] invertYAxis True if the Y axis should be inverted
268 void SetInvertYAxis(bool invertYAxis);
271 * @brief Get whether the Y axis is inverted.
273 * @return True if the Y axis is inverted, false otherwise
275 bool GetInvertYAxis();
278 * @brief Sets the default camera perspective projection for the given canvas size.
280 * Sets the near and far clipping planes, the field of view, the aspect ratio
281 * and the Z position of the actor based on the canvas size so that 1 unit in
282 * XY (z=0) plane is 1 pixel on screen.
284 * If the canvas size is ZERO, it sets the default camera perspective
285 * projection for the stage's size.
287 * @pre If size is non ZERO, \e width and \e height must be greater than zero.
289 * @param[in] size The canvas size.
291 void SetPerspectiveProjection( const Size& size );
294 * @brief Sets the camera projection to use orthographic projection.
296 * The XY plane is centered on the camera axis. The units in the X/Y
297 * plane directly equate to pixels on an equivalently sized
300 * The Z position of the actor, and the near and far clip planes of the
301 * bounding box match those that would be created by using
302 * SetPerspectiveProjection with the same size.
304 * @param[in] size Size of XY plane (normal to camera axis)
306 void SetOrthographicProjection( const Size& size );
309 * @brief Sets the camera projection to use orthographic projection with the given clip planes.
311 * This does not change the Z value of the camera actor.
313 * @param[in] left Distance to left clip plane (normal to camera axis)
314 * @param[in] right Distance to right clip plane (normal to camera axis)
315 * @param[in] top Distance to top clip plane (normal to camera axis)
316 * @param[in] bottom Distance to bottom clip plane (normal to camera axis)
317 * @param[in] near Distance to the near clip plane (along camera axis)
318 * @param[in] far Distance to the far clip plane (along camera axis)
320 void SetOrthographicProjection( float left, float right, float top, float bottom, float near, float far );
322 public: // Not intended for use by Application developers
324 * @brief This constructor is used by Dali New() methods.
326 * @param [in] actor A pointer to a newly allocated Dali resource
328 explicit DALI_INTERNAL CameraActor(Internal::CameraActor* actor);
333 #endif // __DALI_CAMERA_ACTOR_H__