1 #ifndef DALI_INTERNAL_CAMERA_ACTOR_H
2 #define DALI_INTERNAL_CAMERA_ACTOR_H
5 * Copyright (c) 2023 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.
22 #include <dali/devel-api/actors/camera-actor-devel.h>
23 #include <dali/internal/event/actors/actor-declarations.h>
24 #include <dali/internal/event/actors/actor-impl.h>
25 #include <dali/public-api/actors/camera-actor.h>
37 * An actor with Camera.
39 class CameraActor : public Actor
43 * Create an initialised camera actor.
45 * If hintFor3D is false, Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
47 * @param[in] size The canvas size.
48 * @param[in] hintFor3D True if user set hint that this camera used for 3D. Default is false.
50 * @return A smart-pointer to a newly allocated camera actor.
52 static CameraActorPtr New(const Size& size, bool hintFor3D = false);
55 * Sets the reflection plane for the camera
57 * @param[in] plane Plane parameters
59 * @note plane.xyz are normal vector of the plane.
61 void SetReflectByPlane(const Vector4& plane);
64 * @copydoc Dali::CameraActor::SetTargetPosition
66 void SetTarget(const Vector3& targetPosition);
69 * @copydoc Dali::CameraActor::GetTargetPosition
71 Vector3 GetTarget() const;
74 * @copydoc Dali::CameraActor::SetType
76 void SetType(Dali::Camera::Type type);
79 * @copydoc Dali::CameraActor::GetType
81 Dali::Camera::Type GetType() const;
84 * @copydoc Dali::CameraActor::SetProjectionMode
86 void SetProjectionMode(Dali::Camera::ProjectionMode mode);
89 * @copydoc Dali::CameraActor::GetProjectionMode
91 Dali::Camera::ProjectionMode GetProjectionMode() const;
94 * @brief Set the projection direction
96 * @param[in] direction Direction of projection
98 void SetProjectionDirection(Dali::DevelCameraActor::ProjectionDirection direction);
101 * @copydoc Dali::CameraActor::SetFieldOfView
103 void SetFieldOfView(float fieldOfView);
106 * @copydoc Dali::CameraActor::GetFieldOfView
108 float GetFieldOfView() const;
111 * @brief Sets the orthographic size.
112 * Orthographic size will be used when ProjectoinMode is ORTHOGRAPHIC_PROJECTION.
114 * @param[in] orthographicSize The orthographic size.
116 void SetOrthographicSize(float orthographicSize);
119 * @brief Gets the orthographic size.
121 * The default orthographic size is 400.0f.
122 * @return The orthographic size.
124 float GetOrthographicSize() const;
127 * @copydoc Dali::CameraActor::SetAspectRatio
129 void SetAspectRatio(float aspectRatio);
132 * @copydoc Dali::CameraActor::GetAspectRatio
134 float GetAspectRatio() const;
137 * @copydoc Dali::CameraActor::SetNearClippingPlane
139 void SetNearClippingPlane(float nearClippingPlane);
142 * @copydoc Dali::CameraActor::GetNearClippingPlane
144 float GetNearClippingPlane() const;
147 * @copydoc Dali::CameraActor::SetFarClippingPlane
149 void SetFarClippingPlane(float farClippingPlane);
152 * @copydoc Dali::CameraActor::GetFarClippingPlane
154 float GetFarClippingPlane() const;
157 * @copydoc Dali::CameraActor::SetInvertYAxis
159 void SetInvertYAxis(bool invertYAxis);
162 * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
164 bool GetInvertYAxis() const;
167 * @copydoc Dali::CameraActor::SetPerspectiveProjection()
169 void SetPerspectiveProjection(const Size& size);
172 * @copydoc Dali::CameraActor::SetOrthographicProjection(const Size& size);
174 void SetOrthographicProjection(const Size& size);
177 * Build a picking ray with this camera and given screen coordinates
178 * @param [in] screenCoordinates the ray passed through
179 * @param [in] viewport to use
180 * @param [out] rayOrigin for the picking ray
181 * @param [out] rayDirection for the picking ray
182 * @return true if the building was successful, false if its not possible (camera is not valid for hit testing)
184 bool BuildPickingRay(const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection);
187 * Retrieve the view-matrix; This will only be valid when the actor is on-stage.
188 * @return The view-matrix.
190 const Matrix& GetViewMatrix() const;
193 * Retrieve the projection-matrix; This will only be valid when the actor is on-stage.
194 * @return The projection-matrix.
196 const Matrix& GetProjectionMatrix() const;
199 * Return the scene graph camera
200 * @return The scene graph camera.
202 const SceneGraph::Camera& GetCameraSceneObject() const;
205 * Rotate the projection.
206 * It is used in case that the target buffer direction is different from the window direction.
207 * @param [in] rotationAngle The rotation angle
209 void RotateProjection(int rotationAngle);
211 public: // properties
213 * copydoc Dali::Internal::Object::SetDefaultProperty()
215 void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
218 * copydoc Dali::Internal::Object::GetDefaultProperty()
220 Property::Value GetDefaultProperty(Property::Index index) const override;
223 * copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
225 Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
228 * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
230 void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
233 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
235 const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
238 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
240 const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
244 * Constructor; see also CameraActor::New()
245 * @param node the scene graph node
247 CameraActor(const SceneGraph::Node& node);
250 * A reference counted object may only be deleted by calling Unreference()
252 ~CameraActor() override;
255 * @copydoc Dali::Internal::Actor::OnSceneConnectionInternal()
257 void OnSceneConnectionInternal() override;
260 * @copydoc Internal::Object::OnPropertySet
262 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
265 * @brief Set the camera projection values with mCanvasSize
267 void ApplyDefaultProjection();
271 * @brief Retrieve the CameraActor's field of view from update side.
272 * This is either the last value set, or the currently animating value.
273 * It may be defferent to GetFieldOfView() if the set message hasn't been processed yet.
274 * @return The field of view.
276 float GetCurrentFieldOfView() const;
279 * @brief Retrieve the CameraActor's orthographic size from update side.
280 * This is either the last value set, or the currently animating value.
281 * It may be defferent to GetOrthographicSize() if the set message hasn't been processed yet.
282 * @return The orthographic size.
284 float GetCurrentOrthographicSize() const;
287 * @brief Retrieve the CameraActor's aspect ratio from update side.
288 * This is either the last value set, or the currently animating value.
289 * It may be defferent to GetAspectRatio() if the set message hasn't been processed yet.
290 * @return The aspect ratio.
292 float GetCurrentAspectRatio() const;
295 * @brief Retrieve the CameraActor's near clipping plane distance from update side.
296 * This is either the last value set, or the currently animating value.
297 * It may be defferent to GetNearClippingPlane() if the set message hasn't been processed yet.
298 * @return Near clipping plane distance.
300 float GetCurrentNearClippingPlane() const;
303 * @brief Retrieve the CameraActor's far clipping plane distance from update side.
304 * This is either the last value set, or the currently animating value.
305 * It may be defferent to GetFarClippingPlane() if the set message hasn't been processed yet.
306 * @return Far clipping plane distance.
308 float GetCurrentFarClippingPlane() const;
313 Dali::Camera::Type mType;
314 Dali::Camera::ProjectionMode mProjectionMode;
315 Dali::DevelCameraActor::ProjectionDirection mProjectionDirection;
317 float mOrthographicSize;
319 float mNearClippingPlane;
320 float mFarClippingPlane;
322 bool mPropertyChanged;
325 } // namespace Internal
327 // Helpers for public-api forwarding methods
329 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
331 DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
333 BaseObject& handle = camera.GetBaseObject();
335 return static_cast<Internal::CameraActor&>(handle);
338 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
340 DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
342 const BaseObject& handle = camera.GetBaseObject();
344 return static_cast<const Internal::CameraActor&>(handle);
349 #endif // DALI_INTERNAL_CAMERA_ACTOR_H