2 * Copyright(c) 2019 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.
18 using System.ComponentModel;
19 using Tizen.NUI.Binding;
24 /// The Rotation class.
26 /// <since_tizen> 3 </since_tizen>
27 [Binding.TypeConverter(typeof(RotationTypeConverter))]
28 public class Rotation : Disposable
32 /// The default constructor.
34 /// <since_tizen> 3 </since_tizen>
35 public Rotation() : this(Interop.Rotation.NewRotation(), true)
37 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
41 /// The constructor from an axis and angle.
43 /// <param name="angle">The angle around the axis.</param>
44 /// <param name="axis">The vector of the axis.</param>
45 /// <since_tizen> 3 </since_tizen>
46 public Rotation(Radian angle, Vector3 axis) : this(Interop.Rotation.NewRotation(Radian.getCPtr(angle), Vector3.getCPtr(axis)), true)
48 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
52 /// The constructor of Rotation which describes minimum rotation to align v0 with v1.
54 /// <param name="v0">The first normalized vector.</param>
55 /// <param name="v1">The second normalized vector.</param>
57 /// v0 and v1 should be normalized.
59 [EditorBrowsable(EditorBrowsableState.Never)]
60 public Rotation(Vector3 v0, Vector3 v1) : this(Interop.Rotation.NewRotation2(Vector3.getCPtr(v0), Vector3.getCPtr(v1)), true)
62 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66 /// (0.0f,0.0f,0.0f,1.0f).
68 /// <since_tizen> 3 </since_tizen>
69 public static Rotation IDENTITY
73 global::System.IntPtr cPtr = Interop.Rotation.IdentityGet();
74 Rotation ret = (cPtr == global::System.IntPtr.Zero) ? null : new Rotation(cPtr, false);
75 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
81 /// The addition operator.
83 /// <param name="arg1">The first rotation.</param>
84 /// <param name="arg2">The second rotation.</param>
85 /// <returns>The rotation containing the result of the addition.</returns>
86 /// <since_tizen> 3 </since_tizen>
87 public static Rotation operator +(Rotation arg1, Rotation arg2)
89 return arg1?.Add(arg2);
93 /// The subtraction operator.
95 /// <param name="arg1">The first rotation.</param>
96 /// <param name="arg2">The second rotation.</param>
97 /// <returns>The rotation containing the result of the subtraction.</returns>
98 /// <since_tizen> 3 </since_tizen>
99 public static Rotation operator -(Rotation arg1, Rotation arg2)
101 return arg1?.Subtract(arg2);
105 /// The unary negation operator.
107 /// <param name="arg1">The first rotation.</param>
108 /// <returns>The rotation containing the negated result.</returns>
109 /// <since_tizen> 3 </since_tizen>
110 public static Rotation operator -(Rotation arg1)
112 return arg1?.Subtract();
116 /// The multiplication operator.
118 /// <param name="arg1">The first rotation.</param>
119 /// <param name="arg2">The second rotation.</param>
120 /// <returns>The rotation containing the result of the multiplication.</returns>
121 /// <since_tizen> 3 </since_tizen>
122 public static Rotation operator *(Rotation arg1, Rotation arg2)
124 return arg1?.Multiply(arg2);
128 /// The multiplication operator.
130 /// <param name="arg1">Rotation.</param>
131 /// <param name="arg2">The vector to multiply.</param>
132 /// <returns>The rotation containing the result of the multiplication.</returns>
133 /// <since_tizen> 3 </since_tizen>
134 public static Vector3 operator *(Rotation arg1, Vector3 arg2)
136 return arg1?.Multiply(arg2);
140 /// The scale operator.
142 /// <param name="arg1">Rotation.</param>
143 /// <param name="arg2">A value to scale by.</param>
144 /// <returns>The rotation containing the result of scaling.</returns>
145 /// <since_tizen> 3 </since_tizen>
146 public static Rotation operator *(Rotation arg1, float arg2)
148 return arg1?.Multiply(arg2);
152 /// The division operator.
154 /// <param name="arg1">The first rotation.</param>
155 /// <param name="arg2">The second rotation.</param>
156 /// <returns>The rotation containing the result of scaling.</returns>
157 /// <since_tizen> 3 </since_tizen>
158 public static Rotation operator /(Rotation arg1, Rotation arg2)
160 return arg1?.Divide(arg2);
164 /// The scale operator.
166 /// <param name="arg1">Rotation.</param>
167 /// <param name="arg2">A value to scale by.</param>
168 /// <returns>The rotation containing the result of scaling.</returns>
169 /// <since_tizen> 3 </since_tizen>
170 public static Rotation operator /(Rotation arg1, float arg2)
172 return arg1?.Divide(arg2);
176 /// Returns the dot product of two rotations.
178 /// <param name="q1">The first rotation.</param>
179 /// <param name="q2">The second rotation.</param>
180 /// <returns>The dot product of the two rotations.</returns>
181 /// <since_tizen> 3 </since_tizen>
182 public static float Dot(Rotation q1, Rotation q2)
184 float ret = Interop.Rotation.Dot(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
185 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190 /// The linear interpolation (using a straight line between the two rotations).
192 /// <param name="q1">The start rotation.</param>
193 /// <param name="q2">The end rotation.</param>
194 /// <param name="t">A progress value between 0 and 1.</param>
195 /// <returns>The interpolated rotation.</returns>
196 /// <since_tizen> 3 </since_tizen>
197 public static Rotation Lerp(Rotation q1, Rotation q2, float t)
199 Rotation ret = new Rotation(Interop.Rotation.Lerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205 /// The spherical linear interpolation (using the shortest arc of a great circle between the two rotations).
207 /// <param name="q1">The start rotation.</param>
208 /// <param name="q2">The end rotation.</param>
209 /// <param name="progress">A progress value between 0 and 1.</param>
210 /// <returns>The interpolated rotation.</returns>
211 /// <since_tizen> 3 </since_tizen>
212 public static Rotation Slerp(Rotation q1, Rotation q2, float progress)
214 Rotation ret = new Rotation(Interop.Rotation.Slerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), progress), true);
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220 /// This version of slerp, used by squad, does not check for theta > 90.
222 /// <param name="q1">The start rotation.</param>
223 /// <param name="q2">The end rotation.</param>
224 /// <param name="t">A progress value between 0 and 1.</param>
225 /// <returns>The interpolated rotation.</returns>
226 /// <since_tizen> 3 </since_tizen>
227 public static Rotation SlerpNoInvert(Rotation q1, Rotation q2, float t)
229 Rotation ret = new Rotation(Interop.Rotation.SlerpNoInvert(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
230 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235 /// The spherical cubic interpolation.
237 /// <param name="start">The start rotation.</param>
238 /// <param name="end">The end rotation.</param>
239 /// <param name="ctrl1">The control rotation for q1.</param>
240 /// <param name="ctrl2">The control rotation for q2.</param>
241 /// <param name="t">A progress value between 0 and 1.</param>
242 /// <returns>The interpolated rotation.</returns>
243 /// <since_tizen> 3 </since_tizen>
244 public static Rotation Squad(Rotation start, Rotation end, Rotation ctrl1, Rotation ctrl2, float t)
246 Rotation ret = new Rotation(Interop.Rotation.Squad(Rotation.getCPtr(start), Rotation.getCPtr(end), Rotation.getCPtr(ctrl1), Rotation.getCPtr(ctrl2), t), true);
247 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 /// Returns the shortest angle between two rotations in radians.
254 /// <param name="q1">The first rotation.</param>
255 /// <param name="q2">The second rotation.</param>
256 /// <returns>The angle between the two rotation.</returns>
257 /// <since_tizen> 3 </since_tizen>
258 public static float AngleBetween(Rotation q1, Rotation q2)
260 float ret = Interop.Rotation.AngleBetween(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 /// Rotate a vector3 with the Rotation.
267 /// For example, if this Rotation has (0, 1, 0) rotation axis and Math.PI radian angle and the input vector is (1, 0, 0),
268 /// this Rotation method returns (-1, 0, 0) that is rotated along Y axis amount of Math.PI.
270 /// <param name="vector">The vector of vector3 to be rotated with this Rotation</param>
271 /// <returns>Vector3 that is the rotation result of this rotation.</returns>
272 [EditorBrowsable(EditorBrowsableState.Never)]
273 public Vector3 Rotate(Vector3 vector)
275 Vector3 ret = new Vector3(Interop.Rotation.RotateVector3(SwigCPtr, Vector3.getCPtr(vector)), true);
276 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281 /// Rotate a vector4 with the Rotation.
282 /// For example, if this Rotation has (0, 1, 0) rotation axis and Math.PI radian angle and the input vector is (1, 0, 0, 0),
283 /// this Rotation method returns (-1, 0, 0, 0) that is rotated along Y axis amount of Math.PI.
285 /// <param name="vector">The vector of vector4 to be rotated with this Rotation</param>
286 /// <returns>Vector4 that is the rotation result of this rotation.</returns>
287 [EditorBrowsable(EditorBrowsableState.Never)]
288 public Vector4 Rotate(Vector4 vector)
290 Vector4 ret = new Vector4(Interop.Rotation.RotateVector4(SwigCPtr, Vector4.getCPtr(vector)), true);
291 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
296 /// Helper to check if this is an identity quaternion.
298 /// <returns>True if this is identity quaternion.</returns>
299 /// <since_tizen> 3 </since_tizen>
300 public bool IsIdentity()
302 bool ret = Interop.Rotation.IsIdentity(SwigCPtr);
303 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 /// Converts the quaternion to an axis or angle pair.
310 /// <param name="axis">The result of an axis.</param>
311 /// <param name="angle">The result of angle in radians.</param>
312 /// <returns>True if converted correctly.</returns>
313 /// <since_tizen> 3 </since_tizen>
314 public bool GetAxisAngle(Vector3 axis, Radian angle)
316 bool ret = Interop.Rotation.GetAxisAngle(SwigCPtr, Vector3.getCPtr(axis), Radian.getCPtr(angle));
317 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322 /// Returns the length of the rotation.
324 /// <returns>The length of the rotation.</returns>
325 /// <since_tizen> 3 </since_tizen>
326 public float Length()
328 float ret = Interop.Rotation.Length(SwigCPtr);
329 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 /// Returns the squared length of the rotation.
336 /// <returns>The squared length of the rotation.</returns>
337 /// <since_tizen> 3 </since_tizen>
338 public float LengthSquared()
340 float ret = Interop.Rotation.LengthSquared(SwigCPtr);
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346 /// Normalizes this to unit length.
348 /// <since_tizen> 3 </since_tizen>
349 public void Normalize()
351 Interop.Rotation.Normalize(SwigCPtr);
352 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358 /// <returns>A normalized version of this rotation.</returns>
359 /// <since_tizen> 3 </since_tizen>
360 public Rotation Normalized()
362 Rotation ret = new Rotation(Interop.Rotation.Normalized(SwigCPtr), true);
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368 /// Conjugates this rotation.
370 /// <since_tizen> 3 </since_tizen>
371 public void Conjugate()
373 Interop.Rotation.Conjugate(SwigCPtr);
374 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 /// Inverts this rotation.
380 /// <since_tizen> 3 </since_tizen>
383 Interop.Rotation.Invert(SwigCPtr);
384 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388 /// Performs the logarithm of a rotation.
390 /// <returns>The rotation representing the logarithm.</returns>
391 /// <since_tizen> 3 </since_tizen>
392 public Rotation Log()
394 Rotation ret = new Rotation(Interop.Rotation.Log(SwigCPtr), true);
395 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 /// Performs an exponent.
402 /// <returns>The rotation representing the exponent.</returns>
403 /// <since_tizen> 3 </since_tizen>
404 public Rotation Exp()
406 Rotation ret = new Rotation(Interop.Rotation.Exp(SwigCPtr), true);
407 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
411 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rotation obj)
413 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
416 internal Rotation(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
420 /// This will not be public opened.
421 [EditorBrowsable(EditorBrowsableState.Never)]
422 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
424 Interop.Rotation.DeleteRotation(swigCPtr);
427 private Rotation Add(Rotation other)
429 Rotation ret = new Rotation(Interop.Rotation.Add(SwigCPtr, Rotation.getCPtr(other)), true);
430 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
434 private Rotation Subtract(Rotation other)
436 Rotation ret = new Rotation(Interop.Rotation.Subtract(SwigCPtr, Rotation.getCPtr(other)), true);
437 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
441 private Rotation Multiply(Rotation other)
443 Rotation ret = new Rotation(Interop.Rotation.MultiplyQuaternion(SwigCPtr, Rotation.getCPtr(other)), true);
444 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
448 private Vector3 Multiply(Vector3 other)
450 Vector3 ret = new Vector3(Interop.Rotation.MultiplyVector3(SwigCPtr, Vector3.getCPtr(other)), true);
451 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
455 private Rotation Divide(Rotation other)
457 Rotation ret = new Rotation(Interop.Rotation.Divide(SwigCPtr, Rotation.getCPtr(other)), true);
458 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
462 private Rotation Multiply(float scale)
464 Rotation ret = new Rotation(Interop.Rotation.Multiply(SwigCPtr, scale), true);
465 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469 private Rotation Divide(float scale)
471 Rotation ret = new Rotation(Interop.Rotation.Divide(SwigCPtr, scale), true);
472 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
476 private Rotation Subtract()
478 Rotation ret = new Rotation(Interop.Rotation.Subtract(SwigCPtr), true);
479 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483 private Rotation AddAssign(Rotation other)
485 Rotation ret = new Rotation(Interop.Rotation.AddAssign(SwigCPtr, Rotation.getCPtr(other)), false);
486 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
490 private Rotation SubtractAssign(Rotation other)
492 Rotation ret = new Rotation(Interop.Rotation.SubtractAssign(SwigCPtr, Rotation.getCPtr(other)), false);
493 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
497 private Rotation MultiplyAssign(Rotation other)
499 Rotation ret = new Rotation(Interop.Rotation.MultiplyAssign(SwigCPtr, Rotation.getCPtr(other)), false);
500 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
504 private Rotation MultiplyAssign(float scale)
506 Rotation ret = new Rotation(Interop.Rotation.MultiplyAssign(SwigCPtr, scale), false);
507 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
511 private Rotation DivideAssign(float scale)
513 Rotation ret = new Rotation(Interop.Rotation.DivideAssign(SwigCPtr, scale), false);
514 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
518 private bool EqualTo(Rotation rhs)
520 bool ret = Interop.Rotation.EqualTo(SwigCPtr, Rotation.getCPtr(rhs));
521 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
525 private bool NotEqualTo(Rotation rhs)
527 bool ret = Interop.Rotation.NotEqualTo(SwigCPtr, Rotation.getCPtr(rhs));
528 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();