From 51b09464a1a1bf22ccbee49f718b5ee5a189452d Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Fri, 30 Sep 2022 19:46:51 +0900 Subject: [PATCH] [NUI.Scene3D] Add ProjectionDirection in Camera Add new property to control major direction of camera FieldOfView. It will effort to FieldOfView and OrthographicSize. Signed-off-by: Eunki, Hong --- .../src/internal/CameraBindableProperty.cs | 22 +++ .../src/internal/Interop/Interop.Camera.cs | 3 + .../src/public/Controls/Camera.cs | 153 ++++++++++++++++++--- 3 files changed, 156 insertions(+), 22 deletions(-) diff --git a/src/Tizen.NUI.Scene3D/src/internal/CameraBindableProperty.cs b/src/Tizen.NUI.Scene3D/src/internal/CameraBindableProperty.cs index 0e1ef47..5090d26 100755 --- a/src/Tizen.NUI.Scene3D/src/internal/CameraBindableProperty.cs +++ b/src/Tizen.NUI.Scene3D/src/internal/CameraBindableProperty.cs @@ -40,6 +40,28 @@ namespace Tizen.NUI.Scene3D }); /// + /// ProjectionDirectionProperty + /// + internal static readonly BindableProperty ProjectionDirectionProperty = BindableProperty.Create(nameof(ProjectionDirection), typeof(ProjectionDirectionType), typeof(Tizen.NUI.Scene3D.Camera), ProjectionDirectionType.Vertical, propertyChanged: (bindable, oldValue, newValue) => + { + var instance = (Tizen.NUI.Scene3D.Camera)bindable; + if (newValue != null) + { + // Keep previous orthographicSize. + float orthographicSize = instance.OrthographicSize; + instance.InternalProjectionDirection = (ProjectionDirectionType)newValue; + + // Recalculate orthographicSize by changed direction. + instance.OrthographicSize = orthographicSize; + } + }, + defaultValueCreator: (bindable) => + { + var instance = (Tizen.NUI.Scene3D.Camera)bindable; + return instance.InternalProjectionDirection; + }); + + /// /// FieldOfViewProperty /// internal static readonly BindableProperty FieldOfViewProperty = BindableProperty.Create(nameof(FieldOfView), typeof(float), typeof(Tizen.NUI.Scene3D.Camera), default(float), propertyChanged: (bindable, oldValue, newValue) => diff --git a/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Camera.cs b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Camera.cs index f7e6b02..acb0089 100755 --- a/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Camera.cs +++ b/src/Tizen.NUI.Scene3D/src/internal/Interop/Interop.Camera.cs @@ -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_PROJECTION_DIRECTION_get")] + public static extern int ProjectionDirectionGet(); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_CameraActor_Property")] public static extern global::System.IntPtr NewCameraProperty(); diff --git a/src/Tizen.NUI.Scene3D/src/public/Controls/Camera.cs b/src/Tizen.NUI.Scene3D/src/public/Controls/Camera.cs index 0d518a2..cb9ab3d 100755 --- a/src/Tizen.NUI.Scene3D/src/public/Controls/Camera.cs +++ b/src/Tizen.NUI.Scene3D/src/public/Controls/Camera.cs @@ -32,23 +32,6 @@ namespace Tizen.NUI.Scene3D /// 10 public partial class Camera : View { - /// - /// Enumeration for the projectionMode. - /// ProjectionMode defines how the camera shows 3D objects or scene on a 2D plane with projection. - /// - /// 10 - public enum ProjectionModeType - { - /// - /// Distance causes foreshortening; objects further from the camera appear smaller. - /// - Perspective, - /// - /// Relative distance from the camera does not affect the size of objects. - /// - Orthographic - } - internal Camera(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) { } @@ -107,6 +90,40 @@ namespace Tizen.NUI.Scene3D } /// + /// Enumeration for the projectionMode. + /// ProjectionMode defines how the camera shows 3D objects or scene on a 2D plane with projection. + /// + /// 10 + public enum ProjectionModeType + { + /// + /// Distance causes foreshortening; objects further from the camera appear smaller. + /// + Perspective, + /// + /// Relative distance from the camera does not affect the size of objects. + /// + Orthographic + } + + /// + /// Enumeration for the projectionDirection. + /// + /// This will be released at Tizen.NET API Level 10, so currently this would be used as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public enum ProjectionDirectionType + { + /// + /// Distance causes foreshortening; objects further from the camera appear smaller. + /// + Vertical, + /// + /// Relative distance from the camera does not affect the size of objects. + /// + Horizontal + } + + /// /// Sets/Gets the projection mode. /// The default is Perspective /// @@ -125,7 +142,41 @@ namespace Tizen.NUI.Scene3D } /// + /// + /// Sets/Gets the projection direction. + /// Projection direction determine basic direction of projection relative properties. + /// It will be used when we need to calculate some values relative with aspect ratio. + /// , and + /// + /// + /// For example, if aspect ratio is 4:3 and set fieldOfView as 60 degree. + /// If ProjectionDirectionType.Vertical, basic direction is vertical. so, FoV of horizontal direction become ~75.2 degree + /// If ProjectionDirectionType.Horizontal, basic direction is horizontal. so, FoV of vertical direction become ~46.8 degree + /// + /// + /// This property doesn't change and value automatically. + /// So result scene might be changed. + /// + /// The default is Vertical. + /// + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) + [EditorBrowsable(EditorBrowsableState.Never)] + public ProjectionDirectionType ProjectionDirection + { + get + { + return (ProjectionDirectionType)GetValue(ProjectionDirectionProperty); + } + set + { + SetValue(ProjectionDirectionProperty, value); + NotifyPropertyChanged(); + } + } + + /// /// Sets/Gets the field of view in Radians. + /// FieldOfView depends on value. /// The default field of view is 45 degrees. /// /// 10 @@ -144,20 +195,32 @@ namespace Tizen.NUI.Scene3D /// /// Sets/Gets Orthographic Size of this camera. - /// OrthographicSize is height/2 of viewing cube of Orthographic projection. - /// Width of viewing cube is internally computed by using aspect ratio of Viewport. + /// OrthographicSize depends on value. + /// If ProjectoinDirection is Vertical, OrthographicSize is height/2 of viewing cube of Orthographic projection. + /// If ProjectoinDirection is Horizontal, OrthographicSize is width/2 of viewing cube of Orthographic projection. + /// Remained Width or Height of viewing cube is internally computed by using aspect ratio of Viewport. /// /// 10 public float OrthographicSize { get { - return TopPlaneDistance; + return InternalProjectionDirection == ProjectionDirectionType.Vertical ? TopPlaneDistance : RightPlaneDistance; } set { - float halfHeight = value; - float halfWidth = AspectRatio * value; + 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); @@ -333,6 +396,24 @@ namespace Tizen.NUI.Scene3D } } + private ProjectionDirectionType InternalProjectionDirection + { + get + { + int returnValue = (int)ProjectionDirectionType.Vertical; + PropertyValue projectionDirection = GetProperty(Interop.Camera.ProjectionDirectionGet()); + projectionDirection?.Get(out returnValue); + projectionDirection?.Dispose(); + return (ProjectionDirectionType)returnValue; + } + set + { + PropertyValue setValue = new Tizen.NUI.PropertyValue((int)value); + SetProperty(Interop.Camera.ProjectionDirectionGet(), setValue); + setValue.Dispose(); + } + } + private float InternalFieldOfView { get @@ -574,6 +655,34 @@ namespace Tizen.NUI.Scene3D } /// + /// Convert from vertical fov to horizontal fov consider with camera's AspectRatio. + /// + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) + [EditorBrowsable(EditorBrowsableState.Never)] + public static Radian ConvertFovFromVerticalToHorizontal(float aspect, Radian verticalFov) + { + if(verticalFov == null) + { + return null; + } + return new Radian(2.0f * (float)Math.Atan(Math.Tan(verticalFov.ConvertToFloat() * 0.5f) * aspect)); + } + + /// + /// Convert from horizontal fov to vertical fov consider with camera's AspectRatio. + /// + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) + [EditorBrowsable(EditorBrowsableState.Never)] + public static Radian ConvertFovFromHorizontalToVertical(float aspect, Radian horizontalFov) + { + if(horizontalFov == null) + { + return null; + } + return new Radian(2.0f * (float)Math.Atan(Math.Tan(horizontalFov.ConvertToFloat() * 0.5f) / aspect)); + } + + /// /// Release swigCPtr. /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) -- 2.7.4