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.
22 /// The Rotation class.
24 public class Rotation : global::System.IDisposable
26 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30 /// <since_tizen> 3 </since_tizen>
31 protected bool swigCMemOwn;
33 internal Rotation(global::System.IntPtr cPtr, bool cMemoryOwn)
35 swigCMemOwn = cMemoryOwn;
36 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
39 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rotation obj)
41 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44 //A Flag to check who called Dispose(). (By User or DisposeQueue)
45 private bool isDisposeQueued = false;
47 /// A Flat to check if it is already disposed.
49 /// <since_tizen> 3 </since_tizen>
50 protected bool disposed = false;
55 /// <since_tizen> 3 </since_tizen>
60 isDisposeQueued = true;
61 DisposeQueue.Instance.Add(this);
66 /// To make the Rotation instance be disposed.
68 /// <since_tizen> 3 </since_tizen>
71 //Throw excpetion if Dispose() is called in separate thread.
72 if (!Window.IsInstalled())
74 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
79 Dispose(DisposeTypes.Implicit);
83 Dispose(DisposeTypes.Explicit);
84 System.GC.SuppressFinalize(this);
91 /// <since_tizen> 3 </since_tizen>
92 protected virtual void Dispose(DisposeTypes type)
99 if(type == DisposeTypes.Explicit)
102 //Release your own managed resources here.
103 //You should release all of your own disposable objects here.
106 //Release your own unmanaged resources here.
107 //You should not access any managed member here except static instance.
108 //because the execution order of Finalizes is non-deterministic.
110 if (swigCPtr.Handle != global::System.IntPtr.Zero)
115 NDalicPINVOKE.delete_Rotation(swigCPtr);
117 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
123 /// The addition operator.
125 /// <param name="arg1">The first rotation.</param>
126 /// <param name="arg2">The second rotation.</param>
127 /// <returns>The rotation containing the result of the addition.</returns>
128 /// <since_tizen> 3 </since_tizen>
129 public static Rotation operator +(Rotation arg1, Rotation arg2)
131 return arg1.Add(arg2);
135 /// The subtraction operator.
137 /// <param name="arg1">The first rotation.</param>
138 /// <param name="arg2">The second rotation.</param>
139 /// <returns>The rotation containing the result of the subtraction.</returns>
140 /// <since_tizen> 3 </since_tizen>
141 public static Rotation operator -(Rotation arg1, Rotation arg2)
143 return arg1.Subtract(arg2);
147 /// The unary negation operator.
149 /// <param name="arg1">The first rotation.</param>
150 /// <returns>The rotation containing the negated result.</returns>
151 /// <since_tizen> 3 </since_tizen>
152 public static Rotation operator -(Rotation arg1)
154 return arg1.Subtract();
158 /// The multiplication operator.
160 /// <param name="arg1">The first rotation.</param>
161 /// <param name="arg2">The second rotation.</param>
162 /// <returns>The rotation containing the result of the multiplication.</returns>
163 /// <since_tizen> 3 </since_tizen>
164 public static Rotation operator *(Rotation arg1, Rotation arg2)
166 return arg1.Multiply(arg2);
170 /// The multiplication operator.
172 /// <param name="arg1">Rotation.</param>
173 /// <param name="arg2">The vector to multiply.</param>
174 /// <returns>The rotation containing the result of the multiplication.</returns>
175 /// <since_tizen> 3 </since_tizen>
176 public static Vector3 operator *(Rotation arg1, Vector3 arg2)
178 return arg1.Multiply(arg2);
182 /// The scale operator.
184 /// <param name="arg1">Rotation.</param>
185 /// <param name="arg2">A value to scale by.</param>
186 /// <returns>The rotation containing the result of scaling.</returns>
187 /// <since_tizen> 3 </since_tizen>
188 public static Rotation operator *(Rotation arg1, float arg2)
190 return arg1.Multiply(arg2);
194 /// The division operator.
196 /// <param name="arg1">The first rotation.</param>
197 /// <param name="arg2">The second rotation.</param>
198 /// <returns>The rotation containing the result of scaling.</returns>
199 /// <since_tizen> 3 </since_tizen>
200 public static Rotation operator /(Rotation arg1, Rotation arg2)
202 return arg1.Divide(arg2);
206 /// The scale operator.
208 /// <param name="arg1">Rotation.</param>
209 /// <param name="arg2">A value to scale by.</param>
210 /// <returns>The rotation containing the result of scaling.</returns>
211 /// <since_tizen> 3 </since_tizen>
212 public static Rotation operator /(Rotation arg1, float arg2)
214 return arg1.Divide(arg2);
218 /// The default constructor.
220 /// <since_tizen> 3 </since_tizen>
221 public Rotation() : this(NDalicPINVOKE.new_Rotation__SWIG_0(), true)
223 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227 /// The constructor from an axis and angle.
229 /// <param name="angle">The angle around the axis.</param>
230 /// <param name="axis">The vector of the axis.</param>
231 /// <since_tizen> 3 </since_tizen>
232 public Rotation(Radian angle, Vector3 axis) : this(NDalicPINVOKE.new_Rotation__SWIG_1(Radian.getCPtr(angle), Vector3.getCPtr(axis)), true)
234 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 /// (0.0f,0.0f,0.0f,1.0f).
240 /// <since_tizen> 3 </since_tizen>
241 public static Rotation IDENTITY
245 global::System.IntPtr cPtr = NDalicPINVOKE.Rotation_IDENTITY_get();
246 Rotation ret = (cPtr == global::System.IntPtr.Zero) ? null : new Rotation(cPtr, false);
247 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253 /// Helper to check if this is an identity quaternion.
255 /// <returns>True if this is identity quaternion.</returns>
256 /// <since_tizen> 3 </since_tizen>
257 public bool IsIdentity()
259 bool ret = NDalicPINVOKE.Rotation_IsIdentity(swigCPtr);
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 /// Converts the quaternion to an axis or angle pair.
267 /// <param name="axis">The result of an an axis.</param>
268 /// <param name="angle">The result of angle in radians.</param>
269 /// <returns>True if converted correctly.</returns>
270 /// <since_tizen> 3 </since_tizen>
271 public bool GetAxisAngle(Vector3 axis, Radian angle)
273 bool ret = NDalicPINVOKE.Rotation_GetAxisAngle(swigCPtr, Vector3.getCPtr(axis), Radian.getCPtr(angle));
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278 private Rotation Add(Rotation other)
280 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Add(swigCPtr, Rotation.getCPtr(other)), true);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 private Rotation Subtract(Rotation other)
287 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Subtract__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
288 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292 private Rotation Multiply(Rotation other)
294 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Multiply__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
295 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299 private Vector3 Multiply(Vector3 other)
301 Vector3 ret = new Vector3(NDalicPINVOKE.Rotation_Multiply__SWIG_1(swigCPtr, Vector3.getCPtr(other)), true);
302 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306 private Rotation Divide(Rotation other)
308 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Divide__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
309 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313 private Rotation Multiply(float scale)
315 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Multiply__SWIG_2(swigCPtr, scale), true);
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 private Rotation Divide(float scale)
322 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Divide__SWIG_1(swigCPtr, scale), true);
323 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
327 private Rotation Subtract()
329 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Subtract__SWIG_1(swigCPtr), true);
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 private Rotation AddAssign(Rotation other)
336 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_AddAssign(swigCPtr, Rotation.getCPtr(other)), false);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341 private Rotation SubtractAssign(Rotation other)
343 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_SubtractAssign(swigCPtr, Rotation.getCPtr(other)), false);
344 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 private Rotation MultiplyAssign(Rotation other)
350 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_MultiplyAssign__SWIG_0(swigCPtr, Rotation.getCPtr(other)), false);
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 private Rotation MultiplyAssign(float scale)
357 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_MultiplyAssign__SWIG_1(swigCPtr, scale), false);
358 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 private Rotation DivideAssign(float scale)
364 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_DivideAssign(swigCPtr, scale), false);
365 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
369 private bool EqualTo(Rotation rhs)
371 bool ret = NDalicPINVOKE.Rotation_EqualTo(swigCPtr, Rotation.getCPtr(rhs));
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 private bool NotEqualTo(Rotation rhs)
378 bool ret = NDalicPINVOKE.Rotation_NotEqualTo(swigCPtr, Rotation.getCPtr(rhs));
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384 /// Returns the length of the rotation.
386 /// <returns>The length of the rotation.</returns>
387 /// <since_tizen> 3 </since_tizen>
388 public float Length()
390 float ret = NDalicPINVOKE.Rotation_Length(swigCPtr);
391 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396 /// Returns the squared length of the rotation.
398 /// <returns>The squared length of the rotation.</returns>
399 /// <since_tizen> 3 </since_tizen>
400 public float LengthSquared()
402 float ret = NDalicPINVOKE.Rotation_LengthSquared(swigCPtr);
403 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408 /// Normalizes this to unit length.
410 /// <since_tizen> 3 </since_tizen>
411 public void Normalize()
413 NDalicPINVOKE.Rotation_Normalize(swigCPtr);
414 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
420 /// <returns>A normalized version of this rotation.</returns>
421 /// <since_tizen> 3 </since_tizen>
422 public Rotation Normalized()
424 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Normalized(swigCPtr), true);
425 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
430 /// Conjugates this rotation.
432 /// <since_tizen> 3 </since_tizen>
433 public void Conjugate()
435 NDalicPINVOKE.Rotation_Conjugate(swigCPtr);
436 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
440 /// Inverts this rotation.
442 /// <since_tizen> 3 </since_tizen>
445 NDalicPINVOKE.Rotation_Invert(swigCPtr);
446 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
450 /// Performs the logarithm of a rotation.
452 /// <returns>The rotation representing the logarithm.</returns>
453 /// <since_tizen> 3 </since_tizen>
454 public Rotation Log()
456 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Log(swigCPtr), true);
457 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
462 /// Performs an exponent.
464 /// <returns>The rotation representing the exponent.</returns>
465 /// <since_tizen> 3 </since_tizen>
466 public Rotation Exp()
468 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Exp(swigCPtr), true);
469 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
474 /// Returns the dot product of two rotations.
476 /// <param name="q1">The first rotation.</param>
477 /// <param name="q2">The second rotation.</param>
478 /// <returns>The dot product of the two rotations.</returns>
479 /// <since_tizen> 3 </since_tizen>
480 public static float Dot(Rotation q1, Rotation q2)
482 float ret = NDalicPINVOKE.Rotation_Dot(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
483 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
488 /// The linear iterpolation (using a straight line between the two rotations).
490 /// <param name="q1">The start rotation.</param>
491 /// <param name="q2">The end rotation.</param>
492 /// <param name="t">A progress value between 0 and 1.</param>
493 /// <returns>The interpolated rotation.</returns>
494 /// <since_tizen> 3 </since_tizen>
495 public static Rotation Lerp(Rotation q1, Rotation q2, float t)
497 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Lerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
498 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
503 /// The spherical linear interpolation (using the shortest arc of a great circle between the two rotations).
505 /// <param name="q1">The start rotation.</param>
506 /// <param name="q2">The end rotation.</param>
507 /// <param name="progress">A progress value between 0 and 1.</param>
508 /// <returns>The interpolated rotation.</returns>
509 /// <since_tizen> 3 </since_tizen>
510 public static Rotation Slerp(Rotation q1, Rotation q2, float progress)
512 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Slerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), progress), true);
513 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
518 /// This version of slerp, used by squad, does not check for theta > 90.
520 /// <param name="q1">The start rotation.</param>
521 /// <param name="q2">The end rotation.</param>
522 /// <param name="t">A progress value between 0 and 1.</param>
523 /// <returns>The interpolated rotation.</returns>
524 /// <since_tizen> 3 </since_tizen>
525 public static Rotation SlerpNoInvert(Rotation q1, Rotation q2, float t)
527 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_SlerpNoInvert(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
528 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
533 /// The spherical cubic interpolation.
535 /// <param name="start">The start rotation.</param>
536 /// <param name="end">The end rotation.</param>
537 /// <param name="ctrl1">The control rotation for q1.</param>
538 /// <param name="ctrl2">The control rotation for q2.</param>
539 /// <param name="t">A progress value between 0 and 1.</param>
540 /// <returns>The interpolated rotation.</returns>
541 /// <since_tizen> 3 </since_tizen>
542 public static Rotation Squad(Rotation start, Rotation end, Rotation ctrl1, Rotation ctrl2, float t)
544 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Squad(Rotation.getCPtr(start), Rotation.getCPtr(end), Rotation.getCPtr(ctrl1), Rotation.getCPtr(ctrl2), t), true);
545 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
550 /// Returns the shortest angle between two rotations in radians.
552 /// <param name="q1">The first rotation.</param>
553 /// <param name="q2">The second rotation.</param>
554 /// <returns>The angle between the two rotation.</returns>
555 /// <since_tizen> 3 </since_tizen>
556 public static float AngleBetween(Rotation q1, Rotation q2)
558 float ret = NDalicPINVOKE.Rotation_AngleBetween(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
559 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();