6ecb3ed066b390d39c570f616ffe536ed7b2a6f5
[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 Sets the orthographic size.
111    * Orthographic size will be used when ProjectoinMode is ORTHOGRAPHIC_PROJECTION.
112    *
113    * @param[in] orthographicSize The orthographic size.
114    */
115   void SetOrthographicSize(float orthographicSize);
116
117   /**
118    * @brief Gets the orthographic size.
119    *
120    * The default orthographic size is 400.0f.
121    * @return The orthographic size.
122    */
123   float GetOrthographicSize() const;
124
125   /**
126    * @copydoc Dali::CameraActor::SetAspectRatio
127    */
128   void SetAspectRatio(float aspectRatio);
129
130   /**
131    * @copydoc Dali::CameraActor::GetAspectRatio
132    */
133   float GetAspectRatio() const;
134
135   /**
136    * @copydoc Dali::CameraActor::SetNearClippingPlane
137    */
138   void SetNearClippingPlane(float nearClippingPlane);
139
140   /**
141    * @copydoc Dali::CameraActor::GetNearClippingPlane
142    */
143   float GetNearClippingPlane() const;
144
145   /**
146    * @copydoc Dali::CameraActor::SetFarClippingPlane
147    */
148   void SetFarClippingPlane(float farClippingPlane);
149
150   /**
151    * @copydoc Dali::CameraActor::GetFarClippingPlane
152    */
153   float GetFarClippingPlane() const;
154
155   /**
156    * @copydoc Dali::CameraActor::SetInvertYAxis
157    */
158   void SetInvertYAxis(bool invertYAxis);
159
160   /**
161    * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
162    */
163   bool GetInvertYAxis() const;
164
165   /**
166    * @copydoc Dali::CameraActor::SetPerspectiveProjection()
167    */
168   void SetPerspectiveProjection(const Size& size);
169
170   /**
171    * @copydoc Dali::CameraActor::SetOrthographicProjection(const Size& size);
172    */
173   void SetOrthographicProjection(const Size& size);
174
175   /**
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)
182    */
183   bool BuildPickingRay(const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection);
184
185   /**
186    * Retrieve the view-matrix; This will only be valid when the actor is on-stage.
187    * @return The view-matrix.
188    */
189   const Matrix& GetViewMatrix() const;
190
191   /**
192    * Retrieve the projection-matrix; This will only be valid when the actor is on-stage.
193    * @return The projection-matrix.
194    */
195   const Matrix& GetProjectionMatrix() const;
196
197   /**
198    * Return the scene graph camera
199    * @return The scene graph camera.
200    */
201   const SceneGraph::Camera& GetCameraSceneObject() const;
202
203   /**
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
207    */
208   void RotateProjection(int rotationAngle);
209
210 public: // properties
211   /**
212    * copydoc Dali::Internal::Object::SetDefaultProperty()
213    */
214   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
215
216   /**
217    * copydoc Dali::Internal::Object::GetDefaultProperty()
218    */
219   Property::Value GetDefaultProperty(Property::Index index) const override;
220
221   /**
222    * copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
223    */
224   Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
225
226   /**
227    * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
228    */
229   void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
230
231   /**
232    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
233    */
234   const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
235
236   /**
237    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
238    */
239   const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
240
241 private:
242   /**
243    * Constructor; see also CameraActor::New()
244    * @param node the scene graph node
245    */
246   CameraActor(const SceneGraph::Node& node);
247
248   /**
249    * A reference counted object may only be deleted by calling Unreference()
250    */
251   ~CameraActor() override;
252
253   /**
254    * @copydoc Dali::Internal::Actor::OnSceneConnectionInternal()
255    */
256   void OnSceneConnectionInternal() override;
257
258   /**
259    * @copydoc Internal::Object::OnPropertySet
260    */
261   void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
262
263   /**
264    * @brief Set the camera projection values with mCanvasSize
265    */
266   void ApplyDefaultProjection();
267
268 private:
269   /**
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.
274    */
275   float GetCurrentFieldOfView() const;
276
277   /**
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.
282    */
283   float GetCurrentOrthographicSize() const;
284
285   /**
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.
290    */
291   float GetCurrentAspectRatio() const;
292
293 private: // Data
294   Vector3                                     mTarget;
295   Vector2                                     mCanvasSize;
296   Dali::Camera::Type                          mType;
297   Dali::Camera::ProjectionMode                mProjectionMode;
298   Dali::DevelCameraActor::ProjectionDirection mProjectionDirection;
299   float                                       mFieldOfView;
300   float                                       mOrthographicSize;
301   float                                       mAspectRatio;
302   float                                       mNearClippingPlane;
303   float                                       mFarClippingPlane;
304   bool                                        mInvertYAxis;
305   bool                                        mPropertyChanged;
306 };
307
308 } // namespace Internal
309
310 // Helpers for public-api forwarding methods
311
312 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
313 {
314   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
315
316   BaseObject& handle = camera.GetBaseObject();
317
318   return static_cast<Internal::CameraActor&>(handle);
319 }
320
321 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
322 {
323   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
324
325   const BaseObject& handle = camera.GetBaseObject();
326
327   return static_cast<const Internal::CameraActor&>(handle);
328 }
329
330 } // namespace Dali
331
332 #endif // DALI_INTERNAL_CAMERA_ACTOR_H