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 * @brief Retrieve the CameraActor's field of view from update side.
111 * This field of view will be the fov set or animating but will be a frame behind.
112 * @return The field of view.
114 float GetCurrentFieldOfView() const;
117 * @copydoc Dali::CameraActor::SetAspectRatio
119 void SetAspectRatio(float aspectRatio);
122 * @copydoc Dali::CameraActor::GetAspectRatio
124 float GetAspectRatio() const;
127 * @copydoc Dali::CameraActor::SetNearClippingPlane
129 void SetNearClippingPlane(float nearClippingPlane);
132 * @copydoc Dali::CameraActor::GetNearClippingPlane
134 float GetNearClippingPlane() const;
137 * @copydoc Dali::CameraActor::SetFarClippingPlane
139 void SetFarClippingPlane(float farClippingPlane);
142 * @copydoc Dali::CameraActor::GetFarClippingPlane
144 float GetFarClippingPlane() const;
147 * @param leftClippingPlane to use
149 void SetLeftClippingPlane(float leftClippingPlane);
152 * @param rightClippingPlane to use
154 void SetRightClippingPlane(float rightClippingPlane);
157 * @param topClippingPlane to use
159 void SetTopClippingPlane(float topClippingPlane);
162 * @param bottomClippingPlane to use
164 void SetBottomClippingPlane(float bottomClippingPlane);
167 * @copydoc Dali::CameraActor::SetInvertYAxis
169 void SetInvertYAxis(bool invertYAxis);
172 * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
174 bool GetInvertYAxis() const;
177 * @copydoc Dali::CameraActor::SetPerspectiveProjection()
179 void SetPerspectiveProjection(const Size& size);
182 * @copydoc Dali::CameraActor::SetOrthographicProjection(const Vector2& size);
184 void SetOrthographicProjection(const Vector2& size);
187 * @copydoc Dali::CameraActor::SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
189 void SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
192 * Build a picking ray with this camera and given screen coordinates
193 * @param [in] screenCoordinates the ray passed through
194 * @param [in] viewport to use
195 * @param [out] rayOrigin for the picking ray
196 * @param [out] rayDirection for the picking ray
197 * @return true if the building was successful, false if its not possible (camera is not valid for hit testing)
199 bool BuildPickingRay(const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection);
202 * Retrieve the view-matrix; This will only be valid when the actor is on-stage.
203 * @return The view-matrix.
205 const Matrix& GetViewMatrix() const;
208 * Retrieve the projection-matrix; This will only be valid when the actor is on-stage.
209 * @return The projection-matrix.
211 const Matrix& GetProjectionMatrix() const;
214 * Return the scene graph camera
215 * @return The scene graph camera.
217 const SceneGraph::Camera& GetCameraSceneObject() const;
220 * Rotate the projection.
221 * It is used in case that the target buffer direction is different from the window direction.
222 * @param [in] rotationAngle The rotation angle
224 void RotateProjection(int rotationAngle);
226 public: // properties
228 * copydoc Dali::Internal::Object::SetDefaultProperty()
230 void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
233 * copydoc Dali::Internal::Object::GetDefaultProperty()
235 Property::Value GetDefaultProperty(Property::Index index) const override;
238 * copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
240 Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
243 * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
245 void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
248 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
250 const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
253 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
255 const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
259 * Constructor; see also CameraActor::New()
260 * @param node the scene graph node
262 CameraActor(const SceneGraph::Node& node);
265 * A reference counted object may only be deleted by calling Unreference()
267 ~CameraActor() override;
270 * @copydoc Dali::Internal::Actor::OnSceneConnectionInternal()
272 void OnSceneConnectionInternal() override;
275 * @copydoc Internal::Object::OnPropertySet
277 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
282 Dali::Camera::Type mType;
283 Dali::Camera::ProjectionMode mProjectionMode;
284 Dali::DevelCameraActor::ProjectionDirection mProjectionDirection;
287 float mNearClippingPlane;
288 float mFarClippingPlane;
289 float mLeftClippingPlane;
290 float mRightClippingPlane;
291 float mTopClippingPlane;
292 float mBottomClippingPlane;
294 bool mPropertyChanged;
297 } // namespace Internal
299 // Helpers for public-api forwarding methods
301 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
303 DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
305 BaseObject& handle = camera.GetBaseObject();
307 return static_cast<Internal::CameraActor&>(handle);
310 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
312 DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
314 const BaseObject& handle = camera.GetBaseObject();
316 return static_cast<const Internal::CameraActor&>(handle);
321 #endif // DALI_INTERNAL_CAMERA_ACTOR_H