1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
21 /// The Rotation class.
23 public class Rotation : global::System.IDisposable
25 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26 protected bool swigCMemOwn;
28 internal Rotation(global::System.IntPtr cPtr, bool cMemoryOwn)
30 swigCMemOwn = cMemoryOwn;
31 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rotation obj)
36 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39 //A Flag to check who called Dispose(). (By User or DisposeQueue)
40 private bool isDisposeQueued = false;
41 //A Flat to check if it is already disposed.
42 protected bool disposed = false;
48 isDisposeQueued = true;
49 DisposeQueue.Instance.Add(this);
54 /// To make the Rotation instance be disposed.
56 /// <since_tizen> 3 </since_tizen>
59 //Throw excpetion if Dispose() is called in separate thread.
60 if (!Window.IsInstalled())
62 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
67 Dispose(DisposeTypes.Implicit);
71 Dispose(DisposeTypes.Explicit);
72 System.GC.SuppressFinalize(this);
76 protected virtual void Dispose(DisposeTypes type)
83 if(type == DisposeTypes.Explicit)
86 //Release your own managed resources here.
87 //You should release all of your own disposable objects here.
90 //Release your own unmanaged resources here.
91 //You should not access any managed member here except static instance.
92 //because the execution order of Finalizes is non-deterministic.
94 if (swigCPtr.Handle != global::System.IntPtr.Zero)
99 NDalicPINVOKE.delete_Rotation(swigCPtr);
101 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
107 /// The addition operator.
109 /// <param name="arg1">The first rotation.</param>
110 /// <param name="arg2">The second rotation.</param>
111 /// <returns>The rotation containing the result of the addition.</returns>
112 /// <since_tizen> 3 </since_tizen>
113 public static Rotation operator +(Rotation arg1, Rotation arg2)
115 return arg1.Add(arg2);
119 /// The subtraction operator.
121 /// <param name="arg1">The first rotation.</param>
122 /// <param name="arg2">The second rotation.</param>
123 /// <returns>The rotation containing the result of the subtraction.</returns>
124 /// <since_tizen> 3 </since_tizen>
125 public static Rotation operator -(Rotation arg1, Rotation arg2)
127 return arg1.Subtract(arg2);
131 /// The unary negation operator.
133 /// <param name="arg1">The first rotation.</param>
134 /// <returns>The rotation containing the negated result.</returns>
135 /// <since_tizen> 3 </since_tizen>
136 public static Rotation operator -(Rotation arg1)
138 return arg1.Subtract();
142 /// The multiplication operator.
144 /// <param name="arg1">The first rotation.</param>
145 /// <param name="arg2">The second rotation.</param>
146 /// <returns>The rotation containing the result of the multiplication.</returns>
147 /// <since_tizen> 3 </since_tizen>
148 public static Rotation operator *(Rotation arg1, Rotation arg2)
150 return arg1.Multiply(arg2);
154 /// The multiplication operator.
156 /// <param name="arg1">Rotation.</param>
157 /// <param name="arg2">The vector to multiply.</param>
158 /// <returns>The rotation containing the result of the multiplication.</returns>
159 /// <since_tizen> 3 </since_tizen>
160 public static Vector3 operator *(Rotation arg1, Vector3 arg2)
162 return arg1.Multiply(arg2);
166 /// The scale operator.
168 /// <param name="arg1">Rotation.</param>
169 /// <param name="arg2">A value to scale by.</param>
170 /// <returns>The rotation containing the result of scaling.</returns>
171 /// <since_tizen> 3 </since_tizen>
172 public static Rotation operator *(Rotation arg1, float arg2)
174 return arg1.Multiply(arg2);
178 /// The division operator.
180 /// <param name="arg1">The first rotation.</param>
181 /// <param name="arg2">The second rotation.</param>
182 /// <returns>The rotation containing the result of scaling.</returns>
183 /// <since_tizen> 3 </since_tizen>
184 public static Rotation operator /(Rotation arg1, Rotation arg2)
186 return arg1.Divide(arg2);
190 /// The scale operator.
192 /// <param name="arg1">Rotation.</param>
193 /// <param name="arg2">A value to scale by.</param>
194 /// <returns>The rotation containing the result of scaling.</returns>
195 /// <since_tizen> 3 </since_tizen>
196 public static Rotation operator /(Rotation arg1, float arg2)
198 return arg1.Divide(arg2);
202 /// The default constructor.
204 /// <since_tizen> 3 </since_tizen>
205 public Rotation() : this(NDalicPINVOKE.new_Rotation__SWIG_0(), true)
207 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211 /// The constructor from an axis and angle.
213 /// <param name="angle">The angle around the axis.</param>
214 /// <param name="axis">The vector of the axis.</param>
215 /// <since_tizen> 3 </since_tizen>
216 public Rotation(Radian angle, Vector3 axis) : this(NDalicPINVOKE.new_Rotation__SWIG_1(Radian.getCPtr(angle), Vector3.getCPtr(axis)), true)
218 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
222 /// (0.0f,0.0f,0.0f,1.0f).
224 /// <since_tizen> 3 </since_tizen>
225 public static Rotation IDENTITY
229 global::System.IntPtr cPtr = NDalicPINVOKE.Rotation_IDENTITY_get();
230 Rotation ret = (cPtr == global::System.IntPtr.Zero) ? null : new Rotation(cPtr, false);
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 /// Helper to check if this is an identity quaternion.
239 /// <returns>True if this is identity quaternion.</returns>
240 /// <since_tizen> 3 </since_tizen>
241 public bool IsIdentity()
243 bool ret = NDalicPINVOKE.Rotation_IsIdentity(swigCPtr);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 /// Converts the quaternion to an axis or angle pair.
251 /// <param name="axis">The result of an an axis.</param>
252 /// <param name="angle">The result of angle in radians.</param>
253 /// <returns>True if converted correctly.</returns>
254 /// <since_tizen> 3 </since_tizen>
255 public bool GetAxisAngle(Vector3 axis, Radian angle)
257 bool ret = NDalicPINVOKE.Rotation_GetAxisAngle(swigCPtr, Vector3.getCPtr(axis), Radian.getCPtr(angle));
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262 private Rotation Add(Rotation other)
264 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Add(swigCPtr, Rotation.getCPtr(other)), true);
265 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269 private Rotation Subtract(Rotation other)
271 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Subtract__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
272 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276 private Rotation Multiply(Rotation other)
278 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Multiply__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
279 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
283 private Vector3 Multiply(Vector3 other)
285 Vector3 ret = new Vector3(NDalicPINVOKE.Rotation_Multiply__SWIG_1(swigCPtr, Vector3.getCPtr(other)), true);
286 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
290 private Rotation Divide(Rotation other)
292 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Divide__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
293 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 private Rotation Multiply(float scale)
299 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Multiply__SWIG_2(swigCPtr, scale), true);
300 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 private Rotation Divide(float scale)
306 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Divide__SWIG_1(swigCPtr, scale), true);
307 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311 private Rotation Subtract()
313 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Subtract__SWIG_1(swigCPtr), true);
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318 private Rotation AddAssign(Rotation other)
320 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_AddAssign(swigCPtr, Rotation.getCPtr(other)), false);
321 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325 private Rotation SubtractAssign(Rotation other)
327 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_SubtractAssign(swigCPtr, Rotation.getCPtr(other)), false);
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 private Rotation MultiplyAssign(Rotation other)
334 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_MultiplyAssign__SWIG_0(swigCPtr, Rotation.getCPtr(other)), false);
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339 private Rotation MultiplyAssign(float scale)
341 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_MultiplyAssign__SWIG_1(swigCPtr, scale), false);
342 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346 private Rotation DivideAssign(float scale)
348 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_DivideAssign(swigCPtr, scale), false);
349 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353 private bool EqualTo(Rotation rhs)
355 bool ret = NDalicPINVOKE.Rotation_EqualTo(swigCPtr, Rotation.getCPtr(rhs));
356 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360 private bool NotEqualTo(Rotation rhs)
362 bool ret = NDalicPINVOKE.Rotation_NotEqualTo(swigCPtr, Rotation.getCPtr(rhs));
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368 /// Returns the length of the rotation.
370 /// <returns>The length of the rotation.</returns>
371 /// <since_tizen> 3 </since_tizen>
372 public float Length()
374 float ret = NDalicPINVOKE.Rotation_Length(swigCPtr);
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380 /// Returns the squared length of the rotation.
382 /// <returns>The squared length of the rotation.</returns>
383 /// <since_tizen> 3 </since_tizen>
384 public float LengthSquared()
386 float ret = NDalicPINVOKE.Rotation_LengthSquared(swigCPtr);
387 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392 /// Normalizes this to unit length.
394 /// <since_tizen> 3 </since_tizen>
395 public void Normalize()
397 NDalicPINVOKE.Rotation_Normalize(swigCPtr);
398 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
404 /// <returns>A normalized version of this rotation.</returns>
405 /// <since_tizen> 3 </since_tizen>
406 public Rotation Normalized()
408 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Normalized(swigCPtr), true);
409 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414 /// Conjugates this rotation.
416 /// <since_tizen> 3 </since_tizen>
417 public void Conjugate()
419 NDalicPINVOKE.Rotation_Conjugate(swigCPtr);
420 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424 /// Inverts this rotation.
426 /// <since_tizen> 3 </since_tizen>
429 NDalicPINVOKE.Rotation_Invert(swigCPtr);
430 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
434 /// Performs the logarithm of a rotation.
436 /// <returns>The rotation representing the logarithm.</returns>
437 /// <since_tizen> 3 </since_tizen>
438 public Rotation Log()
440 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Log(swigCPtr), true);
441 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
446 /// Performs an exponent.
448 /// <returns>The rotation representing the exponent.</returns>
449 /// <since_tizen> 3 </since_tizen>
450 public Rotation Exp()
452 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Exp(swigCPtr), true);
453 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
458 /// Returns the dot product of two rotations.
460 /// <param name="q1">The first rotation.</param>
461 /// <param name="q2">The second rotation.</param>
462 /// <returns>The dot product of the two rotations.</returns>
463 /// <since_tizen> 3 </since_tizen>
464 public static float Dot(Rotation q1, Rotation q2)
466 float ret = NDalicPINVOKE.Rotation_Dot(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
467 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
472 /// The linear iterpolation (using a straight line between the two rotations).
474 /// <param name="q1">The start rotation.</param>
475 /// <param name="q2">The end rotation.</param>
476 /// <param name="t">A progress value between 0 and 1.</param>
477 /// <returns>The interpolated rotation.</returns>
478 /// <since_tizen> 3 </since_tizen>
479 public static Rotation Lerp(Rotation q1, Rotation q2, float t)
481 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Lerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
482 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
487 /// The spherical linear interpolation (using the shortest arc of a great circle between the two rotations).
489 /// <param name="q1">The start rotation.</param>
490 /// <param name="q2">The end rotation.</param>
491 /// <param name="progress">A progress value between 0 and 1.</param>
492 /// <returns>The interpolated rotation.</returns>
493 /// <since_tizen> 3 </since_tizen>
494 public static Rotation Slerp(Rotation q1, Rotation q2, float progress)
496 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Slerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), progress), true);
497 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
502 /// This version of slerp, used by squad, does not check for theta > 90.
504 /// <param name="q1">The start rotation.</param>
505 /// <param name="q2">The end rotation.</param>
506 /// <param name="t">A progress value between 0 and 1.</param>
507 /// <returns>The interpolated rotation.</returns>
508 /// <since_tizen> 3 </since_tizen>
509 public static Rotation SlerpNoInvert(Rotation q1, Rotation q2, float t)
511 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_SlerpNoInvert(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
512 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
517 /// The spherical cubic interpolation.
519 /// <param name="start">The start rotation.</param>
520 /// <param name="end">The end rotation.</param>
521 /// <param name="ctrl1">The control rotation for q1.</param>
522 /// <param name="ctrl2">The control rotation for q2.</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 Squad(Rotation start, Rotation end, Rotation ctrl1, Rotation ctrl2, float t)
528 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Squad(Rotation.getCPtr(start), Rotation.getCPtr(end), Rotation.getCPtr(ctrl1), Rotation.getCPtr(ctrl2), t), true);
529 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
534 /// Returns the shortest angle between two rotations in radians.
536 /// <param name="q1">The first rotation.</param>
537 /// <param name="q2">The second rotation.</param>
538 /// <returns>The angle between the two rotation.</returns>
539 /// <since_tizen> 3 </since_tizen>
540 public static float AngleBetween(Rotation q1, Rotation q2)
542 float ret = NDalicPINVOKE.Rotation_AngleBetween(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
543 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();