Merge "Make Dali::Any move operator + Resolve memory leak." into 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) 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    * @copydoc Dali::CameraActor::SetAspectRatio
111    */
112   void SetAspectRatio(float aspectRatio);
113
114   /**
115    * @copydoc Dali::CameraActor::GetAspectRatio
116    */
117   float GetAspectRatio() const;
118
119   /**
120    * @copydoc Dali::CameraActor::SetNearClippingPlane
121    */
122   void SetNearClippingPlane(float nearClippingPlane);
123
124   /**
125    * @copydoc Dali::CameraActor::GetNearClippingPlane
126    */
127   float GetNearClippingPlane() const;
128
129   /**
130    * @copydoc Dali::CameraActor::SetFarClippingPlane
131    */
132   void SetFarClippingPlane(float farClippingPlane);
133
134   /**
135    * @copydoc Dali::CameraActor::GetFarClippingPlane
136    */
137   float GetFarClippingPlane() const;
138
139   /**
140    * @param leftClippingPlane to use
141    */
142   void SetLeftClippingPlane(float leftClippingPlane);
143
144   /**
145    * @param rightClippingPlane to use
146    */
147   void SetRightClippingPlane(float rightClippingPlane);
148
149   /**
150    * @param topClippingPlane to use
151    */
152   void SetTopClippingPlane(float topClippingPlane);
153
154   /**
155    * @param bottomClippingPlane to use
156    */
157   void SetBottomClippingPlane(float bottomClippingPlane);
158
159   /**
160    * @copydoc Dali::CameraActor::SetInvertYAxis
161    */
162   void SetInvertYAxis(bool invertYAxis);
163
164   /**
165    * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
166    */
167   bool GetInvertYAxis() const;
168
169   /**
170    * @copydoc Dali::CameraActor::SetPerspectiveProjection()
171    */
172   void SetPerspectiveProjection(const Size& size);
173
174   /**
175    * @copydoc Dali::CameraActor::SetOrthographicProjection(const Vector2& size);
176    */
177   void SetOrthographicProjection(const Vector2& size);
178
179   /**
180    * @copydoc Dali::CameraActor::SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
181    */
182   void SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
183
184   /**
185    * Build a picking ray with this camera and given screen coordinates
186    * @param [in] screenCoordinates the ray passed through
187    * @param [in] viewport to use
188    * @param [out] rayOrigin for the picking ray
189    * @param [out] rayDirection for the picking ray
190    * @return true if the building was successful, false if its not possible (camera is not valid for hit testing)
191    */
192   bool BuildPickingRay(const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection);
193
194   /**
195    * Retrieve the view-matrix; This will only be valid when the actor is on-stage.
196    * @return The view-matrix.
197    */
198   const Matrix& GetViewMatrix() const;
199
200   /**
201    * Retrieve the projection-matrix; This will only be valid when the actor is on-stage.
202    * @return The projection-matrix.
203    */
204   const Matrix& GetProjectionMatrix() const;
205
206   /**
207    * Return the scene graph camera (for RenderTask)
208    * @return The scene graph camera.
209    */
210   const SceneGraph::Camera* GetCamera() const;
211
212   /**
213    * Rotate the projection.
214    * It is used in case that the target buffer direction is different from the window direction.
215    * @param [in] rotationAngle The rotation angle
216    */
217   void RotateProjection(int rotationAngle);
218
219 public: // properties
220   /**
221    * copydoc Dali::Internal::Object::SetDefaultProperty()
222    */
223   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
224
225   /**
226    * copydoc Dali::Internal::Object::GetDefaultProperty()
227    */
228   Property::Value GetDefaultProperty(Property::Index index) const override;
229
230   /**
231    * copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
232    */
233   Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
234
235   /**
236    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
237    */
238   const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
239
240 private:
241   /**
242    * Constructor; see also CameraActor::New()
243    * @param node the scene graph node
244    */
245   CameraActor(const SceneGraph::Node& node);
246
247   /**
248    * A reference counted object may only be deleted by calling Unreference()
249    */
250   ~CameraActor() override;
251
252   /**
253    * @copydoc Dali::Internal::Actor::OnInitialize()
254    */
255   void OnInitialize() override;
256
257   /**
258    * @copydoc Dali::Internal::Actor::OnSceneConnectionInternal()
259    */
260   void OnSceneConnectionInternal() override;
261
262   /**
263    * @copydoc Internal::Object::OnPropertySet
264    */
265   void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
266
267 private:                                  // Data
268   const SceneGraph::Camera* mSceneObject; ///< Not owned
269
270   Vector3                                     mTarget;
271   Vector2                                     mCanvasSize;
272   Dali::Camera::Type                          mType;
273   Dali::Camera::ProjectionMode                mProjectionMode;
274   Dali::DevelCameraActor::ProjectionDirection mProjectionDirection;
275   float                                       mFieldOfView;
276   float                                       mAspectRatio;
277   float                                       mNearClippingPlane;
278   float                                       mFarClippingPlane;
279   float                                       mLeftClippingPlane;
280   float                                       mRightClippingPlane;
281   float                                       mTopClippingPlane;
282   float                                       mBottomClippingPlane;
283   bool                                        mInvertYAxis;
284   bool                                        mPropertyChanged;
285 };
286
287 } // namespace Internal
288
289 // Helpers for public-api forwarding methods
290
291 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
292 {
293   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
294
295   BaseObject& handle = camera.GetBaseObject();
296
297   return static_cast<Internal::CameraActor&>(handle);
298 }
299
300 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
301 {
302   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
303
304   const BaseObject& handle = camera.GetBaseObject();
305
306   return static_cast<const Internal::CameraActor&>(handle);
307 }
308
309 } // namespace Dali
310
311 #endif // DALI_INTERNAL_CAMERA_ACTOR_H