Do not reset properties when properties are explicitly set
[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) 2021 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/internal/event/actors/actor-declarations.h>
23 #include <dali/internal/event/actors/actor-impl.h>
24 #include <dali/public-api/actors/camera-actor.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 namespace SceneGraph
31 {
32 class Camera;
33 }
34
35 /**
36  * An actor with Camera.
37  */
38 class CameraActor : public Actor
39 {
40 public:
41   /**
42    * Create an initialised camera actor.
43    *
44    * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
45    *
46    * @param[in] size The canvas size.
47    *
48    * @return A smart-pointer to a newly allocated camera actor.
49    */
50   static CameraActorPtr New(const Size& size);
51
52   /**
53    * Sets the reflection plane for the camera
54    *
55    * @param[in] plane Plane parameters
56    *
57    * @note plane.xyz are normal vector of the plane.
58    */
59   void SetReflectByPlane(const Vector4& plane);
60
61   /**
62    * @copydoc Dali::CameraActor::SetTargetPosition
63    */
64   void SetTarget(const Vector3& targetPosition);
65
66   /**
67    * @copydoc Dali::CameraActor::GetTargetPosition
68    */
69   Vector3 GetTarget() const;
70
71   /**
72    * @copydoc Dali::CameraActor::SetType
73    */
74   void SetType(Dali::Camera::Type type);
75
76   /**
77    * @copydoc Dali::CameraActor::GetType
78    */
79   Dali::Camera::Type GetType() const;
80
81   /**
82    * @copydoc Dali::CameraActor::SetProjectionMode
83    */
84   void SetProjectionMode(Dali::Camera::ProjectionMode mode);
85
86   /**
87    * @copydoc Dali::CameraActor::GetProjectionMode
88    */
89   Dali::Camera::ProjectionMode GetProjectionMode() const;
90
91   /**
92    * @copydoc Dali::CameraActor::SetFieldOfView
93    */
94   void SetFieldOfView(float fieldOfView);
95
96   /**
97    * @copydoc Dali::CameraActor::GetFieldOfView
98    */
99   float GetFieldOfView() const;
100
101   /**
102    * @copydoc Dali::CameraActor::SetAspectRatio
103    */
104   void SetAspectRatio(float aspectRatio);
105
106   /**
107    * @copydoc Dali::CameraActor::GetAspectRatio
108    */
109   float GetAspectRatio() const;
110
111   /**
112    * @copydoc Dali::CameraActor::SetNearClippingPlane
113    */
114   void SetNearClippingPlane(float nearClippingPlane);
115
116   /**
117    * @copydoc Dali::CameraActor::GetNearClippingPlane
118    */
119   float GetNearClippingPlane() const;
120
121   /**
122    * @copydoc Dali::CameraActor::SetFarClippingPlane
123    */
124   void SetFarClippingPlane(float farClippingPlane);
125
126   /**
127    * @copydoc Dali::CameraActor::GetFarClippingPlane
128    */
129   float GetFarClippingPlane() const;
130
131   /**
132    * @param leftClippingPlane to use
133    */
134   void SetLeftClippingPlane(float leftClippingPlane);
135
136   /**
137    * @param rightClippingPlane to use
138    */
139   void SetRightClippingPlane(float rightClippingPlane);
140
141   /**
142    * @param topClippingPlane to use
143    */
144   void SetTopClippingPlane(float topClippingPlane);
145
146   /**
147    * @param bottomClippingPlane to use
148    */
149   void SetBottomClippingPlane(float bottomClippingPlane);
150
151   /**
152    * @copydoc Dali::CameraActor::SetInvertYAxis
153    */
154   void SetInvertYAxis(bool invertYAxis);
155
156   /**
157    * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
158    */
159   bool GetInvertYAxis() const;
160
161   /**
162    * @copydoc Dali::CameraActor::SetPerspectiveProjection()
163    */
164   void SetPerspectiveProjection(const Size& size);
165
166   /**
167    * @copydoc Dali::CameraActor::SetOrthographicProjection(const Vector2& size);
168    */
169   void SetOrthographicProjection(const Vector2& size);
170
171   /**
172    * @copydoc Dali::CameraActor::SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
173    */
174   void SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
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 (for RenderTask)
200    * @return The scene graph camera.
201    */
202   const SceneGraph::Camera* GetCamera() 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::GetSceneObjectInputProperty()
229    */
230   const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
231
232 private:
233   /**
234    * Constructor; see also CameraActor::New()
235    * @param node the scene graph node
236    */
237   CameraActor(const SceneGraph::Node& node);
238
239   /**
240    * A reference counted object may only be deleted by calling Unreference()
241    */
242   ~CameraActor() override;
243
244   /**
245    * @copydoc Dali::Internal::Actor::OnInitialize()
246    */
247   void OnInitialize() override;
248
249   /**
250    * @copydoc Dali::Internal::Actor::OnSceneConnectionInternal()
251    */
252   void OnSceneConnectionInternal() override;
253
254   /**
255    * @copydoc Internal::Object::OnPropertySet
256    */
257   void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
258
259 private:                                  // Data
260   const SceneGraph::Camera* mSceneObject; ///< Not owned
261
262   Vector3                      mTarget;
263   Vector2                      mCanvasSize;
264   Dali::Camera::Type           mType;
265   Dali::Camera::ProjectionMode mProjectionMode;
266   float                        mFieldOfView;
267   float                        mAspectRatio;
268   float                        mNearClippingPlane;
269   float                        mFarClippingPlane;
270   float                        mLeftClippingPlane;
271   float                        mRightClippingPlane;
272   float                        mTopClippingPlane;
273   float                        mBottomClippingPlane;
274   bool                         mInvertYAxis;
275   bool                         mPropertyChanged;
276 };
277
278 } // namespace Internal
279
280 // Helpers for public-api forwarding methods
281
282 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
283 {
284   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
285
286   BaseObject& handle = camera.GetBaseObject();
287
288   return static_cast<Internal::CameraActor&>(handle);
289 }
290
291 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
292 {
293   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
294
295   const BaseObject& handle = camera.GetBaseObject();
296
297   return static_cast<const Internal::CameraActor&>(handle);
298 }
299
300 } // namespace Dali
301
302 #endif // DALI_INTERNAL_CAMERA_ACTOR_H