e320d761f94e739bdce2e5bd11600beb63654b96
[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) 2019 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/public-api/actors/camera-actor.h>
23 #include <dali/internal/event/actors/actor-impl.h>
24 #include <dali/internal/event/actors/actor-declarations.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 namespace SceneGraph
33 {
34 class Camera;
35 }
36
37 /**
38  * An actor with Camera.
39  */
40 class CameraActor : public Actor
41 {
42 public:
43
44   /**
45    * Create an initialised camera actor.
46    *
47    * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
48    *
49    * @param[in] size The canvas size.
50    *
51    * @return A smart-pointer to a newly allocated camera actor.
52    */
53   static CameraActorPtr New( const Size& size );
54
55   /**
56    * Sets the reflection plane for the camera
57    *
58    * @param[in] plane Plane parameters
59    *
60    * @note plane.xyz are normal vector of the plane.
61    */
62   void SetReflectByPlane( const Vector4& plane );
63
64   /**
65    * @copydoc Dali::CameraActor::SetTargetPosition
66    */
67   void SetTarget( const Vector3& targetPosition );
68
69   /**
70    * @copydoc Dali::CameraActor::GetTargetPosition
71    */
72   Vector3 GetTarget() const;
73
74   /**
75    * @copydoc Dali::CameraActor::SetType
76    */
77   void SetType( Dali::Camera::Type type );
78
79   /**
80    * @copydoc Dali::CameraActor::GetType
81    */
82   Dali::Camera::Type GetType() const;
83
84   /**
85    * @copydoc Dali::CameraActor::SetProjectionMode
86    */
87   void SetProjectionMode( Dali::Camera::ProjectionMode mode );
88
89   /**
90    * @copydoc Dali::CameraActor::GetProjectionMode
91    */
92   Dali::Camera::ProjectionMode GetProjectionMode() const;
93
94   /**
95    * @copydoc Dali::CameraActor::SetFieldOfView
96    */
97   void SetFieldOfView( float fieldOfView );
98
99   /**
100    * @copydoc Dali::CameraActor::GetFieldOfView
101    */
102   float GetFieldOfView() const;
103
104   /**
105    * @copydoc Dali::CameraActor::SetAspectRatio
106    */
107   void SetAspectRatio( float aspectRatio );
108
109   /**
110    * @copydoc Dali::CameraActor::GetAspectRatio
111    */
112   float GetAspectRatio() const;
113
114   /**
115    * @copydoc Dali::CameraActor::SetNearClippingPlane
116    */
117   void SetNearClippingPlane( float nearClippingPlane );
118
119   /**
120    * @copydoc Dali::CameraActor::GetNearClippingPlane
121    */
122   float GetNearClippingPlane() const;
123
124   /**
125    * @copydoc Dali::CameraActor::SetFarClippingPlane
126    */
127   void SetFarClippingPlane( float farClippingPlane );
128
129   /**
130    * @copydoc Dali::CameraActor::GetFarClippingPlane
131    */
132   float GetFarClippingPlane() const;
133
134   /**
135    * @param leftClippingPlane to use
136    */
137   void SetLeftClippingPlane( float leftClippingPlane );
138
139   /**
140    * @param rightClippingPlane to use
141    */
142   void SetRightClippingPlane( float rightClippingPlane );
143
144   /**
145    * @param topClippingPlane to use
146    */
147   void SetTopClippingPlane( float topClippingPlane );
148
149   /**
150    * @param bottomClippingPlane to use
151    */
152   void SetBottomClippingPlane( float bottomClippingPlane );
153
154   /**
155    * @copydoc Dali::CameraActor::SetInvertYAxis
156    */
157   void SetInvertYAxis( bool invertYAxis );
158
159   /**
160    * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
161    */
162   bool GetInvertYAxis() const;
163
164   /**
165    * @copydoc Dali::CameraActor::SetPerspectiveProjection()
166    */
167   void SetPerspectiveProjection( const Size& size );
168
169   /**
170    * @copydoc Dali::CameraActor::SetOrthographicProjection(const Vector2& size);
171    */
172   void SetOrthographicProjection( const Vector2& size );
173
174   /**
175    * @copydoc Dali::CameraActor::SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
176    */
177   void SetOrthographicProjection( float left, float right, float top, float bottom, float near, float far );
178
179   /**
180    * Build a picking ray with this camera and given screen coordinates
181    * @param [in] screenCoordinates the ray passed through
182    * @param [in] viewport to use
183    * @param [out] rayOrigin for the picking ray
184    * @param [out] rayDirection for the picking ray
185    * @return true if the building was successful, false if its not possible (camera is not valid for hit testing)
186    */
187   bool BuildPickingRay( const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection );
188
189   /**
190    * Retrieve the view-matrix; This will only be valid when the actor is on-stage.
191    * @return The view-matrix.
192    */
193   const Matrix& GetViewMatrix() const;
194
195   /**
196    * Retrieve the projection-matrix; This will only be valid when the actor is on-stage.
197    * @return The projection-matrix.
198    */
199   const Matrix& GetProjectionMatrix() const;
200
201   /**
202    * Return the scene graph camera (for RenderTask)
203    * @return The scene graph camera.
204    */
205   const SceneGraph::Camera* GetCamera() const;
206
207 public: // properties
208
209   /**
210    * copydoc Dali::Internal::Object::SetDefaultProperty()
211    */
212   virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
213
214   /**
215    * copydoc Dali::Internal::Object::GetDefaultProperty()
216    */
217   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
218
219   /**
220    * copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
221    */
222   virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
223
224   /**
225    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
226    */
227   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
228
229 private:
230
231   /**
232    * Constructor; see also CameraActor::New()
233    * @param node the scene graph node
234    */
235   CameraActor( const SceneGraph::Node& node );
236
237   /**
238    * A reference counted object may only be deleted by calling Unreference()
239    */
240   virtual ~CameraActor();
241
242
243   /**
244    * @copydoc Dali::Internal::Actor::OnInitialize()
245    */
246   void OnInitialize() override;
247
248   /**
249    * @copydoc Dali::Internal::Actor::OnStageConnectionInternal()
250    */
251   void OnStageConnectionInternal() override;
252
253 private: // Data
254
255   const SceneGraph::Camera* mSceneObject; ///< Not owned
256
257   Vector3            mTarget;
258   Vector2            mCanvasSize;
259   Dali::Camera::Type mType;
260   Dali::Camera::ProjectionMode mProjectionMode;
261   float              mFieldOfView;
262   float              mAspectRatio;
263   float              mNearClippingPlane;
264   float              mFarClippingPlane;
265   float              mLeftClippingPlane;
266   float              mRightClippingPlane;
267   float              mTopClippingPlane;
268   float              mBottomClippingPlane;
269   bool               mInvertYAxis;
270
271 };
272
273 } // namespace Internal
274
275 // Helpers for public-api forwarding methods
276
277 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
278 {
279   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
280
281   BaseObject& handle = camera.GetBaseObject();
282
283   return static_cast<Internal::CameraActor&>(handle);
284 }
285
286 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
287 {
288   DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
289
290   const BaseObject& handle = camera.GetBaseObject();
291
292   return static_cast<const Internal::CameraActor&>(handle);
293 }
294
295 } // namespace Dali
296
297 #endif // DALI_INTERNAL_CAMERA_ACTOR_H