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
74 * @brief An enumeration of properties belonging to the CameraActor class.
75 * Properties additional to Actor.
81 TYPE = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "type", type std::string
82 PROJECTION_MODE, ///< name "projection-mode", type std::string
83 FIELD_OF_VIEW, ///< name "field-of-view", type float
84 ASPECT_RATIO, ///< name "aspect-ratio", type float
85 NEAR_PLANE_DISTANCE, ///< name "near-plane-distance", type float
86 FAR_PLANE_DISTANCE, ///< name "far-plane-distance", type float
87 LEFT_PLANE_DISTANCE, ///< name "left-plane-distance", type float
88 RIGHT_PLANE_DISTANCE, ///< name "right-plane-distance", type float
89 TOP_PLANE_DISTANCE, ///< name "top-plane-distance", type float
90 BOTTOM_PLANE_DISTANCE, ///< name "bottom-plane-distance", type float
91 TARGET_POSITION, ///< name "target-position", type Vector3
92 PROJECTION_MATRIX, ///< name "projection-matrix", type Matrix
93 VIEW_MATRIX, ///< name "view-matrix", type Matrix
94 INVERT_Y_AXIS, ///< name "invert-y-axis", type bool
99 * @brief Create an uninitialized CameraActor handle.
101 * Initialise it using CameraActor::New(). Calling member functions
102 * with an uninitialized Dali::Object is not allowed.
107 * @brief Create a CameraActor object.
109 * Sets the default camera perspective projection for the stage's size. @see SetPerspectiveProjection().
110 * @return the newly created camera actor.
112 static CameraActor New();
115 * @brief Create a CameraActor object.
117 * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
119 * @param[in] size The canvas size.
120 * @return the newly created camera actor.
122 static CameraActor New( const Size& size );
125 * @brief Downcast an Object handle to CameraActor.
127 * If handle points to a CameraActor the downcast produces valid
128 * handle. If not the returned handle is left uninitialized.
129 * @param[in] handle to An object
130 * @return handle to a CameraActor or an uninitialized handle
132 static CameraActor DownCast( BaseHandle handle );
137 * This is non-virtual since derived Handle types must not contain data or virtual methods.
142 * @brief Copy constructor
144 * @param [in] copy The actor to copy.
146 CameraActor(const CameraActor& copy);
149 * @brief Assignment operator
151 * @param [in] rhs The actor to copy.
153 CameraActor& operator=(const CameraActor& rhs);
156 * @brief Set the camera type.
157 * The default type is Dali::Camera::FREE_LOOK
158 * @param[in] type The camera type
160 void SetType( Dali::Camera::Type type );
163 * @brief Get the type of the camera.
165 * @return the type of camera
167 Dali::Camera::Type GetType() const;
170 * @brief Set the projection mode.
172 * @param[in] mode One of PERSPECTIVE_PROJECTION or ORTHOGRAPHIC_PROJECTION
174 void SetProjectionMode( Dali::Camera::ProjectionMode mode );
177 * @brief Get the projection mode.
179 * @return One of PERSPECTIVE_PROJECTION or ORTHOGRAPHIC_PROJECTION
181 Dali::Camera::ProjectionMode GetProjectionMode() const;
184 * @brief Set the field of view.
186 * @param[in] fieldOfView The field of view in radians
188 void SetFieldOfView( float fieldOfView );
191 * @brief Get the field of view in Radians.
193 * The default field of view is 45 degrees
194 * @return The field of view in radians
196 float GetFieldOfView( );
199 * @brief Set the aspect ratio.
201 * @param[in] aspectRatio The aspect ratio
203 void SetAspectRatio( float aspectRatio );
206 * @brief Get the aspect ratio of the camera.
208 * The default aspect ratio is 4.0f/3.0f
209 * @return the aspect ratio
211 float GetAspectRatio( );
214 * @brief Sets the near clipping plane distance.
216 * @param[in] nearClippingPlane distance of the near clipping plane
218 void SetNearClippingPlane( float nearClippingPlane );
221 * @brief Get the near clipping plane distance.
223 * The default near clipping plane is 800.0f, to match the default screen height
224 * Reduce this value to see objects closer to the camera
225 * @return the near clipping plane value
227 float GetNearClippingPlane( );
230 * @brief Sets the far clipping plane distance.
232 * @param[in] farClippingPlane distance of the far clipping plane
234 void SetFarClippingPlane( float farClippingPlane );
237 * @brief Get the far clipping plane distance.
239 * The default value is the default near clipping plane + (0xFFFF>>4)
240 * @return the far clipping plane value
242 float GetFarClippingPlane( );
245 * @brief Set the target position of the camera.
247 * @pre Camera type is LOOK_AT_TARGET
248 * @param[in] targetPosition The position of the target to look at
250 void SetTargetPosition( const Vector3& targetPosition );
253 * @brief Get Camera Target position.
255 * The target position is Vector3::ZERO
256 * @pre Camera type is LOOK_AT_TARGET
257 * @return The target position of the camera
259 Vector3 GetTargetPosition() const;
262 * @brief Request for an inversion on the Y axis on the projection calculation.
264 * The default value is not inverted.
265 * @param[in] invertYAxis True if the Y axis should be inverted
267 void SetInvertYAxis(bool invertYAxis);
270 * @brief Get whether the Y axis is inverted.
272 * @return True if the Y axis is inverted, false otherwise
274 bool GetInvertYAxis();
277 * @brief Sets the default camera perspective projection for the given canvas size.
279 * Sets the near and far clipping planes, the field of view, the aspect ratio
280 * and the Z position of the actor based on the canvas size so that 1 unit in
281 * XY (z=0) plane is 1 pixel on screen.
283 * If the canvas size is ZERO, it sets the default camera perspective
284 * projection for the stage's size.
286 * @pre If size is non ZERO, \e width and \e height must be greater than zero.
288 * @param[in] size The canvas size.
290 void SetPerspectiveProjection( const Size& size );
293 * @brief Sets the camera projection to use orthographic projection.
295 * The XY plane is centered on the camera axis. The units in the X/Y
296 * plane directly equate to pixels on an equivalently sized
299 * The Z position of the actor, and the near and far clip planes of the
300 * bounding box match those that would be created by using
301 * SetPerspectiveProjection with the same size.
303 * @param[in] size Size of XY plane (normal to camera axis)
305 void SetOrthographicProjection( const Size& size );
308 * @brief Sets the camera projection to use orthographic projection with the given clip planes.
310 * This does not change the Z value of the camera actor.
312 * @param[in] left Distance to left clip plane (normal to camera axis)
313 * @param[in] right Distance to right clip plane (normal to camera axis)
314 * @param[in] top Distance to top clip plane (normal to camera axis)
315 * @param[in] bottom Distance to bottom clip plane (normal to camera axis)
316 * @param[in] near Distance to the near clip plane (along camera axis)
317 * @param[in] far Distance to the far clip plane (along camera axis)
319 void SetOrthographicProjection( float left, float right, float top, float bottom, float near, float far );
321 public: // Not intended for use by Application developers
323 * @brief This constructor is used by Dali New() methods.
325 * @param [in] actor A pointer to a newly allocated Dali resource
327 explicit DALI_INTERNAL CameraActor(Internal::CameraActor* actor);
332 #endif // __DALI_CAMERA_ACTOR_H__