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 /// <since_tizen> 3 </since_tizen>
25 public class Rotation : global::System.IDisposable
27 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31 /// <since_tizen> 3 </since_tizen>
32 protected bool swigCMemOwn;
34 internal Rotation(global::System.IntPtr cPtr, bool cMemoryOwn)
36 swigCMemOwn = cMemoryOwn;
37 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
40 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rotation obj)
42 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
45 //A Flag to check who called Dispose(). (By User or DisposeQueue)
46 private bool isDisposeQueued = false;
48 /// A Flat to check if it is already disposed.
50 /// <since_tizen> 3 </since_tizen>
51 protected bool disposed = false;
56 /// <since_tizen> 3 </since_tizen>
61 isDisposeQueued = true;
62 DisposeQueue.Instance.Add(this);
67 /// To make the Rotation instance be disposed.
69 /// <since_tizen> 3 </since_tizen>
72 //Throw excpetion if Dispose() is called in separate thread.
73 if (!Window.IsInstalled())
75 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
80 Dispose(DisposeTypes.Implicit);
84 Dispose(DisposeTypes.Explicit);
85 System.GC.SuppressFinalize(this);
92 /// <since_tizen> 3 </since_tizen>
93 protected virtual void Dispose(DisposeTypes type)
100 if(type == DisposeTypes.Explicit)
103 //Release your own managed resources here.
104 //You should release all of your own disposable objects here.
107 //Release your own unmanaged resources here.
108 //You should not access any managed member here except static instance.
109 //because the execution order of Finalizes is non-deterministic.
111 if (swigCPtr.Handle != global::System.IntPtr.Zero)
116 NDalicPINVOKE.delete_Rotation(swigCPtr);
118 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
124 /// The addition operator.
126 /// <param name="arg1">The first rotation.</param>
127 /// <param name="arg2">The second rotation.</param>
128 /// <returns>The rotation containing the result of the addition.</returns>
129 /// <since_tizen> 3 </since_tizen>
130 public static Rotation operator +(Rotation arg1, Rotation arg2)
132 return arg1.Add(arg2);
136 /// The subtraction operator.
138 /// <param name="arg1">The first rotation.</param>
139 /// <param name="arg2">The second rotation.</param>
140 /// <returns>The rotation containing the result of the subtraction.</returns>
141 /// <since_tizen> 3 </since_tizen>
142 public static Rotation operator -(Rotation arg1, Rotation arg2)
144 return arg1.Subtract(arg2);
148 /// The unary negation operator.
150 /// <param name="arg1">The first rotation.</param>
151 /// <returns>The rotation containing the negated result.</returns>
152 /// <since_tizen> 3 </since_tizen>
153 public static Rotation operator -(Rotation arg1)
155 return arg1.Subtract();
159 /// The multiplication operator.
161 /// <param name="arg1">The first rotation.</param>
162 /// <param name="arg2">The second rotation.</param>
163 /// <returns>The rotation containing the result of the multiplication.</returns>
164 /// <since_tizen> 3 </since_tizen>
165 public static Rotation operator *(Rotation arg1, Rotation arg2)
167 return arg1.Multiply(arg2);
171 /// The multiplication operator.
173 /// <param name="arg1">Rotation.</param>
174 /// <param name="arg2">The vector to multiply.</param>
175 /// <returns>The rotation containing the result of the multiplication.</returns>
176 /// <since_tizen> 3 </since_tizen>
177 public static Vector3 operator *(Rotation arg1, Vector3 arg2)
179 return arg1.Multiply(arg2);
183 /// The scale operator.
185 /// <param name="arg1">Rotation.</param>
186 /// <param name="arg2">A value to scale by.</param>
187 /// <returns>The rotation containing the result of scaling.</returns>
188 /// <since_tizen> 3 </since_tizen>
189 public static Rotation operator *(Rotation arg1, float arg2)
191 return arg1.Multiply(arg2);
195 /// The division operator.
197 /// <param name="arg1">The first rotation.</param>
198 /// <param name="arg2">The second rotation.</param>
199 /// <returns>The rotation containing the result of scaling.</returns>
200 /// <since_tizen> 3 </since_tizen>
201 public static Rotation operator /(Rotation arg1, Rotation arg2)
203 return arg1.Divide(arg2);
207 /// The scale operator.
209 /// <param name="arg1">Rotation.</param>
210 /// <param name="arg2">A value to scale by.</param>
211 /// <returns>The rotation containing the result of scaling.</returns>
212 /// <since_tizen> 3 </since_tizen>
213 public static Rotation operator /(Rotation arg1, float arg2)
215 return arg1.Divide(arg2);
219 /// The default constructor.
221 /// <since_tizen> 3 </since_tizen>
222 public Rotation() : this(NDalicPINVOKE.new_Rotation__SWIG_0(), true)
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228 /// The constructor from an axis and angle.
230 /// <param name="angle">The angle around the axis.</param>
231 /// <param name="axis">The vector of the axis.</param>
232 /// <since_tizen> 3 </since_tizen>
233 public Rotation(Radian angle, Vector3 axis) : this(NDalicPINVOKE.new_Rotation__SWIG_1(Radian.getCPtr(angle), Vector3.getCPtr(axis)), true)
235 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239 /// (0.0f,0.0f,0.0f,1.0f).
241 /// <since_tizen> 3 </since_tizen>
242 public static Rotation IDENTITY
246 global::System.IntPtr cPtr = NDalicPINVOKE.Rotation_IDENTITY_get();
247 Rotation ret = (cPtr == global::System.IntPtr.Zero) ? null : new Rotation(cPtr, false);
248 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 /// Helper to check if this is an identity quaternion.
256 /// <returns>True if this is identity quaternion.</returns>
257 /// <since_tizen> 3 </since_tizen>
258 public bool IsIdentity()
260 bool ret = NDalicPINVOKE.Rotation_IsIdentity(swigCPtr);
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 /// Converts the quaternion to an axis or angle pair.
268 /// <param name="axis">The result of an an axis.</param>
269 /// <param name="angle">The result of angle in radians.</param>
270 /// <returns>True if converted correctly.</returns>
271 /// <since_tizen> 3 </since_tizen>
272 public bool GetAxisAngle(Vector3 axis, Radian angle)
274 bool ret = NDalicPINVOKE.Rotation_GetAxisAngle(swigCPtr, Vector3.getCPtr(axis), Radian.getCPtr(angle));
275 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279 private Rotation Add(Rotation other)
281 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Add(swigCPtr, Rotation.getCPtr(other)), true);
282 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 private Rotation Subtract(Rotation other)
288 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Subtract__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
289 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293 private Rotation Multiply(Rotation other)
295 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Multiply__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
296 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 private Vector3 Multiply(Vector3 other)
302 Vector3 ret = new Vector3(NDalicPINVOKE.Rotation_Multiply__SWIG_1(swigCPtr, Vector3.getCPtr(other)), true);
303 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307 private Rotation Divide(Rotation other)
309 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Divide__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
310 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314 private Rotation Multiply(float scale)
316 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Multiply__SWIG_2(swigCPtr, scale), true);
317 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
321 private Rotation Divide(float scale)
323 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Divide__SWIG_1(swigCPtr, scale), true);
324 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328 private Rotation Subtract()
330 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Subtract__SWIG_1(swigCPtr), true);
331 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
335 private Rotation AddAssign(Rotation other)
337 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_AddAssign(swigCPtr, Rotation.getCPtr(other)), false);
338 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342 private Rotation SubtractAssign(Rotation other)
344 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_SubtractAssign(swigCPtr, Rotation.getCPtr(other)), false);
345 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349 private Rotation MultiplyAssign(Rotation other)
351 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_MultiplyAssign__SWIG_0(swigCPtr, Rotation.getCPtr(other)), false);
352 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356 private Rotation MultiplyAssign(float scale)
358 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_MultiplyAssign__SWIG_1(swigCPtr, scale), false);
359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
363 private Rotation DivideAssign(float scale)
365 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_DivideAssign(swigCPtr, scale), false);
366 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370 private bool EqualTo(Rotation rhs)
372 bool ret = NDalicPINVOKE.Rotation_EqualTo(swigCPtr, Rotation.getCPtr(rhs));
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377 private bool NotEqualTo(Rotation rhs)
379 bool ret = NDalicPINVOKE.Rotation_NotEqualTo(swigCPtr, Rotation.getCPtr(rhs));
380 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
385 /// Returns the length of the rotation.
387 /// <returns>The length of the rotation.</returns>
388 /// <since_tizen> 3 </since_tizen>
389 public float Length()
391 float ret = NDalicPINVOKE.Rotation_Length(swigCPtr);
392 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397 /// Returns the squared length of the rotation.
399 /// <returns>The squared length of the rotation.</returns>
400 /// <since_tizen> 3 </since_tizen>
401 public float LengthSquared()
403 float ret = NDalicPINVOKE.Rotation_LengthSquared(swigCPtr);
404 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
409 /// Normalizes this to unit length.
411 /// <since_tizen> 3 </since_tizen>
412 public void Normalize()
414 NDalicPINVOKE.Rotation_Normalize(swigCPtr);
415 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
421 /// <returns>A normalized version of this rotation.</returns>
422 /// <since_tizen> 3 </since_tizen>
423 public Rotation Normalized()
425 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Normalized(swigCPtr), true);
426 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431 /// Conjugates this rotation.
433 /// <since_tizen> 3 </since_tizen>
434 public void Conjugate()
436 NDalicPINVOKE.Rotation_Conjugate(swigCPtr);
437 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
441 /// Inverts this rotation.
443 /// <since_tizen> 3 </since_tizen>
446 NDalicPINVOKE.Rotation_Invert(swigCPtr);
447 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
451 /// Performs the logarithm of a rotation.
453 /// <returns>The rotation representing the logarithm.</returns>
454 /// <since_tizen> 3 </since_tizen>
455 public Rotation Log()
457 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Log(swigCPtr), true);
458 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
463 /// Performs an exponent.
465 /// <returns>The rotation representing the exponent.</returns>
466 /// <since_tizen> 3 </since_tizen>
467 public Rotation Exp()
469 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Exp(swigCPtr), true);
470 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
475 /// Returns the dot product of two rotations.
477 /// <param name="q1">The first rotation.</param>
478 /// <param name="q2">The second rotation.</param>
479 /// <returns>The dot product of the two rotations.</returns>
480 /// <since_tizen> 3 </since_tizen>
481 public static float Dot(Rotation q1, Rotation q2)
483 float ret = NDalicPINVOKE.Rotation_Dot(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
484 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
489 /// The linear iterpolation (using a straight line between the two rotations).
491 /// <param name="q1">The start rotation.</param>
492 /// <param name="q2">The end rotation.</param>
493 /// <param name="t">A progress value between 0 and 1.</param>
494 /// <returns>The interpolated rotation.</returns>
495 /// <since_tizen> 3 </since_tizen>
496 public static Rotation Lerp(Rotation q1, Rotation q2, float t)
498 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Lerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
499 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
504 /// The spherical linear interpolation (using the shortest arc of a great circle between the two rotations).
506 /// <param name="q1">The start rotation.</param>
507 /// <param name="q2">The end rotation.</param>
508 /// <param name="progress">A progress value between 0 and 1.</param>
509 /// <returns>The interpolated rotation.</returns>
510 /// <since_tizen> 3 </since_tizen>
511 public static Rotation Slerp(Rotation q1, Rotation q2, float progress)
513 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Slerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), progress), true);
514 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
519 /// This version of slerp, used by squad, does not check for theta > 90.
521 /// <param name="q1">The start rotation.</param>
522 /// <param name="q2">The end rotation.</param>
523 /// <param name="t">A progress value between 0 and 1.</param>
524 /// <returns>The interpolated rotation.</returns>
525 /// <since_tizen> 3 </since_tizen>
526 public static Rotation SlerpNoInvert(Rotation q1, Rotation q2, float t)
528 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_SlerpNoInvert(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
529 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
534 /// The spherical cubic interpolation.
536 /// <param name="start">The start rotation.</param>
537 /// <param name="end">The end rotation.</param>
538 /// <param name="ctrl1">The control rotation for q1.</param>
539 /// <param name="ctrl2">The control rotation for q2.</param>
540 /// <param name="t">A progress value between 0 and 1.</param>
541 /// <returns>The interpolated rotation.</returns>
542 /// <since_tizen> 3 </since_tizen>
543 public static Rotation Squad(Rotation start, Rotation end, Rotation ctrl1, Rotation ctrl2, float t)
545 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Squad(Rotation.getCPtr(start), Rotation.getCPtr(end), Rotation.getCPtr(ctrl1), Rotation.getCPtr(ctrl2), t), true);
546 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
551 /// Returns the shortest angle between two rotations in radians.
553 /// <param name="q1">The first rotation.</param>
554 /// <param name="q2">The second rotation.</param>
555 /// <returns>The angle between the two rotation.</returns>
556 /// <since_tizen> 3 </since_tizen>
557 public static float AngleBetween(Rotation q1, Rotation q2)
559 float ret = NDalicPINVOKE.Rotation_AngleBetween(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
560 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();