1 #ifndef DALI_INTERNAL_CAMERA_ACTOR_H
2 #define DALI_INTERNAL_CAMERA_ACTOR_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
38 * An actor with Camera.
40 class CameraActor : public Actor
45 * Create an initialised camera actor.
47 * Sets the default camera perspective projection for the given canvas size. @see SetPerspectiveProjection().
49 * @param[in] size The canvas size.
51 * @return A smart-pointer to a newly allocated camera actor.
53 static CameraActorPtr New( const Size& size );
56 * Sets the reflection plane for the camera
58 * @param[in] plane Plane parameters
60 * @note plane.xyz are normal vector of the plane.
62 void SetReflectByPlane( const Vector4& plane );
65 * @copydoc Dali::CameraActor::SetTargetPosition
67 void SetTarget( const Vector3& targetPosition );
70 * @copydoc Dali::CameraActor::GetTargetPosition
72 Vector3 GetTarget() const;
75 * @copydoc Dali::CameraActor::SetType
77 void SetType( Dali::Camera::Type type );
80 * @copydoc Dali::CameraActor::GetType
82 Dali::Camera::Type GetType() const;
85 * @copydoc Dali::CameraActor::SetProjectionMode
87 void SetProjectionMode( Dali::Camera::ProjectionMode mode );
90 * @copydoc Dali::CameraActor::GetProjectionMode
92 Dali::Camera::ProjectionMode GetProjectionMode() const;
95 * @copydoc Dali::CameraActor::SetFieldOfView
97 void SetFieldOfView( float fieldOfView );
100 * @copydoc Dali::CameraActor::GetFieldOfView
102 float GetFieldOfView() const;
105 * @copydoc Dali::CameraActor::SetAspectRatio
107 void SetAspectRatio( float aspectRatio );
110 * @copydoc Dali::CameraActor::GetAspectRatio
112 float GetAspectRatio() const;
115 * @copydoc Dali::CameraActor::SetNearClippingPlane
117 void SetNearClippingPlane( float nearClippingPlane );
120 * @copydoc Dali::CameraActor::GetNearClippingPlane
122 float GetNearClippingPlane() const;
125 * @copydoc Dali::CameraActor::SetFarClippingPlane
127 void SetFarClippingPlane( float farClippingPlane );
130 * @copydoc Dali::CameraActor::GetFarClippingPlane
132 float GetFarClippingPlane() const;
135 * @param leftClippingPlane to use
137 void SetLeftClippingPlane( float leftClippingPlane );
140 * @param rightClippingPlane to use
142 void SetRightClippingPlane( float rightClippingPlane );
145 * @param topClippingPlane to use
147 void SetTopClippingPlane( float topClippingPlane );
150 * @param bottomClippingPlane to use
152 void SetBottomClippingPlane( float bottomClippingPlane );
155 * @copydoc Dali::CameraActor::SetInvertYAxis
157 void SetInvertYAxis( bool invertYAxis );
160 * @copydoc Dali::CameraActor::GetCurrentInvertYAxis
162 bool GetInvertYAxis() const;
165 * @copydoc Dali::CameraActor::SetPerspectiveProjection()
167 void SetPerspectiveProjection( const Size& size );
170 * @copydoc Dali::CameraActor::SetOrthographicProjection(const Vector2& size);
172 void SetOrthographicProjection( const Vector2& size );
175 * @copydoc Dali::CameraActor::SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far);
177 void SetOrthographicProjection( float left, float right, float top, float bottom, float near, float far );
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)
187 bool BuildPickingRay( const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection );
190 * Retrieve the view-matrix; This will only be valid when the actor is on-stage.
191 * @return The view-matrix.
193 const Matrix& GetViewMatrix() const;
196 * Retrieve the projection-matrix; This will only be valid when the actor is on-stage.
197 * @return The projection-matrix.
199 const Matrix& GetProjectionMatrix() const;
202 * Return the scene graph camera (for RenderTask)
203 * @return The scene graph camera.
205 const SceneGraph::Camera* GetCamera() const;
208 * Rotate the projection.
209 * It is used in case that the target buffer direction is different from the window direction.
210 * @param [in] rotationAngle The rotation angle
212 void RotateProjection(int rotationAngle);
214 public: // properties
217 * copydoc Dali::Internal::Object::SetDefaultProperty()
219 void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) override;
222 * copydoc Dali::Internal::Object::GetDefaultProperty()
224 Property::Value GetDefaultProperty( Property::Index index ) const override;
227 * copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
229 Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const override;
232 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
234 const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const override;
239 * Constructor; see also CameraActor::New()
240 * @param node the scene graph node
242 CameraActor( const SceneGraph::Node& node );
245 * A reference counted object may only be deleted by calling Unreference()
247 ~CameraActor() override;
251 * @copydoc Dali::Internal::Actor::OnInitialize()
253 void OnInitialize() override;
256 * @copydoc Dali::Internal::Actor::OnSceneConnectionInternal()
258 void OnSceneConnectionInternal() override;
262 const SceneGraph::Camera* mSceneObject; ///< Not owned
266 Dali::Camera::Type mType;
267 Dali::Camera::ProjectionMode mProjectionMode;
270 float mNearClippingPlane;
271 float mFarClippingPlane;
272 float mLeftClippingPlane;
273 float mRightClippingPlane;
274 float mTopClippingPlane;
275 float mBottomClippingPlane;
280 } // namespace Internal
282 // Helpers for public-api forwarding methods
284 inline Internal::CameraActor& GetImplementation(Dali::CameraActor& camera)
286 DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
288 BaseObject& handle = camera.GetBaseObject();
290 return static_cast<Internal::CameraActor&>(handle);
293 inline const Internal::CameraActor& GetImplementation(const Dali::CameraActor& camera)
295 DALI_ASSERT_ALWAYS(camera && "Camera handle is empty");
297 const BaseObject& handle = camera.GetBaseObject();
299 return static_cast<const Internal::CameraActor&>(handle);
304 #endif // DALI_INTERNAL_CAMERA_ACTOR_H