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.
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 Rotation instance be disposed.
58 //Throw excpetion if Dispose() is called in separate thread.
59 if (!Window.IsInstalled())
61 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
66 Dispose(DisposeTypes.Implicit);
70 Dispose(DisposeTypes.Explicit);
71 System.GC.SuppressFinalize(this);
75 protected virtual void Dispose(DisposeTypes type)
82 if(type == DisposeTypes.Explicit)
85 //Release your own managed resources here.
86 //You should release all of your own disposable objects here.
89 //Release your own unmanaged resources here.
90 //You should not access any managed member here except static instance.
91 //because the execution order of Finalizes is non-deterministic.
93 if (swigCPtr.Handle != global::System.IntPtr.Zero)
98 NDalicPINVOKE.delete_Rotation(swigCPtr);
100 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
106 /// Addition operator.
108 /// <param name="arg1">First Rotation</param>
109 /// <param name="arg2">Second Rotation</param>
110 /// <returns>A Rotation containing the result of the Addition</returns>
111 public static Rotation operator +(Rotation arg1, Rotation arg2)
113 return arg1.Add(arg2);
117 /// Subtraction operator.
119 /// <param name="arg1">First Rotation</param>
120 /// <param name="arg2">Second Rotation</param>
121 /// <returns>A Rotation containing the result of the subtract</returns>
122 public static Rotation operator -(Rotation arg1, Rotation arg2)
124 return arg1.Subtract(arg2);
128 /// Unary Negation operator.
130 /// <param name="arg1">First Rotation</param>
131 /// <returns>A Rotation containing the negated result</returns>
132 public static Rotation operator -(Rotation arg1)
134 return arg1.Subtract();
138 /// Multiplication operator.
140 /// <param name="arg1">First Rotation</param>
141 /// <param name="arg2">Second Rotation</param>
142 /// <returns>A Rotation containing the result of the Multiplication</returns>
143 public static Rotation operator *(Rotation arg1, Rotation arg2)
145 return arg1.Multiply(arg2);
149 /// Multiplication operator.
151 /// <param name="arg1">Rotation</param>
152 /// <param name="arg2">The vector to multiply</param>
153 /// <returns>A Rotation containing the result of the multiplication</returns>
154 public static Vector3 operator *(Rotation arg1, Vector3 arg2)
156 return arg1.Multiply(arg2);
162 /// <param name="arg1">Rotation</param>
163 /// <param name="arg2">A value to scale by</param>
164 /// <returns>A Rotation containing the result of the scaling</returns>
165 public static Rotation operator *(Rotation arg1, float arg2)
167 return arg1.Multiply(arg2);
171 /// Division operator.
173 /// <param name="arg1">First Rotation</param>
174 /// <param name="arg2">Second Rotation</param>
175 /// <returns>A Rotation containing the result of the scaling</returns>
176 public static Rotation operator /(Rotation arg1, Rotation arg2)
178 return arg1.Divide(arg2);
184 /// <param name="arg1">Rotation</param>
185 /// <param name="arg2">A value to scale by</param>
186 /// <returns>A Rotation containing the result of the scaling</returns>
187 public static Rotation operator /(Rotation arg1, float arg2)
189 return arg1.Divide(arg2);
193 /// Default Constructor.
195 public Rotation() : this(NDalicPINVOKE.new_Rotation__SWIG_0(), true)
197 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201 /// Constructor from an axis and angle.
203 /// <param name="angle">The angle around the axis</param>
204 /// <param name="axis">The vector of the axis</param>
205 public Rotation(Radian angle, Vector3 axis) : this(NDalicPINVOKE.new_Rotation__SWIG_1(Radian.getCPtr(angle), Vector3.getCPtr(axis)), true)
207 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211 /// (0.0f,0.0f,0.0f,1.0f)
213 public static Rotation IDENTITY
217 global::System.IntPtr cPtr = NDalicPINVOKE.Rotation_IDENTITY_get();
218 Rotation ret = (cPtr == global::System.IntPtr.Zero) ? null : new Rotation(cPtr, false);
219 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225 /// Helper to check if this is an identity quaternion.
227 /// <returns>True if this is identity quaternion</returns>
228 public bool IsIdentity()
230 bool ret = NDalicPINVOKE.Rotation_IsIdentity(swigCPtr);
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236 /// Converts the quaternion to an axis/angle pair.
238 /// <param name="axis">the result of axis</param>
239 /// <param name="angle">the result of angle Angle in radians</param>
240 /// <returns>True if converted correctly</returns>
241 public bool GetAxisAngle(Vector3 axis, Radian angle)
243 bool ret = NDalicPINVOKE.Rotation_GetAxisAngle(swigCPtr, Vector3.getCPtr(axis), Radian.getCPtr(angle));
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248 private Rotation Add(Rotation other)
250 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Add(swigCPtr, Rotation.getCPtr(other)), true);
251 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255 private Rotation Subtract(Rotation other)
257 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Subtract__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262 private Rotation Multiply(Rotation other)
264 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Multiply__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
265 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269 private Vector3 Multiply(Vector3 other)
271 Vector3 ret = new Vector3(NDalicPINVOKE.Rotation_Multiply__SWIG_1(swigCPtr, Vector3.getCPtr(other)), true);
272 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276 private Rotation Divide(Rotation other)
278 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Divide__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
279 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
283 private Rotation Multiply(float scale)
285 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Multiply__SWIG_2(swigCPtr, scale), true);
286 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
290 private Rotation Divide(float scale)
292 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Divide__SWIG_1(swigCPtr, scale), true);
293 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 private Rotation Subtract()
299 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Subtract__SWIG_1(swigCPtr), true);
300 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 private Rotation AddAssign(Rotation other)
306 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_AddAssign(swigCPtr, Rotation.getCPtr(other)), false);
307 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311 private Rotation SubtractAssign(Rotation other)
313 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_SubtractAssign(swigCPtr, Rotation.getCPtr(other)), false);
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318 private Rotation MultiplyAssign(Rotation other)
320 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_MultiplyAssign__SWIG_0(swigCPtr, Rotation.getCPtr(other)), false);
321 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325 private Rotation MultiplyAssign(float scale)
327 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_MultiplyAssign__SWIG_1(swigCPtr, scale), false);
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 private Rotation DivideAssign(float scale)
334 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_DivideAssign(swigCPtr, scale), false);
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339 private bool EqualTo(Rotation rhs)
341 bool ret = NDalicPINVOKE.Rotation_EqualTo(swigCPtr, Rotation.getCPtr(rhs));
342 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346 private bool NotEqualTo(Rotation rhs)
348 bool ret = NDalicPINVOKE.Rotation_NotEqualTo(swigCPtr, Rotation.getCPtr(rhs));
349 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354 /// Returns the length of the rotation
356 /// <returns>The length of the rotation</returns>
357 public float Length()
359 float ret = NDalicPINVOKE.Rotation_Length(swigCPtr);
360 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
365 /// Returns the squared length of the rotation
367 /// <returns>The squared length of the rotation</returns>
368 public float LengthSquared()
370 float ret = NDalicPINVOKE.Rotation_LengthSquared(swigCPtr);
371 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 /// Normalizes this to unit length.
378 public void Normalize()
380 NDalicPINVOKE.Rotation_Normalize(swigCPtr);
381 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387 /// <returns>A normalized version of this rotation</returns>
388 public Rotation Normalized()
390 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Normalized(swigCPtr), true);
391 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396 /// Conjugates this rotation.
398 public void Conjugate()
400 NDalicPINVOKE.Rotation_Conjugate(swigCPtr);
401 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405 /// Inverts this rotation.
409 NDalicPINVOKE.Rotation_Invert(swigCPtr);
410 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414 /// Performs the logarithm of a rotation
416 /// <returns>A rotation representing the logarithm</returns>
417 public Rotation Log()
419 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Log(swigCPtr), true);
420 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425 /// Performs an exponent
427 /// <returns>A rotation representing the exponent</returns>
428 public Rotation Exp()
430 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Exp(swigCPtr), true);
431 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
436 /// Returns the dot product of two rotations.
438 /// <param name="q1">The first rotation</param>
439 /// <param name="q2">The second rotation</param>
440 /// <returns>The dot product of the two rotations</returns>
441 public static float Dot(Rotation q1, Rotation q2)
443 float ret = NDalicPINVOKE.Rotation_Dot(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
444 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449 /// Linear Interpolation (using a straight line between the two rotations).
451 /// <param name="q1">The start rotation</param>
452 /// <param name="q2">The end rotation</param>
453 /// <param name="t">A progress value between 0 and 1</param>
454 /// <returns>The interpolated rotation</returns>
455 public static Rotation Lerp(Rotation q1, Rotation q2, float t)
457 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Lerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
458 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
463 /// Spherical Linear Interpolation (using the shortest arc of a great circle between the two rotations).
465 /// <param name="q1">The start rotation</param>
466 /// <param name="q2">The end rotation</param>
467 /// <param name="progress">A progress value between 0 and 1</param>
468 /// <returns>The interpolated rotation</returns>
469 public static Rotation Slerp(Rotation q1, Rotation q2, float progress)
471 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Slerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), progress), true);
472 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
477 /// This version of Slerp, used by Squad, does not check for theta > 90.
479 /// <param name="q1">The start rotation</param>
480 /// <param name="q2">The end rotation</param>
481 /// <param name="t">A progress value between 0 and 1</param>
482 /// <returns>The interpolated rotation</returns>
483 public static Rotation SlerpNoInvert(Rotation q1, Rotation q2, float t)
485 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_SlerpNoInvert(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
486 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
491 /// Spherical Cubic Interpolation.
493 /// <param name="start">The start rotation</param>
494 /// <param name="end">The end rotation</param>
495 /// <param name="ctrl1">The control rotation for q1</param>
496 /// <param name="ctrl2">The control rotation for q2</param>
497 /// <param name="t">A progress value between 0 and 1</param>
498 /// <returns>The interpolated rotation</returns>
499 public static Rotation Squad(Rotation start, Rotation end, Rotation ctrl1, Rotation ctrl2, float t)
501 Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Squad(Rotation.getCPtr(start), Rotation.getCPtr(end), Rotation.getCPtr(ctrl1), Rotation.getCPtr(ctrl2), t), true);
502 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
507 /// Returns the shortest angle between two rotations in Radians.
509 /// <param name="q1">The first rotation</param>
510 /// <param name="q2">The second rotation</param>
511 /// <returns>The angle between the two rotation</returns>
512 public static float AngleBetween(Rotation q1, Rotation q2)
514 float ret = NDalicPINVOKE.Rotation_AngleBetween(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
515 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();