[NUI] Rotation class with EulerAngle (pitch/yaw/roll)
authorEunki Hong <eunkiki.hong@samsung.com>
Mon, 10 Apr 2023 17:01:19 +0000 (02:01 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 13 Apr 2023 04:51:31 +0000 (13:51 +0900)
Add API that we can set Rotation by pitch/yaw/roll +
Get Rotation informations as pitch/yaw/roll

Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/internal/Interop/Interop.Rotation.cs
src/Tizen.NUI/src/public/Common/Rotation.cs
test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/public/Common/TSRotation.cs [new file with mode: 0755]

index 7297740..3273505 100755 (executable)
@@ -30,6 +30,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_Rotation_2")]
             public static extern global::System.IntPtr NewRotation2(global::System.Runtime.InteropServices.HandleRef v0, global::System.Runtime.InteropServices.HandleRef v1);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_Rotation_3")]
+            public static extern global::System.IntPtr NewRotation3(global::System.Runtime.InteropServices.HandleRef pitch, global::System.Runtime.InteropServices.HandleRef yaw, global::System.Runtime.InteropServices.HandleRef roll);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_Rotation")]
             public static extern void DeleteRotation(global::System.Runtime.InteropServices.HandleRef rotation);
 
@@ -44,6 +47,12 @@ namespace Tizen.NUI
             [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
             public static extern bool GetAxisAngle(global::System.Runtime.InteropServices.HandleRef rotation, global::System.Runtime.InteropServices.HandleRef axis, global::System.Runtime.InteropServices.HandleRef radianAngle);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Rotation_SetEulerAngle")]
+            public static extern void SetEulerAngle(global::System.Runtime.InteropServices.HandleRef rotation, global::System.Runtime.InteropServices.HandleRef pitch, global::System.Runtime.InteropServices.HandleRef yaw, global::System.Runtime.InteropServices.HandleRef roll);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Rotation_GetEulerAngle")]
+            public static extern void GetEulerAngle(global::System.Runtime.InteropServices.HandleRef rotation, global::System.Runtime.InteropServices.HandleRef pitch, global::System.Runtime.InteropServices.HandleRef yaw, global::System.Runtime.InteropServices.HandleRef roll);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Rotation_Add")]
             public static extern global::System.IntPtr Add(global::System.Runtime.InteropServices.HandleRef rotation0, global::System.Runtime.InteropServices.HandleRef rotation1);
 
index ea18ea7..2c303f0 100755 (executable)
@@ -63,6 +63,18 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// The constructor of Rotation from Euler angles.
+        /// </summary>
+        /// <param name="pitch">Pitch value as Radian.</param>
+        /// <param name="yaw">Yaw value as Radian</param>
+        /// <param name="roll">Roll value as Radian</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Rotation(Radian pitch, Radian yaw, Radian roll) : this(Interop.Rotation.NewRotation3(Radian.getCPtr(pitch), Radian.getCPtr(yaw), Radian.getCPtr(roll)), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
         /// (0.0f,0.0f,0.0f,1.0f).
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -319,6 +331,32 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Set the quaternion from Euler angles.
+        /// </summary>
+        /// <param name="pitch">Pitch value as Radian.</param>
+        /// <param name="yaw">Yaw value as Radian</param>
+        /// <param name="roll">Roll value as Radian</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetEulerAngle(Radian pitch, Radian yaw, Radian roll)
+        {
+            Interop.Rotation.SetEulerAngle(SwigCPtr, Radian.getCPtr(pitch), Radian.getCPtr(yaw), Radian.getCPtr(roll));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Get the Euler angles from this quaternion.
+        /// </summary>
+        /// <param name="pitch">The result of pitch value as Radian.</param>
+        /// <param name="yaw">The result of yaw value as Radian</param>
+        /// <param name="roll">The result of roll value as Radian</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void GetEulerAngle(Radian pitch, Radian yaw, Radian roll)
+        {
+            Interop.Rotation.GetEulerAngle(SwigCPtr, Radian.getCPtr(pitch), Radian.getCPtr(yaw), Radian.getCPtr(roll));
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
         /// Returns the length of the rotation.
         /// </summary>
         /// <returns>The length of the rotation.</returns>
diff --git a/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/public/Common/TSRotation.cs b/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/public/Common/TSRotation.cs
new file mode 100755 (executable)
index 0000000..6b4fe86
--- /dev/null
@@ -0,0 +1,115 @@
+using global::System;
+using NUnit.Framework;
+using NUnit.Framework.TUnit;
+using Tizen.NUI;
+
+namespace Tizen.NUI.Devel.Tests
+{
+    using tlog = Tizen.Log;
+
+    [TestFixture]
+    [Description("public/Common/Rotation")]
+    public class RotationTest
+    {
+        private const string tag = "NUITEST";
+
+        [SetUp]
+        public void Init()
+        {
+            tlog.Info(tag, "Init() is called!");
+        }
+
+        [TearDown]
+        public void Destroy()
+        {
+            tlog.Info(tag, "Destroy() is called!");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Rotation constructor. With Euler Angles")]
+        [Property("SPEC", "Tizen.NUI.Rotation.Rotation C")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "CONSTR")]
+        [Property("AUTHOR", "eunkiki.hong@samsung.com")]
+        public void RotationConstructorWithEulerAngle()
+        {
+            tlog.Debug(tag, $"RotationConstructorWithEulerAngle START");
+
+            var testingTarget = new Rotation(new Radian(new Degree(30.0f)), new Radian(new Degree(45.0f)), new Radian(new Degree(60.0f)));
+            Assert.IsNotNull(testingTarget, "Can't create success object Rotation.");
+            Assert.IsInstanceOf<Rotation>(testingTarget, "Should return Rotation instance.");
+
+            testingTarget.Dispose();
+            tlog.Debug(tag, $"RotationConstructorWithEulerAngle END (OK)");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Rotation SetEulerAngle.")]
+        [Property("SPEC", "Tizen.NUI.Rotation.SetEulerAngle M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "eunkiki.hong@samsung.com")]
+        public void RotationSetEulerAngle()
+        {
+            tlog.Debug(tag, $"RotationSetEulerAngle START");
+
+            var testingTarget = new Rotation();
+            Assert.IsNotNull(testingTarget, "Can't create success object Rotation.");
+            Assert.IsInstanceOf<Rotation>(testingTarget, "Should return Rotation instance.");
+
+            try
+            {
+                testingTarget.SetEulerAngle(new Radian(new Degree(30.0f)), new Radian(new Degree(45.0f)), new Radian(new Degree(60.0f)));
+            }
+            catch (Exception e)
+            {
+                tlog.Debug(tag, e.Message.ToString());
+                Assert.Fail("Caught Exception : Failed!");
+            }
+
+            testingTarget.Dispose();
+            tlog.Debug(tag, $"RotationSetEulerAngle END (OK)");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Rotation GetEulerAngle.")]
+        [Property("SPEC", "Tizen.NUI.Rotation.GetEulerAngle M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "eunkiki.hong@samsung.com")]
+        public void RotationGetEulerAngle()
+        {
+            tlog.Debug(tag, $"RotationGetEulerAngle START");
+
+            var expectPitchRadian = new Radian(new Degree(30.0f));
+            var expectYawRadian = new Radian(new Degree(45.0f));
+            var expectRollRadian = new Radian(new Degree(60.0f));
+            var testingTarget = new Rotation(expectPitchRadian, expectYawRadian, expectRollRadian);
+            Assert.IsNotNull(testingTarget, "Can't create success object Rotation.");
+            Assert.IsInstanceOf<Rotation>(testingTarget, "Should return Rotation instance.");
+
+            try
+            {
+                using var pitch = new Radian();
+                using var yaw = new Radian();
+                using var roll = new Radian();
+                testingTarget.GetEulerAngle(pitch, yaw, roll);
+
+                Assert.AreEqual(expectPitchRadian.Value, pitch.Value, 0.001, "Pitch value should be same");
+                Assert.AreEqual(expectYawRadian.Value, yaw.Value,  0.001, "Yaw value should be same");
+                Assert.AreEqual(expectRollRadian.Value, roll.Value, 0.001, "Roll value should be same");
+            }
+            catch (Exception e)
+            {
+                tlog.Debug(tag, e.Message.ToString());
+                Assert.Fail("Caught Exception : Failed!");
+            }
+
+            testingTarget.Dispose();
+            tlog.Debug(tag, $"RotationGetEulerAngle END (OK)");
+        }
+    }
+}