1 #ifndef DALI_INTERNAL_CAMERA_ACTOR_H
2 #define DALI_INTERNAL_CAMERA_ACTOR_H
5 * Copyright (c) 2021 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/internal/event/actors/actor-declarations.h>
23 #include <dali/internal/event/actors/actor-impl.h>
24 #include <dali/public-api/actors/camera-actor.h>
36 * An actor with Camera.
38 class CameraActor : public Actor
42 * Create an initialised camera actor.
44 * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
46 * @param[in] size The canvas size.
48 * @return A smart-pointer to a newly allocated camera actor.
50 static CameraActorPtr New(const Size& size);
53 * Sets the reflection plane for the camera
55 * @param[in] plane Plane parameters
57 * @note plane.xyz are normal vector of the plane.
59 void SetReflectByPlane(const Vector4& plane);
62 * @copydoc Dali::CameraActor::SetTargetPosition
64 void SetTarget(const Vector3& targetPosition);
67 * @copydoc Dali::CameraActor::GetTargetPosition
69 Vector3 GetTarget() const;
72 * @copydoc Dali::CameraActor::SetType
74 void SetType(Dali::Camera::Type type);
77 * @copydoc Dali::CameraActor::GetType
79 Dali::Camera::Type GetType() const;
82 * @copydoc Dali::CameraActor::SetProjectionMode
84 void SetProjectionMode(Dali::Camera::ProjectionMode mode);
87 * @copydoc Dali::CameraActor::GetProjectionMode
89 Dali::Camera::ProjectionMode GetProjectionMode() const;
92 * @copydoc Dali::CameraActor::SetFieldOfView
94 void SetFieldOfView(float fieldOfView);
97 * @copydoc Dali::CameraActor::GetFieldOfView
99 float GetFieldOfView() const;
102 * @copydoc Dali::CameraActor::SetAspectRatio
104 void SetAspectRatio(float aspectRatio);
107 * @copydoc Dali::CameraActor::GetAspectRatio
109 float GetAspectRatio() const;
112 * @copydoc Dali::CameraActor::SetNearClippingPlane
114 void SetNearClippingPlane(float nearClippingPlane);
117 * @copydoc Dali::CameraActor::GetNearClippingPlane
119 float GetNearClippingPlane() const;
122 * @copydoc Dali::CameraActor::SetFarClippingPlane
124 void SetFarClippingPlane(float farClippingPlane);
127 * @copydoc Dali::CameraActor::GetFarClippingPlane
129 float GetFarClippingPlane() const;
132 * @param leftClippingPlane to use
134 void SetLeftClippingPlane(float leftClippingPlane);
137 * @param rightClippingPlane to use
139 void SetRightClippingPlane(float rightClippingPlane);
142 * @param topClippingPlane to use
144 void SetTopClippingPlane(float topClippingPlane);
147 * @param bottomClippingPlane to use
149 void SetBottomClippingPlane(float bottomClippingPlane);
152 * @copydoc Dali::CameraActor::SetInvertYAxis
154 void SetInvertYAxis(bool invertYAxis);
157 * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
159 bool GetInvertYAxis() const;
162 * @copydoc Dali::CameraActor::SetPerspectiveProjection()
164 void SetPerspectiveProjection(const Size& size);
167 * @copydoc Dali::CameraActor::SetOrthographicProjection(const Vector2& size);
169 void SetOrthographicProjection(const Vector2& size);
172 * @copydoc Dali::CameraActor::SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
174 void SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
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 (for RenderTask)
200 * @return The scene graph camera.
202 const SceneGraph::Camera* GetCamera() 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::GetSceneObjectInputProperty()
230 const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
234 * Constructor; see also CameraActor::New()
235 * @param node the scene graph node
237 CameraActor(const SceneGraph::Node& node);
240 * A reference counted object may only be deleted by calling Unreference()
242 ~CameraActor() override;
245 * @copydoc Dali::Internal::Actor::OnInitialize()
247 void OnInitialize() override;
250 * @copydoc Dali::Internal::Actor::OnSceneConnectionInternal()
252 void OnSceneConnectionInternal() override;
255 const SceneGraph::Camera* mSceneObject; ///< Not owned
259 Dali::Camera::Type mType;
260 Dali::Camera::ProjectionMode mProjectionMode;
263 float mNearClippingPlane;
264 float mFarClippingPlane;
265 float mLeftClippingPlane;
266 float mRightClippingPlane;
267 float mTopClippingPlane;
268 float mBottomClippingPlane;
272 } // namespace Internal
274 // Helpers for public-api forwarding methods
276 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
278 DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
280 BaseObject& handle = camera.GetBaseObject();
282 return static_cast<Internal::CameraActor&>(handle);
285 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
287 DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
289 const BaseObject& handle = camera.GetBaseObject();
291 return static_cast<const Internal::CameraActor&>(handle);
296 #endif // DALI_INTERNAL_CAMERA_ACTOR_H