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 Sets the orthographic size.
111 * Orthographic size will be used when ProjectoinMode is ORTHOGRAPHIC_PROJECTION.
113 * @param[in] orthographicSize The orthographic size.
115 void SetOrthographicSize(float orthographicSize);
118 * @brief Gets the orthographic size.
120 * The default orthographic size is 400.0f.
121 * @return The orthographic size.
123 float GetOrthographicSize() const;
126 * @copydoc Dali::CameraActor::SetAspectRatio
128 void SetAspectRatio(float aspectRatio);
131 * @copydoc Dali::CameraActor::GetAspectRatio
133 float GetAspectRatio() const;
136 * @copydoc Dali::CameraActor::SetNearClippingPlane
138 void SetNearClippingPlane(float nearClippingPlane);
141 * @copydoc Dali::CameraActor::GetNearClippingPlane
143 float GetNearClippingPlane() const;
146 * @copydoc Dali::CameraActor::SetFarClippingPlane
148 void SetFarClippingPlane(float farClippingPlane);
151 * @copydoc Dali::CameraActor::GetFarClippingPlane
153 float GetFarClippingPlane() const;
156 * @copydoc Dali::CameraActor::SetInvertYAxis
158 void SetInvertYAxis(bool invertYAxis);
161 * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
163 bool GetInvertYAxis() const;
166 * @copydoc Dali::CameraActor::SetPerspectiveProjection()
168 void SetPerspectiveProjection(const Size& size);
171 * @copydoc Dali::CameraActor::SetOrthographicProjection(const Size& size);
173 void SetOrthographicProjection(const Size& size);
176 * Build a picking ray with this camera and given screen coordinates
177 * @param [in] screenCoordinates the ray passed through
178 * @param [in] viewport to use
179 * @param [out] rayOrigin for the picking ray
180 * @param [out] rayDirection for the picking ray
181 * @return true if the building was successful, false if its not possible (camera is not valid for hit testing)
183 bool BuildPickingRay(const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection);
186 * Retrieve the view-matrix; This will only be valid when the actor is on-stage.
187 * @return The view-matrix.
189 const Matrix& GetViewMatrix() const;
192 * Retrieve the projection-matrix; This will only be valid when the actor is on-stage.
193 * @return The projection-matrix.
195 const Matrix& GetProjectionMatrix() const;
198 * Return the scene graph camera
199 * @return The scene graph camera.
201 const SceneGraph::Camera& GetCameraSceneObject() const;
204 * Rotate the projection.
205 * It is used in case that the target buffer direction is different from the window direction.
206 * @param [in] rotationAngle The rotation angle
208 void RotateProjection(int rotationAngle);
210 public: // properties
212 * copydoc Dali::Internal::Object::SetDefaultProperty()
214 void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
217 * copydoc Dali::Internal::Object::GetDefaultProperty()
219 Property::Value GetDefaultProperty(Property::Index index) const override;
222 * copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
224 Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
227 * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
229 void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
232 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
234 const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
237 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
239 const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
243 * Constructor; see also CameraActor::New()
244 * @param node the scene graph node
246 CameraActor(const SceneGraph::Node& node);
249 * A reference counted object may only be deleted by calling Unreference()
251 ~CameraActor() override;
254 * @copydoc Dali::Internal::Actor::OnSceneConnectionInternal()
256 void OnSceneConnectionInternal() override;
259 * @copydoc Internal::Object::OnPropertySet
261 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
264 * @brief Set the camera projection values with mCanvasSize
266 void ApplyDefaultProjection();
270 * @brief Retrieve the CameraActor's field of view from update side.
271 * This is either the last value set, or the currently animating value.
272 * It may be defferent to GetFieldOfView() if the set message hasn't been processed yet.
273 * @return The field of view.
275 float GetCurrentFieldOfView() const;
278 * @brief Retrieve the CameraActor's orthographic size from update side.
279 * This is either the last value set, or the currently animating value.
280 * It may be defferent to GetOrthographicSize() if the set message hasn't been processed yet.
281 * @return The orthographic size.
283 float GetCurrentOrthographicSize() const;
286 * @brief Retrieve the CameraActor's aspect ratio from update side.
287 * This is either the last value set, or the currently animating value.
288 * It may be defferent to GetAspectRatio() if the set message hasn't been processed yet.
289 * @return The aspect ratio.
291 float GetCurrentAspectRatio() const;
296 Dali::Camera::Type mType;
297 Dali::Camera::ProjectionMode mProjectionMode;
298 Dali::DevelCameraActor::ProjectionDirection mProjectionDirection;
300 float mOrthographicSize;
302 float mNearClippingPlane;
303 float mFarClippingPlane;
305 bool mPropertyChanged;
308 } // namespace Internal
310 // Helpers for public-api forwarding methods
312 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
314 DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
316 BaseObject& handle = camera.GetBaseObject();
318 return static_cast<Internal::CameraActor&>(handle);
321 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
323 DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
325 const BaseObject& handle = camera.GetBaseObject();
327 return static_cast<const Internal::CameraActor&>(handle);
332 #endif // DALI_INTERNAL_CAMERA_ACTOR_H