[NUI.Scene3D] OrthographicSize native binding
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 7 Nov 2022 12:15:20 +0000 (21:15 +0900)
committerJaehyun Cho <jaehyun0cho@gmail.com>
Wed, 23 Nov 2022 09:19:17 +0000 (18:19 +0900)
Let we use orthographicSize as native side.
And make it animatable

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI.Scene3D/src/internal/CameraBindableProperty.cs
src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Camera.cs
src/Tizen.NUI.Scene3D/src/public/Controls/Camera.cs
src/Tizen.NUI.Scene3D/src/public/Controls/SceneView.cs

index 5090d26..24c75ba 100755 (executable)
@@ -79,6 +79,23 @@ namespace Tizen.NUI.Scene3D
         });
 
         /// <summary>
+        /// OrthographicSizeProperty
+        /// </summary>
+        internal static readonly BindableProperty OrthographicSizeProperty = BindableProperty.Create(nameof(OrthographicSize), typeof(float), typeof(Tizen.NUI.Scene3D.Camera), default(float), propertyChanged: (bindable, oldValue, newValue) =>
+        {
+            var instance = (Tizen.NUI.Scene3D.Camera)bindable;
+            if (newValue != null)
+            {
+                instance.InternalOrthographicSize = (float)newValue;
+            }
+        },
+        defaultValueCreator: (bindable) =>
+        {
+            var instance = (Tizen.NUI.Scene3D.Camera)bindable;
+            return instance.InternalOrthographicSize;
+        });
+
+        /// <summary>
         /// AspectRatioProperty
         /// </summary>
         internal static readonly BindableProperty AspectRatioProperty = BindableProperty.Create(nameof(AspectRatio), typeof(float), typeof(Tizen.NUI.Scene3D.Camera), default(float), propertyChanged: (bindable, oldValue, newValue) =>
index acb0089..4976040 100755 (executable)
@@ -57,6 +57,9 @@ namespace Tizen.NUI.Scene3D
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_CameraActor_Property_INVERT_Y_AXIS_get")]
             public static extern int InvertYAxisGet();
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_CameraActor_Property_ORTHOGRAPHIC_SIZE_get")]
+            public static extern int OrthographicSizeGet();
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_CameraActor_Property_PROJECTION_DIRECTION_get")]
             public static extern int ProjectionDirectionGet();
 
index cb9ab3d..e7e19f8 100755 (executable)
@@ -205,26 +205,11 @@ namespace Tizen.NUI.Scene3D
         {
             get
             {
-                return InternalProjectionDirection == ProjectionDirectionType.Vertical ? TopPlaneDistance : RightPlaneDistance;
+                return InternalOrthographicSize;
             }
             set
             {
-                float halfHeight;
-                float halfWidth;
-                if(InternalProjectionDirection == ProjectionDirectionType.Vertical)
-                {
-                    halfHeight = value;
-                    halfWidth = AspectRatio * value;
-                }
-                else
-                {
-                    halfHeight = value / AspectRatio;
-                    halfWidth = value;
-                }
-                SetValue(TopPlaneDistanceProperty, halfHeight);
-                SetValue(BottomPlaneDistanceProperty, -halfHeight);
-                SetValue(LeftPlaneDistanceProperty, -halfWidth);
-                SetValue(RightPlaneDistanceProperty, halfWidth);
+                SetValue(OrthographicSizeProperty, value);
                 NotifyPropertyChanged();
             }
         }
@@ -432,6 +417,24 @@ namespace Tizen.NUI.Scene3D
             }
         }
 
