2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/actors/camera-actor-impl.h>
23 #include <cstring> // for strcmp
26 #include <dali/devel-api/actors/camera-actor-devel.h>
27 #include <dali/internal/common/matrix-utils.h>
28 #include <dali/internal/event/common/projection.h>
29 #include <dali/internal/event/common/property-helper.h>
30 #include <dali/internal/event/common/thread-local-storage.h>
31 #include <dali/public-api/object/type-registry.h>
33 #include <dali/internal/update/common/property-base.h>
34 #include <dali/internal/update/manager/update-manager.h>
35 #include <dali/internal/update/render-tasks/scene-graph-camera-messages.h>
46 * We want to discourage the use of property strings (minimize string comparisons),
47 * particularly for the default properties.
48 * Name Type writable animatable constraint-input enum for index-checking
51 DALI_PROPERTY_TABLE_BEGIN
52 DALI_PROPERTY( "type", INTEGER, true, false, true, Dali::CameraActor::Property::TYPE )
53 DALI_PROPERTY( "projectionMode", INTEGER, true, false, true, Dali::CameraActor::Property::PROJECTION_MODE )
54 DALI_PROPERTY( "fieldOfView", FLOAT, true, true, true, Dali::CameraActor::Property::FIELD_OF_VIEW )
55 DALI_PROPERTY( "aspectRatio", FLOAT, true, true, true, Dali::CameraActor::Property::ASPECT_RATIO )
56 DALI_PROPERTY( "nearPlaneDistance", FLOAT, true, false, true, Dali::CameraActor::Property::NEAR_PLANE_DISTANCE )
57 DALI_PROPERTY( "farPlaneDistance", FLOAT, true, false, true, Dali::CameraActor::Property::FAR_PLANE_DISTANCE )
58 DALI_PROPERTY( "leftPlaneDistance", FLOAT, false, false, true, Dali::CameraActor::Property::LEFT_PLANE_DISTANCE )
59 DALI_PROPERTY( "rightPlaneDistance", FLOAT, false, false, true, Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE )
60 DALI_PROPERTY( "topPlaneDistance", FLOAT, false, false, true, Dali::CameraActor::Property::TOP_PLANE_DISTANCE )
61 DALI_PROPERTY( "bottomPlaneDistance", FLOAT, false, false, true, Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE )
62 DALI_PROPERTY( "targetPosition", VECTOR3, true, false, true, Dali::CameraActor::Property::TARGET_POSITION )
63 DALI_PROPERTY( "projectionMatrix", MATRIX, false, false, true, Dali::CameraActor::Property::PROJECTION_MATRIX )
64 DALI_PROPERTY( "viewMatrix", MATRIX, false, false, true, Dali::CameraActor::Property::VIEW_MATRIX )
65 DALI_PROPERTY( "invertYAxis", BOOLEAN, true, false, true, Dali::CameraActor::Property::INVERT_Y_AXIS )
66 DALI_PROPERTY( "orthographicSize", FLOAT, true, true, true, Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE )
67 DALI_PROPERTY( "projectionDirection", INTEGER, true, false, true, Dali::DevelCameraActor::Property::PROJECTION_DIRECTION )
68 DALI_PROPERTY_TABLE_END( DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, CameraDefaultProperties )
71 // calculate the far plane distance for a 16bit depth buffer with 4 bits per unit precision
72 void CalculateClippingAndZ(float width, float height, float& nearClippingPlane, float& farClippingPlane, float& cameraZ)
74 nearClippingPlane = std::max(width, height);
75 farClippingPlane = nearClippingPlane + static_cast<float>(0xFFFF >> 4);
76 cameraZ = 2.0f * nearClippingPlane;
81 return Dali::CameraActor::New();
84 TypeRegistration mType(typeid(Dali::CameraActor), typeid(Dali::Actor), Create, CameraDefaultProperties);
87 * Builds the picking ray in the world reference system from an orthographic camera
88 * The ray origin is the screen coordinate in the near plane translated to a parallel
89 * plane at the camera origin. The ray direction is the direction the camera is facing
90 * (i.e. Z=-1 in view space).
92 void BuildOrthoPickingRay(const Matrix& viewMatrix,
93 const Matrix& projectionMatrix,
94 const Viewport& viewport,
99 float nearPlaneDistance)
101 // inv( modelMatrix ) inv( viewMatrix ) inv( projectionMatrix ) normalize
102 // <----------------- <----------------- <-------------- <-------------
103 // Local World Camera Normalized Screen
104 // reference reference reference clip coordinates
105 // system system system coordinates
106 // -----------------> -----------------> --------------> ------------->
107 // modelMatrix viewMatrix projectionMatrix viewport
109 // Transforms the touch point from the screen reference system to the world reference system.
110 Matrix invViewProjection(false); // Don't initialize.
111 MatrixUtils::MultiplyProjectionMatrix(invViewProjection, viewMatrix, projectionMatrix);
112 if(!invViewProjection.Invert())
114 DALI_ASSERT_DEBUG(false);
117 Vector4 near(screenX - static_cast<float>(viewport.x),
118 static_cast<float>(viewport.height) - (screenY - static_cast<float>(viewport.y)),
121 if(!Unproject(near, invViewProjection, static_cast<float>(viewport.width), static_cast<float>(viewport.height), rayOrigin))
123 DALI_ASSERT_DEBUG(false);
126 Matrix invView = viewMatrix;
127 if(!invView.Invert())
129 DALI_ASSERT_DEBUG(false);
132 Vector4 cameraOrigin = invView * Vector4(0.f, 0.f, 0.f, 1.f);
133 Vector4 nearPlaneOrigin = invView * Vector4(0.0f, 0.0f, -nearPlaneDistance, 1.0f);
135 // Vector pointing from the camera to the near plane
136 rayDir = cameraOrigin - nearPlaneOrigin;
143 * @brief Helper class to calculate left/right/top/bottom plane distance by orthographicSize and something other info.
144 * It will resolve some confuse case of plane distance value.
145 * (Something like, Is top plane distance is positive or negative? is aspect ratio is width/height or height/width?)
147 struct OrthographicSizeConverter
149 constexpr OrthographicSizeConverter(float orthographicSize, float aspectRatio, Dali::DevelCameraActor::ProjectionDirection projectionDirection)
150 : mOrthographicSize(orthographicSize),
151 mAspectRatio(aspectRatio),
152 mProjectionDirection(projectionDirection)
156 inline float LeftPlaneDistance() const
158 return -(mProjectionDirection == DevelCameraActor::ProjectionDirection::VERTICAL ? mOrthographicSize * mAspectRatio : mOrthographicSize);
161 inline float RightPlaneDistance() const
163 return (mProjectionDirection == DevelCameraActor::ProjectionDirection::VERTICAL ? mOrthographicSize * mAspectRatio : mOrthographicSize);
166 inline float TopPlaneDistance() const
168 return (mProjectionDirection == DevelCameraActor::ProjectionDirection::VERTICAL ? mOrthographicSize : mOrthographicSize / mAspectRatio);
171 inline float BottomPlaneDistance() const
173 return -(mProjectionDirection == DevelCameraActor::ProjectionDirection::VERTICAL ? mOrthographicSize : mOrthographicSize / mAspectRatio);
176 float mOrthographicSize;
178 Dali::DevelCameraActor::ProjectionDirection mProjectionDirection;
181 static const float DEFAULT_NEAR_CLIPPING_PLANE_FOR_3D = 0.1f;
182 static const float DEFAULT_FAR_CLIPPING_PLANE_FOR_3D = 100.0f;
184 static const Dali::Camera::ProjectionMode DEFAULT_MODE_FOR_3D = SceneGraph::Camera::DEFAULT_MODE;
185 static const Dali::DevelCameraActor::ProjectionDirection DEFAULT_PROJECTION_DIRECTION_FOR_3D = SceneGraph::Camera::DEFAULT_PROJECTION_DIRECTION;
187 static const float DEFAULT_FIELD_OF_VIEW_FOR_3D = SceneGraph::Camera::DEFAULT_FIELD_OF_VIEW;
188 static const float DEFAULT_POSITIN_Z_FOR_3D = 5.0f;
189 static const Quaternion DEFAULT_ORIENTATION_FOR_3D = Quaternion(Dali::ANGLE_180, Vector3::YAXIS);
190 static const float DEFAULT_ORTHOGRAPHIC_SIZE_FOR_3D = 2.071068f; // DEFAULT_POSITIN_Z_FOR_3D * std::tan(DEFAULT_FIELD_OF_VIEW_FOR_3D * 0.5f); // Rectangle size of z=0.
193 * @brief Setup CameraActor's parameters for 3D apps.
194 * Conceptually, We can must see 1 world unit cube at world origin.
195 * Detail value can be changed by UX.
197 * @param[in,out] cameraActorObject CameraActor who need to apply default camera parameters.
199 void SetupDefault3DCameraProperties(Internal::CameraActor& cameraActorObject)
201 cameraActorObject.SetNearClippingPlane(DEFAULT_NEAR_CLIPPING_PLANE_FOR_3D);
202 cameraActorObject.SetFarClippingPlane(DEFAULT_FAR_CLIPPING_PLANE_FOR_3D);
204 cameraActorObject.SetProjectionMode(DEFAULT_MODE_FOR_3D);
205 cameraActorObject.SetProjectionDirection(DEFAULT_PROJECTION_DIRECTION_FOR_3D);
206 cameraActorObject.SetFieldOfView(DEFAULT_FIELD_OF_VIEW_FOR_3D);
207 cameraActorObject.SetZ(DEFAULT_POSITIN_Z_FOR_3D);
208 cameraActorObject.SetOrientation(DEFAULT_ORIENTATION_FOR_3D);
210 cameraActorObject.SetOrthographicSize(DEFAULT_ORTHOGRAPHIC_SIZE_FOR_3D);
215 CameraActorPtr CameraActor::New(const Size& size, bool hintFor3D)
217 // create camera. Cameras are owned by the update manager
218 SceneGraph::Camera* camera = SceneGraph::Camera::New();
219 OwnerPointer<SceneGraph::Node> transferOwnership(camera);
220 Internal::ThreadLocalStorage* tls = Internal::ThreadLocalStorage::GetInternal();
222 DALI_ASSERT_ALWAYS(tls && "ThreadLocalStorage is null");
224 // Send ownership of camera.
225 AddNodeMessage(tls->GetUpdateManager(), transferOwnership);
227 CameraActorPtr actor(new CameraActor(*camera));
229 // Second-phase construction
232 actor->SetName("DefaultCamera");
235 // Initialize camera property for 3D case.
236 SetupDefault3DCameraProperties(*actor);
240 actor->SetPerspectiveProjection(size);
242 // By default Actors face in the positive Z direction in world space
243 // CameraActors should face in the negative Z direction, towards the other actors
244 actor->SetOrientation(Quaternion(Dali::ANGLE_180, Vector3::YAXIS));
250 CameraActor::CameraActor(const SceneGraph::Node& node)
251 : Actor(Actor::BASIC, node),
252 mTarget(SceneGraph::Camera::DEFAULT_TARGET_POSITION),
253 mType(SceneGraph::Camera::DEFAULT_TYPE),
254 mProjectionMode(SceneGraph::Camera::DEFAULT_MODE),
255 mProjectionDirection(SceneGraph::Camera::DEFAULT_PROJECTION_DIRECTION),
256 mFieldOfView(SceneGraph::Camera::DEFAULT_FIELD_OF_VIEW),
257 mOrthographicSize(SceneGraph::Camera::DEFAULT_ORTHOGRAPHIC_SIZE),
258 mAspectRatio(SceneGraph::Camera::DEFAULT_ASPECT_RATIO),
259 mNearClippingPlane(SceneGraph::Camera::DEFAULT_NEAR_CLIPPING_PLANE),
260 mFarClippingPlane(SceneGraph::Camera::DEFAULT_FAR_CLIPPING_PLANE),
261 mInvertYAxis(SceneGraph::Camera::DEFAULT_INVERT_Y_AXIS),
262 mPropertyChanged(false)
266 CameraActor::~CameraActor()
270 void CameraActor::OnSceneConnectionInternal()
272 // If the canvas size has not been set, then use the size of the scene to which we've been added
273 // in order to set up the current projection
274 if(!mPropertyChanged && ((mCanvasSize.width < Math::MACHINE_EPSILON_1000) || (mCanvasSize.height < Math::MACHINE_EPSILON_1000)))
276 if(mProjectionMode == Dali::Camera::ORTHOGRAPHIC_PROJECTION)
278 SetOrthographicProjection(GetScene().GetSize());
280 else //if(mProjectionMode == Dali::Camera::PERSPECTIVE_PROJECTION)
282 SetPerspectiveProjection(GetScene().GetSize());
287 void CameraActor::SetReflectByPlane(const Vector4& plane)
289 SetReflectByPlaneMessage(GetEventThreadServices(), GetCameraSceneObject(), plane);
292 void CameraActor::SetTarget(const Vector3& target)
294 mPropertyChanged = true;
295 if(target != mTarget) // using range epsilon
299 SetTargetPositionMessage(GetEventThreadServices(), GetCameraSceneObject(), mTarget);
303 Vector3 CameraActor::GetTarget() const
308 void CameraActor::SetType(Dali::Camera::Type type)
314 // sceneObject is being used in a separate thread; queue a message to set
315 SetTypeMessage(GetEventThreadServices(), GetCameraSceneObject(), mType);
319 Dali::Camera::Type CameraActor::GetType() const
324 void CameraActor::SetProjectionMode(Dali::Camera::ProjectionMode mode)
326 if(mode != mProjectionMode)
328 mProjectionMode = mode;
330 // sceneObject is being used in a separate thread; queue a message to set
331 SetProjectionModeMessage(GetEventThreadServices(), GetCameraSceneObject(), mProjectionMode);
335 Dali::Camera::ProjectionMode CameraActor::GetProjectionMode() const
337 return mProjectionMode;
340 void CameraActor::SetProjectionDirection(Dali::DevelCameraActor::ProjectionDirection direction)
342 mPropertyChanged = true;
343 if(direction != mProjectionDirection)
345 mProjectionDirection = direction;
347 // sceneObject is being used in a separate thread; queue a message to set
348 SetProjectionDirectionMessage(GetEventThreadServices(), GetCameraSceneObject(), mProjectionDirection);
352 void CameraActor::SetFieldOfView(float fieldOfView)
354 mPropertyChanged = true;
355 if(!Equals(fieldOfView, mFieldOfView))
357 mFieldOfView = fieldOfView;
359 // sceneObject is being used in a separate thread; queue a message to set
360 BakeFieldOfViewMessage(GetEventThreadServices(), GetCameraSceneObject(), mFieldOfView);
364 float CameraActor::GetFieldOfView() const
369 float CameraActor::GetCurrentFieldOfView() const
371 // node is being used in a separate thread; copy the value from the previous update
372 return GetCameraSceneObject().GetFieldOfView(GetEventThreadServices().GetEventBufferIndex());
375 void CameraActor::SetOrthographicSize(float orthographicSize)
377 mPropertyChanged = true;
378 if(!Equals(orthographicSize, mOrthographicSize))
380 mOrthographicSize = orthographicSize;
382 // sceneObject is being used in a separate thread; queue a message to set
383 BakeOrthographicSizeMessage(GetEventThreadServices(), GetCameraSceneObject(), mOrthographicSize);
387 float CameraActor::GetOrthographicSize() const
389 return mOrthographicSize;
392 float CameraActor::GetCurrentOrthographicSize() const
394 // node is being used in a separate thread; copy the value from the previous update
395 return GetCameraSceneObject().GetOrthographicSize(GetEventThreadServices().GetEventBufferIndex());
398 void CameraActor::SetAspectRatio(float aspectRatio)
400 mPropertyChanged = true;
401 if(!Equals(aspectRatio, mAspectRatio))
403 mAspectRatio = aspectRatio;
405 // sceneObject is being used in a separate thread; queue a message to set
406 BakeAspectRatioMessage(GetEventThreadServices(), GetCameraSceneObject(), mAspectRatio);
410 float CameraActor::GetAspectRatio() const
415 float CameraActor::GetCurrentAspectRatio() const
417 // node is being used in a separate thread; copy the value from the previous update
418 return GetCameraSceneObject().GetAspectRatio(GetEventThreadServices().GetEventBufferIndex());
421 void CameraActor::SetNearClippingPlane(float nearClippingPlane)
423 mPropertyChanged = true;
424 if(!Equals(nearClippingPlane, mNearClippingPlane))
426 mNearClippingPlane = nearClippingPlane;
428 // sceneObject is being used in a separate thread; queue a message to set
429 SetNearClippingPlaneMessage(GetEventThreadServices(), GetCameraSceneObject(), mNearClippingPlane);
433 float CameraActor::GetNearClippingPlane() const
435 return mNearClippingPlane;
438 void CameraActor::SetFarClippingPlane(float farClippingPlane)
440 mPropertyChanged = true;
441 if(!Equals(farClippingPlane, mFarClippingPlane))
443 mFarClippingPlane = farClippingPlane;
445 // sceneObject is being used in a separate thread; queue a message to set
446 SetFarClippingPlaneMessage(GetEventThreadServices(), GetCameraSceneObject(), mFarClippingPlane);
450 float CameraActor::GetFarClippingPlane() const
452 return mFarClippingPlane;
455 void CameraActor::SetInvertYAxis(bool invertYAxis)
457 if(invertYAxis != mInvertYAxis)
459 mInvertYAxis = invertYAxis;
461 // sceneObject is being used in a separate thread; queue a message to set
462 SetInvertYAxisMessage(GetEventThreadServices(), GetCameraSceneObject(), mInvertYAxis);
466 bool CameraActor::GetInvertYAxis() const
471 void CameraActor::SetPerspectiveProjection(const Size& size)
473 SetProjectionMode(Dali::Camera::PERSPECTIVE_PROJECTION);
474 mCanvasSize = static_cast<const Vector2>(size);
476 if((size.width < Math::MACHINE_EPSILON_1000) || (size.height < Math::MACHINE_EPSILON_1000))
478 // If the size given is invalid, i.e. ZERO, then check if we've been added to a scene
481 // We've been added to a scene already, set the canvas size to the scene's size
482 mCanvasSize = GetScene().GetSize();
486 // We've not been added to a scene yet, so just return.
487 // We'll set the canvas size when we get added to a scene later
491 ApplyDefaultProjection();
494 void CameraActor::SetOrthographicProjection(const Size& size)
496 SetProjectionMode(Dali::Camera::ORTHOGRAPHIC_PROJECTION);
497 mCanvasSize = static_cast<const Vector2>(size);
499 if((size.width < Math::MACHINE_EPSILON_1000) || (size.height < Math::MACHINE_EPSILON_1000))
501 // If the size given is invalid, i.e. ZERO, then check if we've been added to a scene
504 // We've been added to a scene already, set the canvas size to the scene's size
505 mCanvasSize = GetScene().GetSize();
509 // We've not been added to a scene yet, so just return.
510 // We'll set the canvas size when we get added to a scene later
515 ApplyDefaultProjection();
518 void CameraActor::ApplyDefaultProjection()
520 const float width = mCanvasSize.width;
521 const float height = mCanvasSize.height;
523 // Choose near, far and Z parameters to match the SetPerspectiveProjection above.
524 float nearClippingPlane;
525 float farClippingPlane;
527 CalculateClippingAndZ(width, height, nearClippingPlane, farClippingPlane, cameraZ);
529 // calculate orthographic size.
530 const float orthographicSize = (mProjectionDirection == DevelCameraActor::ProjectionDirection::VERTICAL ? height : width) * 0.5f;
532 // calculate the position of the camera to have the desired aspect ratio
533 const float fieldOfView = 2.0f * std::atan(orthographicSize / cameraZ);
535 // unless it is too small, we want at least as much space to the back as we have torwards the front
536 const float minClippingFarPlane = 2.f * nearClippingPlane;
537 if(farClippingPlane < minClippingFarPlane)
539 farClippingPlane = minClippingFarPlane;
542 const float aspectRatio = width / height;
544 // sceneObject is being used in a separate thread; queue a message to set
545 SetFieldOfView(fieldOfView);
546 SetNearClippingPlane(nearClippingPlane);
547 SetFarClippingPlane(farClippingPlane);
548 SetAspectRatio(aspectRatio);
549 SetOrthographicSize(orthographicSize);
553 bool CameraActor::BuildPickingRay(const Vector2& screenCoordinates,
554 const Viewport& viewport,
556 Vector4& rayDirection)
559 if(mProjectionMode == Dali::Camera::PERSPECTIVE_PROJECTION)
561 // Build a picking ray in the world reference system.
562 // ray starts from the camera world position
563 rayOrigin = GetNode().GetWorldMatrix(0).GetTranslation();
566 // Transform the touch point from the screen coordinate system to the world coordinates system.
567 Vector4 near(screenCoordinates.x - static_cast<float>(viewport.x),
568 static_cast<float>(viewport.height) - (screenCoordinates.y - static_cast<float>(viewport.y)),
571 const Matrix& inverseViewProjection = GetCameraSceneObject().GetInverseViewProjectionMatrix(GetEventThreadServices().GetEventBufferIndex());
572 success = Unproject(near, inverseViewProjection, static_cast<float>(viewport.width), static_cast<float>(viewport.height), near);
574 // Compute the ray's director vector.
575 rayDirection.x = near.x - rayOrigin.x;
576 rayDirection.y = near.y - rayOrigin.y;
577 rayDirection.z = near.z - rayOrigin.z;
578 rayDirection.Normalize();
579 rayDirection.w = 1.f;
583 float nearPlaneDistance = GetNearClippingPlane();
584 BuildOrthoPickingRay(GetViewMatrix(),
585 GetProjectionMatrix(),
597 const Matrix& CameraActor::GetViewMatrix() const
601 return GetCameraSceneObject().GetViewMatrix(GetEventThreadServices().GetEventBufferIndex());
605 return Matrix::IDENTITY;
609 const Matrix& CameraActor::GetProjectionMatrix() const
613 return GetCameraSceneObject().GetProjectionMatrix(GetEventThreadServices().GetEventBufferIndex());
617 return Matrix::IDENTITY;
620 const SceneGraph::Camera& CameraActor::GetCameraSceneObject() const
622 return static_cast<const SceneGraph::Camera&>(GetNode());
625 void CameraActor::RotateProjection(int rotationAngle)
627 // sceneObject is being used in a separate thread; queue a message to set
628 RotateProjectionMessage(GetEventThreadServices(), GetCameraSceneObject(), rotationAngle);
631 void CameraActor::SetDefaultProperty(Property::Index index, const Property::Value& propertyValue)
633 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
635 Actor::SetDefaultProperty(index, propertyValue);
641 case Dali::CameraActor::Property::TYPE:
643 Dali::Camera::Type cameraType = Dali::Camera::Type(propertyValue.Get<int>());
647 case Dali::CameraActor::Property::PROJECTION_MODE:
649 Dali::Camera::ProjectionMode projectionMode = Dali::Camera::ProjectionMode(propertyValue.Get<int>());
650 SetProjectionMode(projectionMode);
653 case Dali::CameraActor::Property::FIELD_OF_VIEW:
655 SetFieldOfView(propertyValue.Get<float>()); // set to 0 in case property is not float
658 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
660 SetOrthographicSize(propertyValue.Get<float>()); // set to 0 in case property is not float
663 case Dali::CameraActor::Property::ASPECT_RATIO:
665 SetAspectRatio(propertyValue.Get<float>()); // set to 0 in case property is not float
668 case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE:
670 SetNearClippingPlane(propertyValue.Get<float>()); // set to 0 in case property is not float
673 case Dali::CameraActor::Property::FAR_PLANE_DISTANCE:
675 SetFarClippingPlane(propertyValue.Get<float>()); // set to 0 in case property is not float
678 case Dali::CameraActor::Property::LEFT_PLANE_DISTANCE:
680 DALI_LOG_WARNING("LEFT_PLANE_DISTANCE is read-only\n");
683 case Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE:
685 DALI_LOG_WARNING("RIGHT_PLANE_DISTANCE is read-only\n");
688 case Dali::CameraActor::Property::TOP_PLANE_DISTANCE:
690 DALI_LOG_WARNING("TOP_PLANE_DISTANCE is read-only\n");
693 case Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE:
695 DALI_LOG_WARNING("BOTTOM_PLANE_DISTANCE is read-only\n");
698 case Dali::CameraActor::Property::TARGET_POSITION:
700 SetTarget(propertyValue.Get<Vector3>()); // set to 0 in case property is not Vector3
703 case Dali::CameraActor::Property::PROJECTION_MATRIX:
705 DALI_LOG_WARNING("projection-matrix is read-only\n");
708 case Dali::CameraActor::Property::VIEW_MATRIX:
710 DALI_LOG_WARNING("view-matrix is read-only\n");
713 case Dali::CameraActor::Property::INVERT_Y_AXIS:
715 SetInvertYAxis(propertyValue.Get<bool>()); // set to false in case property is not bool
718 case Dali::DevelCameraActor::Property::REFLECTION_PLANE:
720 SetReflectByPlane(propertyValue.Get<Vector4>());
723 case Dali::DevelCameraActor::Property::PROJECTION_DIRECTION:
725 Dali::DevelCameraActor::ProjectionDirection projectionDirection = Dali::DevelCameraActor::ProjectionDirection(propertyValue.Get<int>());
726 SetProjectionDirection(projectionDirection);
732 DALI_LOG_WARNING("Unknown property (%d)\n", index);
740 Property::Value CameraActor::GetDefaultProperty(Property::Index index) const
743 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
745 ret = Actor::GetDefaultProperty(index);
751 case Dali::CameraActor::Property::TYPE:
756 case Dali::CameraActor::Property::PROJECTION_MODE:
758 ret = mProjectionMode;
761 case Dali::CameraActor::Property::FIELD_OF_VIEW:
766 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
768 ret = mOrthographicSize;
771 case Dali::CameraActor::Property::ASPECT_RATIO:
776 case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE:
778 ret = mNearClippingPlane;
781 case Dali::CameraActor::Property::FAR_PLANE_DISTANCE:
783 ret = mFarClippingPlane;
786 case Dali::CameraActor::Property::LEFT_PLANE_DISTANCE:
788 ret = OrthographicSizeConverter(mOrthographicSize, mAspectRatio, mProjectionDirection).LeftPlaneDistance();
791 case Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE:
793 ret = OrthographicSizeConverter(mOrthographicSize, mAspectRatio, mProjectionDirection).RightPlaneDistance();
796 case Dali::CameraActor::Property::TOP_PLANE_DISTANCE:
798 ret = OrthographicSizeConverter(mOrthographicSize, mAspectRatio, mProjectionDirection).TopPlaneDistance();
801 case Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE:
803 ret = OrthographicSizeConverter(mOrthographicSize, mAspectRatio, mProjectionDirection).BottomPlaneDistance();
806 case Dali::CameraActor::Property::TARGET_POSITION:
811 case Dali::CameraActor::Property::PROJECTION_MATRIX:
813 ret = GetProjectionMatrix(); // Only on scene-graph
816 case Dali::CameraActor::Property::VIEW_MATRIX:
818 ret = GetViewMatrix(); // Only on scene-graph
821 case Dali::CameraActor::Property::INVERT_Y_AXIS:
826 case Dali::DevelCameraActor::Property::PROJECTION_DIRECTION:
828 ret = mProjectionDirection;
837 Property::Value CameraActor::GetDefaultPropertyCurrentValue(Property::Index index) const
840 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
842 ret = Actor::GetDefaultPropertyCurrentValue(index);
848 case Dali::CameraActor::Property::FIELD_OF_VIEW:
850 ret = GetCurrentFieldOfView();
853 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
855 ret = GetCurrentOrthographicSize();
858 case Dali::CameraActor::Property::ASPECT_RATIO:
860 ret = GetCurrentAspectRatio();
863 case Dali::CameraActor::Property::LEFT_PLANE_DISTANCE:
865 ret = OrthographicSizeConverter(GetCurrentOrthographicSize(), GetCurrentAspectRatio(), mProjectionDirection).LeftPlaneDistance();
868 case Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE:
870 ret = OrthographicSizeConverter(GetCurrentOrthographicSize(), GetCurrentAspectRatio(), mProjectionDirection).RightPlaneDistance();
873 case Dali::CameraActor::Property::TOP_PLANE_DISTANCE:
875 ret = OrthographicSizeConverter(GetCurrentOrthographicSize(), GetCurrentAspectRatio(), mProjectionDirection).TopPlaneDistance();
878 case Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE:
880 ret = OrthographicSizeConverter(GetCurrentOrthographicSize(), GetCurrentAspectRatio(), mProjectionDirection).BottomPlaneDistance();
885 ret = GetDefaultProperty(index); // Most are event-side properties, the scene-graph properties are only on the scene-graph
893 void CameraActor::OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType)
895 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
897 Actor::OnNotifyDefaultPropertyAnimation(animation, index, value, animationType);
901 switch(animationType)
904 case Animation::BETWEEN:
908 case Dali::CameraActor::Property::FIELD_OF_VIEW:
910 value.Get(mFieldOfView);
913 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
915 value.Get(mOrthographicSize);
918 case Dali::CameraActor::Property::ASPECT_RATIO:
920 value.Get(mAspectRatio);
930 case Dali::CameraActor::Property::FIELD_OF_VIEW:
932 AdjustValue<float>(mFieldOfView, value);
935 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
937 AdjustValue<float>(mOrthographicSize, value);
940 case Dali::CameraActor::Property::ASPECT_RATIO:
942 AdjustValue<float>(mAspectRatio, value);
952 const SceneGraph::PropertyBase* CameraActor::GetSceneObjectAnimatableProperty(Property::Index index) const
954 const SceneGraph::PropertyBase* property(nullptr);
957 case Dali::CameraActor::Property::FIELD_OF_VIEW:
959 property = GetCameraSceneObject().GetFieldOfView();
962 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
964 property = GetCameraSceneObject().GetOrthographicSize();
967 case Dali::CameraActor::Property::ASPECT_RATIO:
969 property = GetCameraSceneObject().GetAspectRatio();
972 // no default on purpose as we chain method up to actor
976 // not our property, ask base
977 property = Actor::GetSceneObjectAnimatableProperty(index);
983 const PropertyInputImpl* CameraActor::GetSceneObjectInputProperty(Property::Index index) const
985 const PropertyInputImpl* property(nullptr);
989 case Dali::CameraActor::Property::FIELD_OF_VIEW:
991 property = GetCameraSceneObject().GetFieldOfView();
994 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
996 property = GetCameraSceneObject().GetOrthographicSize();
999 case Dali::CameraActor::Property::ASPECT_RATIO:
1001 property = GetCameraSceneObject().GetAspectRatio();
1004 case Dali::CameraActor::Property::PROJECTION_MATRIX:
1006 property = GetCameraSceneObject().GetProjectionMatrix();
1009 case Dali::CameraActor::Property::VIEW_MATRIX:
1011 property = GetCameraSceneObject().GetViewMatrix();
1014 // no default on purpose as we chain method up to actor
1018 property = Actor::GetSceneObjectInputProperty(index);
1024 void CameraActor::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
1026 // If Position or Orientation are explicitly set, make mPropertyChanged flag true.
1027 if(index == Dali::Actor::Property::POSITION ||
1028 index == Dali::Actor::Property::POSITION_X ||
1029 index == Dali::Actor::Property::POSITION_Y ||
1030 index == Dali::Actor::Property::POSITION_Z ||
1031 index == Dali::Actor::Property::ORIENTATION)
1033 mPropertyChanged = true;
1037 } // namespace Internal