1 #ifndef DALI_INTERNAL_CAMERA_ACTOR_H
2 #define DALI_INTERNAL_CAMERA_ACTOR_H
5 * Copyright (c) 2022 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 * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
47 * @param[in] size The canvas size.
49 * @return A smart-pointer to a newly allocated camera actor.
51 static CameraActorPtr New(const Size& size);
54 * Sets the reflection plane for the camera
56 * @param[in] plane Plane parameters
58 * @note plane.xyz are normal vector of the plane.
60 void SetReflectByPlane(const Vector4& plane);
63 * @copydoc Dali::CameraActor::SetTargetPosition
65 void SetTarget(const Vector3& targetPosition);
68 * @copydoc Dali::CameraActor::GetTargetPosition
70 Vector3 GetTarget() const;
73 * @copydoc Dali::CameraActor::SetType
75 void SetType(Dali::Camera::Type type);
78 * @copydoc Dali::CameraActor::GetType
80 Dali::Camera::Type GetType() const;
83 * @copydoc Dali::CameraActor::SetProjectionMode
85 void SetProjectionMode(Dali::Camera::ProjectionMode mode);
88 * @copydoc Dali::CameraActor::GetProjectionMode
90 Dali::Camera::ProjectionMode GetProjectionMode() const;
93 * @brief Set the projection direction
95 * @param[in] direction Direction of projection
97 void SetProjectionDirection(Dali::DevelCameraActor::ProjectionDirection direction);
100 * @copydoc Dali::CameraActor::SetFieldOfView
102 void SetFieldOfView(float fieldOfView);
105 * @copydoc Dali::CameraActor::GetFieldOfView
107 float GetFieldOfView() const;
110 * @copydoc Dali::CameraActor::SetAspectRatio
112 void SetAspectRatio(float aspectRatio);
115 * @copydoc Dali::CameraActor::GetAspectRatio
117 float GetAspectRatio() const;
120 * @copydoc Dali::CameraActor::SetNearClippingPlane
122 void SetNearClippingPlane(float nearClippingPlane);
125 * @copydoc Dali::CameraActor::GetNearClippingPlane
127 float GetNearClippingPlane() const;
130 * @copydoc Dali::CameraActor::SetFarClippingPlane
132 void SetFarClippingPlane(float farClippingPlane);
135 * @copydoc Dali::CameraActor::GetFarClippingPlane
137 float GetFarClippingPlane() const;
140 * @param leftClippingPlane to use
142 void SetLeftClippingPlane(float leftClippingPlane);
145 * @param rightClippingPlane to use
147 void SetRightClippingPlane(float rightClippingPlane);
150 * @param topClippingPlane to use
152 void SetTopClippingPlane(float topClippingPlane);
155 * @param bottomClippingPlane to use
157 void SetBottomClippingPlane(float bottomClippingPlane);
160 * @copydoc Dali::CameraActor::SetInvertYAxis
162 void SetInvertYAxis(bool invertYAxis);
165 * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
167 bool GetInvertYAxis() const;
170 * @copydoc Dali::CameraActor::SetPerspectiveProjection()
172 void SetPerspectiveProjection(const Size& size);
175 * @copydoc Dali::CameraActor::SetOrthographicProjection(const Vector2& size);
177 void SetOrthographicProjection(const Vector2& size);
180 * @copydoc Dali::CameraActor::SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
182 void SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
185 * Build a picking ray with this camera and given screen coordinates
186 * @param [in] screenCoordinates the ray passed through
187 * @param [in] viewport to use
188 * @param [out] rayOrigin for the picking ray
189 * @param [out] rayDirection for the picking ray
190 * @return true if the building was successful, false if its not possible (camera is not valid for hit testing)
192 bool BuildPickingRay(const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection);
195 * Retrieve the view-matrix; This will only be valid when the actor is on-stage.
196 * @return The view-matrix.
198 const Matrix& GetViewMatrix() const;
201 * Retrieve the projection-matrix; This will only be valid when the actor is on-stage.
202 * @return The projection-matrix.
204 const Matrix& GetProjectionMatrix() const;
207 * Return the scene graph camera (for RenderTask)
208 * @return The scene graph camera.
210 const SceneGraph::Camera* GetCamera() const;
213 * Rotate the projection.
214 * It is used in case that the target buffer direction is different from the window direction.
215 * @param [in] rotationAngle The rotation angle
217 void RotateProjection(int rotationAngle);
219 public: // properties
221 * copydoc Dali::Internal::Object::SetDefaultProperty()
223 void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
226 * copydoc Dali::Internal::Object::GetDefaultProperty()
228 Property::Value GetDefaultProperty(Property::Index index) const override;
231 * copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
233 Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
236 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
238 const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
242 * Constructor; see also CameraActor::New()
243 * @param node the scene graph node
245 CameraActor(const SceneGraph::Node& node);
248 * A reference counted object may only be deleted by calling Unreference()
250 ~CameraActor() override;
253 * @copydoc Dali::Internal::Actor::OnInitialize()
255 void OnInitialize() override;
258 * @copydoc Dali::Internal::Actor::OnSceneConnectionInternal()
260 void OnSceneConnectionInternal() override;
263 * @copydoc Internal::Object::OnPropertySet
265 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
268 const SceneGraph::Camera* mSceneObject; ///< Not owned
272 Dali::Camera::Type mType;
273 Dali::Camera::ProjectionMode mProjectionMode;
274 Dali::DevelCameraActor::ProjectionDirection mProjectionDirection;
277 float mNearClippingPlane;
278 float mFarClippingPlane;
279 float mLeftClippingPlane;
280 float mRightClippingPlane;
281 float mTopClippingPlane;
282 float mBottomClippingPlane;
284 bool mPropertyChanged;
287 } // namespace Internal
289 // Helpers for public-api forwarding methods
291 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
293 DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
295 BaseObject& handle = camera.GetBaseObject();
297 return static_cast<Internal::CameraActor&>(handle);
300 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
302 DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
304 const BaseObject& handle = camera.GetBaseObject();
306 return static_cast<const Internal::CameraActor&>(handle);
311 #endif // DALI_INTERNAL_CAMERA_ACTOR_H