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, true, true, Dali::CameraActor::Property::NEAR_PLANE_DISTANCE )
57 DALI_PROPERTY( "farPlaneDistance", FLOAT, true, true, 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 BakeNearClippingPlaneMessage(GetEventThreadServices(), GetCameraSceneObject(), mNearClippingPlane);
433 float CameraActor::GetNearClippingPlane() const
435 return mNearClippingPlane;
438 float CameraActor::GetCurrentNearClippingPlane() const
440 return GetCameraSceneObject().GetNearClippingPlane(GetEventThreadServices().GetEventBufferIndex());
443 void CameraActor::SetFarClippingPlane(float farClippingPlane)
445 mPropertyChanged = true;
446 if(!Equals(farClippingPlane, mFarClippingPlane))
448 mFarClippingPlane = farClippingPlane;
450 // sceneObject is being used in a separate thread; queue a message to set
451 BakeFarClippingPlaneMessage(GetEventThreadServices(), GetCameraSceneObject(), mFarClippingPlane);
455 float CameraActor::GetFarClippingPlane() const
457 return mFarClippingPlane;
460 float CameraActor::GetCurrentFarClippingPlane() const
462 return GetCameraSceneObject().GetFarClippingPlane(GetEventThreadServices().GetEventBufferIndex());
465 void CameraActor::SetInvertYAxis(bool invertYAxis)
467 if(invertYAxis != mInvertYAxis)
469 mInvertYAxis = invertYAxis;
471 // sceneObject is being used in a separate thread; queue a message to set
472 SetInvertYAxisMessage(GetEventThreadServices(), GetCameraSceneObject(), mInvertYAxis);
476 bool CameraActor::GetInvertYAxis() const
481 void CameraActor::SetPerspectiveProjection(const Size& size)
483 SetProjectionMode(Dali::Camera::PERSPECTIVE_PROJECTION);
484 mCanvasSize = static_cast<const Vector2>(size);
486 if((size.width < Math::MACHINE_EPSILON_1000) || (size.height < Math::MACHINE_EPSILON_1000))
488 // If the size given is invalid, i.e. ZERO, then check if we've been added to a scene
491 // We've been added to a scene already, set the canvas size to the scene's size
492 mCanvasSize = GetScene().GetSize();
496 // We've not been added to a scene yet, so just return.
497 // We'll set the canvas size when we get added to a scene later
501 ApplyDefaultProjection();
504 void CameraActor::SetOrthographicProjection(const Size& size)
506 SetProjectionMode(Dali::Camera::ORTHOGRAPHIC_PROJECTION);
507 mCanvasSize = static_cast<const Vector2>(size);
509 if((size.width < Math::MACHINE_EPSILON_1000) || (size.height < Math::MACHINE_EPSILON_1000))
511 // If the size given is invalid, i.e. ZERO, then check if we've been added to a scene
514 // We've been added to a scene already, set the canvas size to the scene's size
515 mCanvasSize = GetScene().GetSize();
519 // We've not been added to a scene yet, so just return.
520 // We'll set the canvas size when we get added to a scene later
525 ApplyDefaultProjection();
528 void CameraActor::ApplyDefaultProjection()
530 const float width = mCanvasSize.width;
531 const float height = mCanvasSize.height;
533 // Choose near, far and Z parameters to match the SetPerspectiveProjection above.
534 float nearClippingPlane;
535 float farClippingPlane;
537 CalculateClippingAndZ(width, height, nearClippingPlane, farClippingPlane, cameraZ);
539 // calculate orthographic size.
540 const float orthographicSize = (mProjectionDirection == DevelCameraActor::ProjectionDirection::VERTICAL ? height : width) * 0.5f;
542 // calculate the position of the camera to have the desired aspect ratio
543 const float fieldOfView = 2.0f * std::atan(orthographicSize / cameraZ);
545 // unless it is too small, we want at least as much space to the back as we have torwards the front
546 const float minClippingFarPlane = 2.f * nearClippingPlane;
547 if(farClippingPlane < minClippingFarPlane)
549 farClippingPlane = minClippingFarPlane;
552 const float aspectRatio = width / height;
554 // sceneObject is being used in a separate thread; queue a message to set
555 SetFieldOfView(fieldOfView);
556 SetNearClippingPlane(nearClippingPlane);
557 SetFarClippingPlane(farClippingPlane);
558 SetAspectRatio(aspectRatio);
559 SetOrthographicSize(orthographicSize);
563 bool CameraActor::BuildPickingRay(const Vector2& screenCoordinates,
564 const Viewport& viewport,
566 Vector4& rayDirection)
569 if(mProjectionMode == Dali::Camera::PERSPECTIVE_PROJECTION)
571 // Build a picking ray in the world reference system.
572 // ray starts from the camera world position
573 rayOrigin = GetNode().GetWorldMatrix(0).GetTranslation();
576 // Transform the touch point from the screen coordinate system to the world coordinates system.
577 Vector4 near(screenCoordinates.x - static_cast<float>(viewport.x),
578 static_cast<float>(viewport.height) - (screenCoordinates.y - static_cast<float>(viewport.y)),
581 const Matrix& inverseViewProjection = GetCameraSceneObject().GetInverseViewProjectionMatrix(GetEventThreadServices().GetEventBufferIndex());
582 success = Unproject(near, inverseViewProjection, static_cast<float>(viewport.width), static_cast<float>(viewport.height), near);
584 // Compute the ray's director vector.
585 rayDirection.x = near.x - rayOrigin.x;
586 rayDirection.y = near.y - rayOrigin.y;
587 rayDirection.z = near.z - rayOrigin.z;
588 rayDirection.Normalize();
589 rayDirection.w = 1.f;
593 float nearPlaneDistance = GetNearClippingPlane();
594 BuildOrthoPickingRay(GetViewMatrix(),
595 GetProjectionMatrix(),
607 const Matrix& CameraActor::GetViewMatrix() const
611 return GetCameraSceneObject().GetViewMatrix(GetEventThreadServices().GetEventBufferIndex());
615 return Matrix::IDENTITY;
619 const Matrix& CameraActor::GetProjectionMatrix() const
623 return GetCameraSceneObject().GetProjectionMatrix(GetEventThreadServices().GetEventBufferIndex());
627 return Matrix::IDENTITY;
630 const SceneGraph::Camera& CameraActor::GetCameraSceneObject() const
632 return static_cast<const SceneGraph::Camera&>(GetNode());
635 void CameraActor::RotateProjection(int rotationAngle)
637 // sceneObject is being used in a separate thread; queue a message to set
638 RotateProjectionMessage(GetEventThreadServices(), GetCameraSceneObject(), rotationAngle);
641 void CameraActor::SetDefaultProperty(Property::Index index, const Property::Value& propertyValue)
643 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
645 Actor::SetDefaultProperty(index, propertyValue);
651 case Dali::CameraActor::Property::TYPE:
653 Dali::Camera::Type cameraType = Dali::Camera::Type(propertyValue.Get<int>());
657 case Dali::CameraActor::Property::PROJECTION_MODE:
659 Dali::Camera::ProjectionMode projectionMode = Dali::Camera::ProjectionMode(propertyValue.Get<int>());
660 SetProjectionMode(projectionMode);
663 case Dali::CameraActor::Property::FIELD_OF_VIEW:
665 SetFieldOfView(propertyValue.Get<float>()); // set to 0 in case property is not float
668 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
670 SetOrthographicSize(propertyValue.Get<float>()); // set to 0 in case property is not float
673 case Dali::CameraActor::Property::ASPECT_RATIO:
675 SetAspectRatio(propertyValue.Get<float>()); // set to 0 in case property is not float
678 case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE:
680 SetNearClippingPlane(propertyValue.Get<float>()); // set to 0 in case property is not float
683 case Dali::CameraActor::Property::FAR_PLANE_DISTANCE:
685 SetFarClippingPlane(propertyValue.Get<float>()); // set to 0 in case property is not float
688 case Dali::CameraActor::Property::LEFT_PLANE_DISTANCE:
690 DALI_LOG_WARNING("LEFT_PLANE_DISTANCE is read-only\n");
693 case Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE:
695 DALI_LOG_WARNING("RIGHT_PLANE_DISTANCE is read-only\n");
698 case Dali::CameraActor::Property::TOP_PLANE_DISTANCE:
700 DALI_LOG_WARNING("TOP_PLANE_DISTANCE is read-only\n");
703 case Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE:
705 DALI_LOG_WARNING("BOTTOM_PLANE_DISTANCE is read-only\n");
708 case Dali::CameraActor::Property::TARGET_POSITION:
710 SetTarget(propertyValue.Get<Vector3>()); // set to 0 in case property is not Vector3
713 case Dali::CameraActor::Property::PROJECTION_MATRIX:
715 DALI_LOG_WARNING("projection-matrix is read-only\n");
718 case Dali::CameraActor::Property::VIEW_MATRIX:
720 DALI_LOG_WARNING("view-matrix is read-only\n");
723 case Dali::CameraActor::Property::INVERT_Y_AXIS:
725 SetInvertYAxis(propertyValue.Get<bool>()); // set to false in case property is not bool
728 case Dali::DevelCameraActor::Property::REFLECTION_PLANE:
730 SetReflectByPlane(propertyValue.Get<Vector4>());
733 case Dali::DevelCameraActor::Property::PROJECTION_DIRECTION:
735 Dali::DevelCameraActor::ProjectionDirection projectionDirection = Dali::DevelCameraActor::ProjectionDirection(propertyValue.Get<int>());
736 SetProjectionDirection(projectionDirection);
742 DALI_LOG_WARNING("Unknown property (%d)\n", index);
750 Property::Value CameraActor::GetDefaultProperty(Property::Index index) const
753 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
755 ret = Actor::GetDefaultProperty(index);
761 case Dali::CameraActor::Property::TYPE:
766 case Dali::CameraActor::Property::PROJECTION_MODE:
768 ret = mProjectionMode;
771 case Dali::CameraActor::Property::FIELD_OF_VIEW:
776 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
778 ret = mOrthographicSize;
781 case Dali::CameraActor::Property::ASPECT_RATIO:
786 case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE:
788 ret = mNearClippingPlane;
791 case Dali::CameraActor::Property::FAR_PLANE_DISTANCE:
793 ret = mFarClippingPlane;
796 case Dali::CameraActor::Property::LEFT_PLANE_DISTANCE:
798 ret = OrthographicSizeConverter(mOrthographicSize, mAspectRatio, mProjectionDirection).LeftPlaneDistance();
801 case Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE:
803 ret = OrthographicSizeConverter(mOrthographicSize, mAspectRatio, mProjectionDirection).RightPlaneDistance();
806 case Dali::CameraActor::Property::TOP_PLANE_DISTANCE:
808 ret = OrthographicSizeConverter(mOrthographicSize, mAspectRatio, mProjectionDirection).TopPlaneDistance();
811 case Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE:
813 ret = OrthographicSizeConverter(mOrthographicSize, mAspectRatio, mProjectionDirection).BottomPlaneDistance();
816 case Dali::CameraActor::Property::TARGET_POSITION:
821 case Dali::CameraActor::Property::PROJECTION_MATRIX:
823 ret = GetProjectionMatrix(); // Only on scene-graph
826 case Dali::CameraActor::Property::VIEW_MATRIX:
828 ret = GetViewMatrix(); // Only on scene-graph
831 case Dali::CameraActor::Property::INVERT_Y_AXIS:
836 case Dali::DevelCameraActor::Property::PROJECTION_DIRECTION:
838 ret = mProjectionDirection;
847 Property::Value CameraActor::GetDefaultPropertyCurrentValue(Property::Index index) const
850 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
852 ret = Actor::GetDefaultPropertyCurrentValue(index);
858 case Dali::CameraActor::Property::FIELD_OF_VIEW:
860 ret = GetCurrentFieldOfView();
863 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
865 ret = GetCurrentOrthographicSize();
868 case Dali::CameraActor::Property::ASPECT_RATIO:
870 ret = GetCurrentAspectRatio();
873 case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE:
875 ret = GetCurrentNearClippingPlane();
878 case Dali::CameraActor::Property::FAR_PLANE_DISTANCE:
880 ret = GetCurrentFarClippingPlane();
883 case Dali::CameraActor::Property::LEFT_PLANE_DISTANCE:
885 ret = OrthographicSizeConverter(GetCurrentOrthographicSize(), GetCurrentAspectRatio(), mProjectionDirection).LeftPlaneDistance();
888 case Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE:
890 ret = OrthographicSizeConverter(GetCurrentOrthographicSize(), GetCurrentAspectRatio(), mProjectionDirection).RightPlaneDistance();
893 case Dali::CameraActor::Property::TOP_PLANE_DISTANCE:
895 ret = OrthographicSizeConverter(GetCurrentOrthographicSize(), GetCurrentAspectRatio(), mProjectionDirection).TopPlaneDistance();
898 case Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE:
900 ret = OrthographicSizeConverter(GetCurrentOrthographicSize(), GetCurrentAspectRatio(), mProjectionDirection).BottomPlaneDistance();
905 ret = GetDefaultProperty(index); // Most are event-side properties, the scene-graph properties are only on the scene-graph
913 void CameraActor::OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType)
915 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
917 Actor::OnNotifyDefaultPropertyAnimation(animation, index, value, animationType);
921 switch(animationType)
924 case Animation::BETWEEN:
928 case Dali::CameraActor::Property::FIELD_OF_VIEW:
930 value.Get(mFieldOfView);
933 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
935 value.Get(mOrthographicSize);
938 case Dali::CameraActor::Property::ASPECT_RATIO:
940 value.Get(mAspectRatio);
943 case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE:
945 value.Get(mNearClippingPlane);
948 case Dali::CameraActor::Property::FAR_PLANE_DISTANCE:
950 value.Get(mFarClippingPlane);
960 case Dali::CameraActor::Property::FIELD_OF_VIEW:
962 AdjustValue<float>(mFieldOfView, value);
965 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
967 AdjustValue<float>(mOrthographicSize, value);
970 case Dali::CameraActor::Property::ASPECT_RATIO:
972 AdjustValue<float>(mAspectRatio, value);
975 case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE:
977 AdjustValue<float>(mNearClippingPlane, value);
980 case Dali::CameraActor::Property::FAR_PLANE_DISTANCE:
982 AdjustValue<float>(mFarClippingPlane, value);
992 const SceneGraph::PropertyBase* CameraActor::GetSceneObjectAnimatableProperty(Property::Index index) const
994 const SceneGraph::PropertyBase* property(nullptr);
997 case Dali::CameraActor::Property::FIELD_OF_VIEW:
999 property = GetCameraSceneObject().GetFieldOfView();
1002 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
1004 property = GetCameraSceneObject().GetOrthographicSize();
1007 case Dali::CameraActor::Property::ASPECT_RATIO:
1009 property = GetCameraSceneObject().GetAspectRatio();
1012 case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE:
1014 property = GetCameraSceneObject().GetNearPlaneDistance();
1017 case Dali::CameraActor::Property::FAR_PLANE_DISTANCE:
1019 property = GetCameraSceneObject().GetFarPlaneDistance();
1022 // no default on purpose as we chain method up to actor
1026 // not our property, ask base
1027 property = Actor::GetSceneObjectAnimatableProperty(index);
1033 const PropertyInputImpl* CameraActor::GetSceneObjectInputProperty(Property::Index index) const
1035 const PropertyInputImpl* property(nullptr);
1039 case Dali::CameraActor::Property::PROJECTION_MODE:
1041 property = GetCameraSceneObject().GetProjectionMode();
1044 case Dali::CameraActor::Property::FIELD_OF_VIEW:
1046 property = GetCameraSceneObject().GetFieldOfView();
1049 case Dali::CameraActor::Property::ASPECT_RATIO:
1051 property = GetCameraSceneObject().GetAspectRatio();
1054 case Dali::CameraActor::Property::NEAR_PLANE_DISTANCE:
1056 property = GetCameraSceneObject().GetNearPlaneDistance();
1059 case Dali::CameraActor::Property::FAR_PLANE_DISTANCE:
1061 property = GetCameraSceneObject().GetFarPlaneDistance();
1064 case Dali::CameraActor::Property::PROJECTION_MATRIX:
1066 property = GetCameraSceneObject().GetProjectionMatrix();
1069 case Dali::CameraActor::Property::VIEW_MATRIX:
1071 property = GetCameraSceneObject().GetViewMatrix();
1074 case Dali::CameraActor::Property::INVERT_Y_AXIS:
1076 property = GetCameraSceneObject().GetInvertYAxis();
1079 case Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE:
1081 property = GetCameraSceneObject().GetOrthographicSize();
1084 case Dali::DevelCameraActor::Property::PROJECTION_DIRECTION:
1086 property = GetCameraSceneObject().GetProjectionDirection();
1089 // no default on purpose as we chain method up to actor
1093 property = Actor::GetSceneObjectInputProperty(index);
1099 void CameraActor::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
1101 // If Position or Orientation are explicitly set, make mPropertyChanged flag true.
1102 if(index == Dali::Actor::Property::POSITION ||
1103 index == Dali::Actor::Property::POSITION_X ||
1104 index == Dali::Actor::Property::POSITION_Y ||
1105 index == Dali::Actor::Property::POSITION_Z ||
1106 index == Dali::Actor::Property::ORIENTATION)
1108 mPropertyChanged = true;
1112 } // namespace Internal