Make SceneGraph::Camera as Node + FieldOfView animatable
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / camera-actor-impl.h
1 #ifndef DALI_INTERNAL_CAMERA_ACTOR_H
2 #define DALI_INTERNAL_CAMERA_ACTOR_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUES
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>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 namespace SceneGraph
32 {
33 class Camera;
34 }
35
36 /**
37  * An actor with Camera.
38  */
39 class CameraActor : public Actor
40 {
41 public:
42   /**
43    * Create an initialised camera actor.
44    *
45    * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
46    *
47    * @param[in] size The canvas size.
48    *
49    * @return A smart-pointer to a newly allocated camera actor.
50    */
51   static CameraActorPtr New(const Size& size);
52
53   /**
54    * Sets the reflection plane for the camera
55    *
56    * @param[in] plane Plane parameters
57    *
58    * @note plane.xyz are normal vector of the plane.
59    */
60   void SetReflectByPlane(const Vector4& plane);
61
62   /**
63    * @copydoc Dali::CameraActor::SetTargetPosition
64    */
65   void SetTarget(const Vector3& targetPosition);
66
67   /**
68    * @copydoc Dali::CameraActor::GetTargetPosition
69    */
70   Vector3 GetTarget() const;
71
72   /**
73    * @copydoc Dali::CameraActor::SetType
74    */
75   void SetType(Dali::Camera::Type type);
76
77   /**
78    * @copydoc Dali::CameraActor::GetType
79    */
80   Dali::Camera::Type GetType() const;
81
82   /**
83    * @copydoc Dali::CameraActor::SetProjectionMode
84    */
85   void SetProjectionMode(Dali::Camera::ProjectionMode mode);
86
87   /**
88    * @copydoc Dali::CameraActor::GetProjectionMode
89    */
90   Dali::Camera::ProjectionMode GetProjectionMode() const;
91
92   /**
93    * @brief Set the projection direction
94    *
95    * @param[in] direction Direction of projection
96    */
97   void SetProjectionDirection(Dali::DevelCameraActor::ProjectionDirection direction);
98
99   /**
100    * @copydoc Dali::CameraActor::SetFieldOfView
101    */
102   void SetFieldOfView(float fieldOfView);
103
104   /**
105    * @copydoc Dali::CameraActor::GetFieldOfView
106    */
107   float GetFieldOfView() const;
108
109   /**
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.
113    */
114   float GetCurrentFieldOfView() const;
115
116   /**
117    * @copydoc Dali::CameraActor::SetAspectRatio
118    */
119   void SetAspectRatio(float aspectRatio);
120
121   /**
122    * @copydoc Dali::CameraActor::GetAspectRatio
123    */
124   float GetAspectRatio() const;
125
126   /**
127    * @copydoc Dali::CameraActor::SetNearClippingPlane
128    */
129   void SetNearClippingPlane(float nearClippingPlane);
130
131   /**
132    * @copydoc Dali::CameraActor::GetNearClippingPlane
133    */
134   float GetNearClippingPlane() const;
135
136   /**
137    * @copydoc Dali::CameraActor::SetFarClippingPlane
138    */
139   void SetFarClippingPlane(float farClippingPlane);
140
141   /**
142    * @copydoc Dali::CameraActor::GetFarClippingPlane
143    */
144   float GetFarClippingPlane() const;
145
146   /**
147    * @param leftClippingPlane to use
148    */
149   void SetLeftClippingPlane(float leftClippingPlane);
150
151   /**
152    * @param rightClippingPlane to use
153    */
154   void SetRightClippingPlane(float rightClippingPlane);
155
156   /**
157    * @param topClippingPlane to use
158    */
159   void SetTopClippingPlane(float topClippingPlane);
160
161   /**
162    * @param bottomClippingPlane to use
163    */
164   void SetBottomClippingPlane(float bottomClippingPlane);
165
166   /**
167    * @copydoc Dali::CameraActor::SetInvertYAxis
168    */
169   void SetInvertYAxis(bool invertYAxis);
170
171   /**
172    * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
173    */
174   bool GetInvertYAxis() const;
175
176   /**
177    * @copydoc Dali::CameraActor::SetPerspectiveProjection()
178    */
179   void SetPerspectiveProjection(const Size& size);
180
181   /**
182    * @copydoc Dali::CameraActor::SetOrthographicProjection(const Vector2& size);
183    */
184   void SetOrthographicProjection(const Vector2& size);
185
186   /**
187    * @copydoc Dali::CameraActor::SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
188    */
189   void SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
190
191   /**
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)
198    */
199   bool BuildPickingRay(const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection);
200
201   /**
202    * Retrieve the view-matrix; This will only be valid when the actor is on-stage.
203    * @return The view-matrix.
204    */
205   const Matrix& GetViewMatrix() const;
206
207   /**
208    * Retrieve the projection-matrix; This will only be valid when the actor is on-stage.
209    * @return The projection-matrix.
210    */
211   const Matrix& GetProjectionMatrix() const;
212
213   /**
214    * Return the scene graph camera
215    * @return The scene graph camera.
216    */
217   const SceneGraph::Camera& GetCameraSceneObject() const;
218
219   /**
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
223    */
224   void RotateProjection(int rotationAngle);
225
226 public: // properties
227   /**
228    * copydoc Dali::Internal::Object::SetDefaultProperty()
229    */
230   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
231
232   /**
233    * copydoc Dali::Internal::Object::GetDefaultProperty()
234    */
235   Property::Value GetDefaultProperty(Property::Index index) const override;
236
237   /**
238    * copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
239    */
240   Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
241
242   /**
243    * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
244    */
245   void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
246
247   /**
248    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
249    */
250   const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
251
252   /**
253    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
254    */
255   const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
256
257 private:
258   /**
259    * Constructor; see also CameraActor::New()
260    * @param node the scene graph node
261    */
262   CameraActor(const SceneGraph::Node& node);
263
264   /**
265    * A reference counted object may only be deleted by calling Unreference()
266    */
267   ~CameraActor() override;
268
269   /**
270    * @copydoc Dali::Internal::Actor::OnSceneConnectionInternal()
271    */
272   void OnSceneConnectionInternal() override;
273
274   /**
275    * @copydoc Internal::Object::OnPropertySet
276    */
277   void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
278
279 private: // Data
280   Vector3                                     mTarget;
281   Vector2                                     mCanvasSize;
282   Dali::Camera::Type                          mType;
283   Dali::Camera::ProjectionMode                mProjectionMode;
284   Dali::DevelCameraActor::ProjectionDirection mProjectionDirection;
285   float                                       mFieldOfView;
286   float                                       mAspectRatio;
287   float                                       mNearClippingPlane;
288   float                                       mFarClippingPlane;
289   float                                       mLeftClippingPlane;
290   float                                       mRightClippingPlane;
291   float                                       mTopClippingPlane;
292   float                                       mBottomClippingPlane;
293   bool                                        mInvertYAxis;
294   bool                                        mPropertyChanged;
295 };
296
297 } // namespace Internal
298
299 // Helpers for public-api forwarding methods
300
301 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
302 {
303   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
304
305   BaseObject& handle = camera.GetBaseObject();
306
307   return static_cast<Internal::CameraActor&>(handle);
308 }
309
310 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
311 {
312   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
313
314   const BaseObject& handle = camera.GetBaseObject();
315
316   return static_cast<const Internal::CameraActor&>(handle);
317 }
318
319 } // namespace Dali
320
321 #endif // DALI_INTERNAL_CAMERA_ACTOR_H