+        private float InternalOrthographicSize
+        {
+            get
+            {
+                float returnValue = 0.0f;
+                PropertyValue orthographicSize = GetProperty(Interop.Camera.OrthographicSizeGet());
+                orthographicSize?.Get(out returnValue);
+                orthographicSize?.Dispose();
+                return returnValue;
+            }
+            set
+            {
+                PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
+                SetProperty(Interop.Camera.OrthographicSizeGet(), setValue);
+                setValue.Dispose();
+            }
+        }
+
         private float InternalAspectRatio
         {
             get
index 8e040aa..6525a00 100755 (executable)
@@ -542,25 +542,9 @@ namespace Tizen.NUI.Scene3D
 
             Position sourcePosition = sourceCamera.Position;
             Rotation sourceOrientation = sourceCamera.Orientation;
-            Radian   sourceFieldOfView = sourceCamera.FieldOfView;
 
             Position destinationPosition = destinationCamera.Position;
             Rotation destinationOrientation = destinationCamera.Orientation;
-            Radian   destinationFieldOfView = destinationCamera.FieldOfView;
-
-            // If ProjectionDirection is not equal, match the value.
-            if (sourceCamera.ProjectionDirection != destinationCamera.ProjectionDirection)
-            {
-                float aspect = destinationCamera.AspectRatio;
-                if (destinationCamera.ProjectionDirection == Camera.ProjectionDirectionType.Vertical)
-                {
-                    sourceFieldOfView = Camera.ConvertFovFromHorizontalToVertical(aspect, sourceFieldOfView);
-                }
-                else
-                {
-                    sourceFieldOfView = Camera.ConvertFovFromVerticalToHorizontal(aspect, sourceFieldOfView);
-                }
-            }
 
             cameraTransition = new Animation(durationMilliSeconds);
 
@@ -572,13 +556,63 @@ namespace Tizen.NUI.Scene3D
             orientationKeyFrames.Add(0.0f, sourceOrientation);
             orientationKeyFrames.Add(1.0f, destinationOrientation);
 
-            KeyFrames fieldOfViewKeyFrames = new KeyFrames();
-            fieldOfViewKeyFrames.Add(0.0f, sourceFieldOfView.ConvertToFloat());
-            fieldOfViewKeyFrames.Add(1.0f, destinationFieldOfView.ConvertToFloat());
-
             cameraTransition.AnimateBetween(destinationCamera, "Position", positionKeyFrames, Animation.Interpolation.Linear, alphaFunction);
             cameraTransition.AnimateBetween(destinationCamera, "Orientation", orientationKeyFrames, Animation.Interpolation.Linear, alphaFunction);
-            cameraTransition.AnimateBetween(destinationCamera, "FieldOfView", fieldOfViewKeyFrames, Animation.Interpolation.Linear, alphaFunction);
+
+            if(destinationCamera.ProjectionMode == Camera.ProjectionModeType.Perspective)
+            {
+                Radian sourceFieldOfView = sourceCamera.FieldOfView;
+                Radian destinationFieldOfView = destinationCamera.FieldOfView;
+
+                // If ProjectionDirection is not equal, match the value.
+                if (sourceCamera.ProjectionDirection != destinationCamera.ProjectionDirection)
+                {
+                    float aspect = destinationCamera.AspectRatio;
+                    if (destinationCamera.ProjectionDirection == Camera.ProjectionDirectionType.Vertical)
+                    {
+                        sourceFieldOfView = Camera.ConvertFovFromHorizontalToVertical(aspect, sourceFieldOfView);
+                    }
+                    else
+                    {
+                        sourceFieldOfView = Camera.ConvertFovFromVerticalToHorizontal(aspect, sourceFieldOfView);
+                    }
+                }
+
+                KeyFrames fieldOfViewKeyFrames = new KeyFrames();
+                fieldOfViewKeyFrames.Add(0.0f, sourceFieldOfView.ConvertToFloat());
+                fieldOfViewKeyFrames.Add(1.0f, destinationFieldOfView.ConvertToFloat());
+                cameraTransition.AnimateBetween(destinationCamera, "FieldOfView", fieldOfViewKeyFrames, Animation.Interpolation.Linear, alphaFunction);
+
+                sourceFieldOfView.Dispose();
+                destinationFieldOfView.Dispose();
+                fieldOfViewKeyFrames.Dispose();
+            }
+            else
+            {
+                float sourceOrthographicSize = sourceCamera.OrthographicSize;
+                float destinationOrthographicSize = destinationCamera.OrthographicSize;
+
+                // If ProjectionDirection is not equal, match the value.
+                if (sourceCamera.ProjectionDirection != destinationCamera.ProjectionDirection)
+                {
+                    float aspect = destinationCamera.AspectRatio;
+                    if (destinationCamera.ProjectionDirection == Camera.ProjectionDirectionType.Vertical)
+                    {
+                        sourceOrthographicSize = sourceOrthographicSize / aspect;
+                    }
+                    else
+                    {
+                        sourceOrthographicSize = sourceOrthographicSize * aspect;
+                    }
+                }
+
+                KeyFrames orthographicSizeKeyFrames = new KeyFrames();
+                orthographicSizeKeyFrames.Add(0.0f, sourceOrthographicSize);
+                orthographicSizeKeyFrames.Add(1.0f, destinationOrthographicSize);
+                cameraTransition.AnimateBetween(destinationCamera, "OrthographicSize", orthographicSizeKeyFrames, Animation.Interpolation.Linear, alphaFunction);
+
+                orthographicSizeKeyFrames.Dispose();
+            }
 
             cameraTransition.Finished += (s, e) =>
             {
@@ -587,10 +621,8 @@ namespace Tizen.NUI.Scene3D
             };
             cameraTransition.Play();
 
-            sourceFieldOfView.Dispose();
             positionKeyFrames.Dispose();
             orientationKeyFrames.Dispose();
-            fieldOfViewKeyFrames.Dispose();
         }
 
         /// <summary>