2 * Copyright(c) 2017 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 Tizen.NUI.Binding;
24 /// The Rotation class.
26 /// <since_tizen> 3 </since_tizen>
27 [TypeConverter(typeof(RotationTypeConverter))]
28 public class Rotation : global::System.IDisposable
30 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
34 /// <since_tizen> 3 </since_tizen>
35 protected bool swigCMemOwn;
37 internal Rotation(global::System.IntPtr cPtr, bool cMemoryOwn)
39 swigCMemOwn = cMemoryOwn;
40 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
43 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rotation obj)
45 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
48 //A Flag to check who called Dispose(). (By User or DisposeQueue)
49 private bool isDisposeQueued = false;
51 /// A Flat to check if it is already disposed.
53 /// <since_tizen> 3 </since_tizen>
54 protected bool disposed = false;
59 /// <since_tizen> 3 </since_tizen>
64 isDisposeQueued = true;
65 DisposeQueue.Instance.Add(this);
70 /// To make the Rotation instance be disposed.
72 /// <since_tizen> 3 </since_tizen>
75 //Throw excpetion if Dispose() is called in separate thread.
76 if (!Window.IsInstalled())
78 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
83 Dispose(DisposeTypes.Implicit);
87 Dispose(DisposeTypes.Explicit);
88 System.GC.SuppressFinalize(this);
95 /// <since_tizen> 3 </since_tizen>
96 protected virtual void Dispose(DisposeTypes type)
103 if(type == DisposeTypes.Explicit)
106 //Release your own managed resources here.
107 //You should release all of your own disposable objects here.
110 //Release your own unmanaged resources here.
111 //You should not access any managed member here except static instance.
112 //because the execution order of Finalizes is non-deterministic.
114 if (swigCPtr.Handle != global::System.IntPtr.Zero)
119 NDalicPINVOKE.delete_Rotation(swigCPtr);
121 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
127 /// The addition operator.
129 /// <param name="arg1">The first rotation.</param>
130 /// <param name="arg2">The second rotation.</param>
131 /// <returns>The rotation containing the result of the addition.</returns>
132 /// <since_tizen> 3 </since_tizen>
133 public static Rotation operator +(Rotation arg1, Rotation arg2)
135 return arg1.Add(arg2);
139 /// The subtraction operator.
141 /// <param name="arg1">The first rotation.</param>
142 /// <param name="arg2">The second rotation.</param>
143 /// <returns>The rotation containing the result of the subtraction.</returns>
144 /// <since_tizen> 3 </since_tizen>
145 public static Rotation operator -(Rotation arg1, Rotation arg2)
147 return arg1.Subtract(arg2);
151 /// The unary negation operator.
153 /// <param name="arg1">The first rotation.</param>
154 /// <returns>The rotation containing the negated result.</returns>
155 /// <since_tizen> 3 </since_tizen>
156 public static Rotation operator -(Rotation arg1)
158 return arg1.Subtract();
162 /// The multiplication operator.
164 /// <param name="arg1">The first rotation.</param>
165 /// <param name="arg2">The second rotation.</param>
166 /// <returns>The rotation containing the result of the multiplication.</returns>
167 /// <since_tizen> 3 </since_tizen>
168 public static Rotation operator *(Rotation arg1, Rotation arg2)
170 return arg1.Multiply(arg2);
174 /// The multiplication operator.
176 /// <param name="arg1">Rotation.</param>
177 /// <param name="arg2">The vector to multiply.</param>
178 /// <returns>The rotation containing the result of the multiplication.</returns>
179 /// <since_tizen> 3 </since_tizen>
180 public static Vector3 operator *(Rotation arg1, Vector3 arg2)
182 return arg1.Multiply(arg2);
186 /// The scale operator.
188 /// <param name="arg1">Rotation.</param>
189 /// <param name="arg2">A value to scale by.</param>
190 /// <returns>The rotation containing the result of scaling.</returns>
191 /// <since_tizen> 3 </since_tizen>
192 public static Rotation operator *(Rotation arg1, float arg2)
194 return arg1.Multiply(arg2);
198 /// The division operator.
200 /// <param name="arg1">The first rotation.</param>
201 /// <param name="arg2">The second rotation.</param>
202 /// <returns>The rotation containing the result of scaling.</returns>
203 /// <since_tizen> 3 </since_tizen>
204 public static Rotation operator /(Rotation arg1, Rotation arg2)
206 return arg1.Divide(arg2);
210 /// The scale operator.
212 /// <param name="arg1">Rotation.</param>
213 /// <param name="arg2">A value to scale by.</param>
214 /// <returns>The rotation containing the result of scaling.</returns>
215 /// <since_tizen> 3 </since_tizen>
216 public static Rotation operator /(Rotation arg1, float arg2)
218 return arg1.Divide(arg2);
222 /// The default constructor.
224 /// <since_tizen> 3 </since_tizen>
225 public Rotation() : this(NDalicPINVOKE.new_Rotation__SWIG_0(), true)
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231 /// The constructor from an axis and angle.
233 /// <param name="angle">The angle around the axis.</param>
234 /// <param name="axis">The vector of the axis.</param>
235 /// <since_tizen> 3 </since_tizen>
236 public Rotation(Radian angle, Vector3 axis) : this(NDalicPINVOKE.new_Rotation__SWIG_1(Radian.getCPtr(angle), Vector3.getCPtr(axis)), true)
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242 /// (0.0f,0.0f,0.0f,1.0f).
244 /// <since_tizen> 3 </since_tizen>
245 public static Rotation IDENTITY
249 global::System.IntPtr cPtr = NDalicPINVOKE.Rotation_IDENTITY_get();
250 Rotation ret = (cPtr == global::System.IntPtr.Zero) ? null : new Rotation(cPtr, false);
251 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257 /// Helper to check if this is an identity quaternion.
259 /// <returns>True if this is identity quaternion.</returns>
260 /// <since_tizen> 3 </since_tizen>
261 public bool IsIdentity()
263 bool ret = NDalicPINVOKE.Rotation_IsIdentity(swigCPtr);
264 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269 /// Converts the quaternion to an axis or angle pair.
271 /// <param name="axis">The result of an an axis.</param>
272 /// <param name="angle">The result of angle in radians.</param>
273 /// <returns>True if converted correctly.</returns>
274 /// <since_tizen> 3 </since_tizen>
275 public bool GetAxisAngle(Vector3 axis, Radian angle)
277 bool ret = NDalicPINVOKE.Rotation_GetAxisAngle(swigCPtr, Vector3.getCPtr(axis), Radian.getCPtr(angle));
278 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282 private Rotation Add(Rotation other)
284 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Add(swigCPtr, Rotation.getCPtr(other)), true);
285 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 private Rotation Subtract(Rotation other)
291 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Subtract__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
296 private Rotation Multiply(Rotation other)
298 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Multiply__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
299 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
303 private Vector3 Multiply(Vector3 other)
305 Vector3 ret = new Vector3(NDalicPINVOKE.Rotation_Multiply__SWIG_1(swigCPtr, Vector3.getCPtr(other)), true);
306 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310 private Rotation Divide(Rotation other)
312 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Divide__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
313 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 private Rotation Multiply(float scale)
319 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Multiply__SWIG_2(swigCPtr, scale), true);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 private Rotation Divide(float scale)
326 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Divide__SWIG_1(swigCPtr, scale), true);
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331 private Rotation Subtract()
333 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Subtract__SWIG_1(swigCPtr), true);
334 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338 private Rotation AddAssign(Rotation other)
340 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_AddAssign(swigCPtr, Rotation.getCPtr(other)), false);
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 private Rotation SubtractAssign(Rotation other)
347 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_SubtractAssign(swigCPtr, Rotation.getCPtr(other)), false);
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352 private Rotation MultiplyAssign(Rotation other)
354 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_MultiplyAssign__SWIG_0(swigCPtr, Rotation.getCPtr(other)), false);
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 private Rotation MultiplyAssign(float scale)
361 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_MultiplyAssign__SWIG_1(swigCPtr, scale), false);
362 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
366 private Rotation DivideAssign(float scale)
368 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_DivideAssign(swigCPtr, scale), false);
369 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 private bool EqualTo(Rotation rhs)
375 bool ret = NDalicPINVOKE.Rotation_EqualTo(swigCPtr, Rotation.getCPtr(rhs));
376 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380 private bool NotEqualTo(Rotation rhs)
382 bool ret = NDalicPINVOKE.Rotation_NotEqualTo(swigCPtr, Rotation.getCPtr(rhs));
383 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388 /// Returns the length of the rotation.
390 /// <returns>The length of the rotation.</returns>
391 /// <since_tizen> 3 </since_tizen>
392 public float Length()
394 float ret = NDalicPINVOKE.Rotation_Length(swigCPtr);
395 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 /// Returns the squared length of the rotation.
402 /// <returns>The squared length of the rotation.</returns>
403 /// <since_tizen> 3 </since_tizen>
404 public float LengthSquared()
406 float ret = NDalicPINVOKE.Rotation_LengthSquared(swigCPtr);
407 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
412 /// Normalizes this to unit length.
414 /// <since_tizen> 3 </since_tizen>
415 public void Normalize()
417 NDalicPINVOKE.Rotation_Normalize(swigCPtr);
418 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424 /// <returns>A normalized version of this rotation.</returns>
425 /// <since_tizen> 3 </since_tizen>
426 public Rotation Normalized()
428 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Normalized(swigCPtr), true);
429 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
434 /// Conjugates this rotation.
436 /// <since_tizen> 3 </since_tizen>
437 public void Conjugate()
439 NDalicPINVOKE.Rotation_Conjugate(swigCPtr);
440 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
444 /// Inverts this rotation.
446 /// <since_tizen> 3 </since_tizen>
449 NDalicPINVOKE.Rotation_Invert(swigCPtr);
450 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
454 /// Performs the logarithm of a rotation.
456 /// <returns>The rotation representing the logarithm.</returns>
457 /// <since_tizen> 3 </since_tizen>
458 public Rotation Log()
460 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Log(swigCPtr), true);
461 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
466 /// Performs an exponent.
468 /// <returns>The rotation representing the exponent.</returns>
469 /// <since_tizen> 3 </since_tizen>
470 public Rotation Exp()
472 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Exp(swigCPtr), true);
473 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
478 /// Returns the dot product of two rotations.
480 /// <param name="q1">The first rotation.</param>
481 /// <param name="q2">The second rotation.</param>
482 /// <returns>The dot product of the two rotations.</returns>
483 /// <since_tizen> 3 </since_tizen>
484 public static float Dot(Rotation q1, Rotation q2)
486 float ret = NDalicPINVOKE.Rotation_Dot(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
487 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
492 /// The linear iterpolation (using a straight line between the two rotations).
494 /// <param name="q1">The start rotation.</param>
495 /// <param name="q2">The end rotation.</param>
496 /// <param name="t">A progress value between 0 and 1.</param>
497 /// <returns>The interpolated rotation.</returns>
498 /// <since_tizen> 3 </since_tizen>
499 public static Rotation Lerp(Rotation q1, Rotation q2, float t)
501 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Lerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
502 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
507 /// The spherical linear interpolation (using the shortest arc of a great circle between the two rotations).
509 /// <param name="q1">The start rotation.</param>
510 /// <param name="q2">The end rotation.</param>
511 /// <param name="progress">A progress value between 0 and 1.</param>
512 /// <returns>The interpolated rotation.</returns>
513 /// <since_tizen> 3 </since_tizen>
514 public static Rotation Slerp(Rotation q1, Rotation q2, float progress)
516 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Slerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), progress), true);
517 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
522 /// This version of slerp, used by squad, does not check for theta > 90.
524 /// <param name="q1">The start rotation.</param>
525 /// <param name="q2">The end rotation.</param>
526 /// <param name="t">A progress value between 0 and 1.</param>
527 /// <returns>The interpolated rotation.</returns>
528 /// <since_tizen> 3 </since_tizen>
529 public static Rotation SlerpNoInvert(Rotation q1, Rotation q2, float t)
531 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_SlerpNoInvert(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
532 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
537 /// The spherical cubic interpolation.
539 /// <param name="start">The start rotation.</param>
540 /// <param name="end">The end rotation.</param>
541 /// <param name="ctrl1">The control rotation for q1.</param>
542 /// <param name="ctrl2">The control rotation for q2.</param>
543 /// <param name="t">A progress value between 0 and 1.</param>
544 /// <returns>The interpolated rotation.</returns>
545 /// <since_tizen> 3 </since_tizen>
546 public static Rotation Squad(Rotation start, Rotation end, Rotation ctrl1, Rotation ctrl2, float t)
548 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Squad(Rotation.getCPtr(start), Rotation.getCPtr(end), Rotation.getCPtr(ctrl1), Rotation.getCPtr(ctrl2), t), true);
549 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
554 /// Returns the shortest angle between two rotations in radians.
556 /// <param name="q1">The first rotation.</param>
557 /// <param name="q2">The second rotation.</param>
558 /// <returns>The angle between the two rotation.</returns>
559 /// <since_tizen> 3 </since_tizen>
560 public static float AngleBetween(Rotation q1, Rotation q2)
562 float ret = NDalicPINVOKE.Rotation_AngleBetween(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
563 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();