[dali_2.3.22] Merge branch 'devel/master'
[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) 2023 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    * If hintFor3D is false, Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
46    *
47    * @param[in] size The canvas size.
48    * @param[in] hintFor3D True if user set hint that this camera used for 3D. Default is false.
49    *
50    * @return A smart-pointer to a newly allocated camera actor.
51    */
52   static CameraActorPtr New(const Size& size, bool hintFor3D = false);
53
54   /**
55    * Sets the reflection plane for the camera
56    *
57    * @param[in] plane Plane parameters
58    *
59    * @note plane.xyz are normal vector of the plane.
60    */
61   void SetReflectByPlane(const Vector4& plane);
62
63   /**
64    * @copydoc Dali::CameraActor::SetTargetPosition
65    */
66   void SetTarget(const Vector3& targetPosition);
67
68   /**
69    * @copydoc Dali::CameraActor::GetTargetPosition
70    */
71   Vector3 GetTarget() const;
72
73   /**
74    * @copydoc Dali::CameraActor::SetType
75    */
76   void SetType(Dali::Camera::Type type);
77
78   /**
79    * @copydoc Dali::CameraActor::GetType
80    */
81   Dali::Camera::Type GetType() const;
82
83   /**
84    * @copydoc Dali::CameraActor::SetProjectionMode
85    */
86   void SetProjectionMode(Dali::Camera::ProjectionMode mode);
87
88   /**
89    * @copydoc Dali::CameraActor::GetProjectionMode
90    */
91   Dali::Camera::ProjectionMode GetProjectionMode() const;
92
93   /**
94    * @brief Set the projection direction
95    *
96    * @param[in] direction Direction of projection
97    */
98   void SetProjectionDirection(Dali::DevelCameraActor::ProjectionDirection direction);
99
100   /**
101    * @copydoc Dali::CameraActor::SetFieldOfView
102    */
103   void SetFieldOfView(float fieldOfView);
104
105   /**
106    * @copydoc Dali::CameraActor::GetFieldOfView
107    */
108   float GetFieldOfView() const;
109
110   /**
111    * @brief Sets the orthographic size.
112    * Orthographic size will be used when ProjectoinMode is ORTHOGRAPHIC_PROJECTION.
113    *
114    * @param[in] orthographicSize The orthographic size.
115    */
116   void SetOrthographicSize(float orthographicSize);
117
118   /**
119    * @brief Gets the orthographic size.
120    *
121    * The default orthographic size is 400.0f.
122    * @return The orthographic size.
123    */
124   float GetOrthographicSize() const;
125
126   /**
127    * @copydoc Dali::CameraActor::SetAspectRatio
128    */
129   void SetAspectRatio(float aspectRatio);
130
131   /**
132    * @copydoc Dali::CameraActor::GetAspectRatio
133    */
134   float GetAspectRatio() const;
135
136   /**
137    * @copydoc Dali::CameraActor::SetNearClippingPlane
138    */
139   void SetNearClippingPlane(float nearClippingPlane);
140
141   /**
142    * @copydoc Dali::CameraActor::GetNearClippingPlane
143    */
144   float GetNearClippingPlane() const;
145
146   /**
147    * @copydoc Dali::CameraActor::SetFarClippingPlane
148    */
149   void SetFarClippingPlane(float farClippingPlane);
150
151   /**
152    * @copydoc Dali::CameraActor::GetFarClippingPlane
153    */
154   float GetFarClippingPlane() const;
155
156   /**
157    * @copydoc Dali::CameraActor::SetInvertYAxis
158    */
159   void SetInvertYAxis(bool invertYAxis);
160
161   /**
162    * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
163    */
164   bool GetInvertYAxis() const;
165
166   /**
167    * @copydoc Dali::CameraActor::SetPerspectiveProjection()
168    */
169   void SetPerspectiveProjection(const Size& size);
170
171   /**
172    * @copydoc Dali::CameraActor::SetOrthographicProjection(const Size& size);
173    */
174   void SetOrthographicProjection(const Size& size);
175
176   /**
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)
183    */
184   bool BuildPickingRay(const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection);
185
186   /**
187    * Retrieve the view-matrix; This will only be valid when the actor is on-stage.
188    * @return The view-matrix.
189    */
190   const Matrix& GetViewMatrix() const;
191
192   /**
193    * Retrieve the projection-matrix; This will only be valid when the actor is on-stage.
194    * @return The projection-matrix.
195    */
196   const Matrix& GetProjectionMatrix() const;
197
198   /**
199    * Return the scene graph camera
200    * @return The scene graph camera.
201    */
202   const SceneGraph::Camera& GetCameraSceneObject() const;
203
204   /**
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
208    */
209   void RotateProjection(int rotationAngle);
210
211 public: // properties
212   /**
213    * copydoc Dali::Internal::Object::SetDefaultProperty()
214    */
215   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
216
217   /**
218    * copydoc Dali::Internal::Object::GetDefaultProperty()
219    */
220   Property::Value GetDefaultProperty(Property::Index index) const override;
221
222   /**
223    * copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
224    */
225   Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
226
227   /**
228    * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
229    */
230   void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
231
232   /**
233    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
234    */
235   const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
236
237   /**
238    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
239    */
240   const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
241
242 private:
243   /**
244    * Constructor; see also CameraActor::New()
245    * @param node the scene graph node
246    */
247   CameraActor(const SceneGraph::Node& node);
248
249   /**
250    * A reference counted object may only be deleted by calling Unreference()
251    */
252   ~CameraActor() override;
253
254   /**
255    * @copydoc Dali::Internal::Actor::OnSceneConnectionInternal()
256    */
257   void OnSceneConnectionInternal() override;
258
259   /**
260    * @copydoc Internal::Object::OnPropertySet
261    */
262   void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
263
264   /**
265    * @brief Set the camera projection values with mCanvasSize
266    */
267   void ApplyDefaultProjection();
268
269 private:
270   /**
271    * @brief Retrieve the CameraActor's field of view from update side.
272    * This is either the last value set, or the currently animating value.
273    * It may be defferent to GetFieldOfView() if the set message hasn't been processed yet.
274    * @return The field of view.
275    */
276   float GetCurrentFieldOfView() const;
277
278   /**
279    * @brief Retrieve the CameraActor's orthographic size from update side.
280    * This is either the last value set, or the currently animating value.
281    * It may be defferent to GetOrthographicSize() if the set message hasn't been processed yet.
282    * @return The orthographic size.
283    */
284   float GetCurrentOrthographicSize() const;
285
286   /**
287    * @brief Retrieve the CameraActor's aspect ratio from update side.
288    * This is either the last value set, or the currently animating value.
289    * It may be defferent to GetAspectRatio() if the set message hasn't been processed yet.
290    * @return The aspect ratio.
291    */
292   float GetCurrentAspectRatio() const;
293
294   /**
295    * @brief Retrieve the CameraActor's near clipping plane distance from update side.
296    * This is either the last value set, or the currently animating value.
297    * It may be defferent to GetNearClippingPlane() if the set message hasn't been processed yet.
298    * @return Near clipping plane distance.
299    */
300   float GetCurrentNearClippingPlane() const;
301
302   /**
303    * @brief Retrieve the CameraActor's far clipping plane distance from update side.
304    * This is either the last value set, or the currently animating value.
305    * It may be defferent to GetFarClippingPlane() if the set message hasn't been processed yet.
306    * @return Far clipping plane distance.
307    */
308   float GetCurrentFarClippingPlane() const;
309
310 private: // Data
311   Vector3                                     mTarget;
312   Vector2                                     mCanvasSize;
313   Dali::Camera::Type                          mType;
314   Dali::Camera::ProjectionMode                mProjectionMode;
315   Dali::DevelCameraActor::ProjectionDirection mProjectionDirection;
316   float                                       mFieldOfView;
317   float                                       mOrthographicSize;
318   float                                       mAspectRatio;
319   float                                       mNearClippingPlane;
320   float                                       mFarClippingPlane;
321   bool                                        mInvertYAxis;
322   bool                                        mPropertyChanged;
323 };
324
325 } // namespace Internal
326
327 // Helpers for public-api forwarding methods
328
329 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
330 {
331   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
332
333   BaseObject& handle = camera.GetBaseObject();
334
335   return static_cast<Internal::CameraActor&>(handle);
336 }
337
338 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
339 {
340   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
341
342   const BaseObject& handle = camera.GetBaseObject();
343
344   return static_cast<const Internal::CameraActor&>(handle);
345 }
346
347 } // namespace Dali
348
349 #endif // DALI_INTERNAL_CAMERA_ACTOR_H