Release 4.0.0-preview1-00235
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Rotation.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
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
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 *
15 */
16
17 namespace Tizen.NUI
18 {
19
20     /// <summary>
21     /// The Rotation class.
22     /// </summary>
23     public class Rotation : global::System.IDisposable
24     {
25         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26         protected bool swigCMemOwn;
27
28         internal Rotation(global::System.IntPtr cPtr, bool cMemoryOwn)
29         {
30             swigCMemOwn = cMemoryOwn;
31             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
32         }
33
34         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rotation obj)
35         {
36             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
37         }
38
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;
43
44         ~Rotation()
45         {
46             if(!isDisposeQueued)
47             {
48                 isDisposeQueued = true;
49                 DisposeQueue.Instance.Add(this);
50             }
51         }
52
53         /// <summary>
54         /// To make the Rotation instance be disposed.
55         /// </summary>
56         public void Dispose()
57         {
58             //Throw excpetion if Dispose() is called in separate thread.
59             if (!Window.IsInstalled())
60             {
61                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
62             }
63
64             if (isDisposeQueued)
65             {
66                 Dispose(DisposeTypes.Implicit);
67             }
68             else
69             {
70                 Dispose(DisposeTypes.Explicit);
71                 System.GC.SuppressFinalize(this);
72             }
73         }
74
75         protected virtual void Dispose(DisposeTypes type)
76         {
77             if (disposed)
78             {
79                 return;
80             }
81
82             if(type == DisposeTypes.Explicit)
83             {
84                 //Called by User
85                 //Release your own managed resources here.
86                 //You should release all of your own disposable objects here.
87             }
88
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.
92
93             if (swigCPtr.Handle != global::System.IntPtr.Zero)
94             {
95                 if (swigCMemOwn)
96                 {
97                     swigCMemOwn = false;
98                     NDalicPINVOKE.delete_Rotation(swigCPtr);
99                 }
100                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
101             }
102             disposed = true;
103         }
104
105         /// <summary>
106         /// The addition operator.
107         /// </summary>
108         /// <param name="arg1">The first rotation.</param>
109         /// <param name="arg2">The second rotation.</param>
110         /// <returns>The rotation containing the result of the addition.</returns>
111         public static Rotation operator +(Rotation arg1, Rotation arg2)
112         {
113             return arg1.Add(arg2);
114         }
115
116         /// <summary>
117         /// The subtraction operator.
118         /// </summary>
119         /// <param name="arg1">The first rotation.</param>
120         /// <param name="arg2">The second rotation.</param>
121         /// <returns>The rotation containing the result of the subtraction.</returns>
122         public static Rotation operator -(Rotation arg1, Rotation arg2)
123         {
124             return arg1.Subtract(arg2);
125         }
126
127         /// <summary>
128         /// The unary negation operator.
129         /// </summary>
130         /// <param name="arg1">The first rotation.</param>
131         /// <returns>The rotation containing the negated result.</returns>
132         public static Rotation operator -(Rotation arg1)
133         {
134             return arg1.Subtract();
135         }
136
137         /// <summary>
138         /// The multiplication operator.
139         /// </summary>
140         /// <param name="arg1">The first rotation.</param>
141         /// <param name="arg2">The second rotation.</param>
142         /// <returns>The rotation containing the result of the multiplication.</returns>
143         public static Rotation operator *(Rotation arg1, Rotation arg2)
144         {
145             return arg1.Multiply(arg2);
146         }
147
148         /// <summary>
149         /// The multiplication operator.
150         /// </summary>
151         /// <param name="arg1">Rotation.</param>
152         /// <param name="arg2">The vector to multiply.</param>
153         /// <returns>The rotation containing the result of the multiplication.</returns>
154         public static Vector3 operator *(Rotation arg1, Vector3 arg2)
155         {
156             return arg1.Multiply(arg2);
157         }
158
159         /// <summary>
160         /// The scale operator.
161         /// </summary>
162         /// <param name="arg1">Rotation.</param>
163         /// <param name="arg2">A value to scale by.</param>
164         /// <returns>The rotation containing the result of scaling.</returns>
165         public static Rotation operator *(Rotation arg1, float arg2)
166         {
167             return arg1.Multiply(arg2);
168         }
169
170         /// <summary>
171         /// The division operator.
172         /// </summary>
173         /// <param name="arg1">The first rotation.</param>
174         /// <param name="arg2">The second rotation.</param>
175         /// <returns>The rotation containing the result of scaling.</returns>
176         public static Rotation operator /(Rotation arg1, Rotation arg2)
177         {
178             return arg1.Divide(arg2);
179         }
180
181         /// <summary>
182         /// The scale operator.
183         /// </summary>
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         public static Rotation operator /(Rotation arg1, float arg2)
188         {
189             return arg1.Divide(arg2);
190         }
191
192         /// <summary>
193         /// The default constructor.
194         /// </summary>
195         public Rotation() : this(NDalicPINVOKE.new_Rotation__SWIG_0(), true)
196         {
197             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198         }
199
200         /// <summary>
201         /// The constructor from an axis and angle.
202         /// </summary>
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)
206         {
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208         }
209
210         /// <summary>
211         /// (0.0f,0.0f,0.0f,1.0f).
212         /// </summary>
213         public static Rotation IDENTITY
214         {
215             get
216             {
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();
220                 return ret;
221             }
222         }
223
224         /// <summary>
225         /// Helper to check if this is an identity quaternion.
226         /// </summary>
227         /// <returns>True if this is identity quaternion.</returns>
228         public bool IsIdentity()
229         {
230             bool ret = NDalicPINVOKE.Rotation_IsIdentity(swigCPtr);
231             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232             return ret;
233         }
234
235         /// <summary>
236         /// Converts the quaternion to an axis or angle pair.
237         /// </summary>
238         /// <param name="axis">The result of an an axis.</param>
239         /// <param name="angle">The result of angle in radians.</param>
240         /// <returns>True if converted correctly.</returns>
241         public bool GetAxisAngle(Vector3 axis, Radian angle)
242         {
243             bool ret = NDalicPINVOKE.Rotation_GetAxisAngle(swigCPtr, Vector3.getCPtr(axis), Radian.getCPtr(angle));
244             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245             return ret;
246         }
247
248         private Rotation Add(Rotation other)
249         {
250             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Add(swigCPtr, Rotation.getCPtr(other)), true);
251             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252             return ret;
253         }
254
255         private Rotation Subtract(Rotation other)
256         {
257             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Subtract__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
258             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259             return ret;
260         }
261
262         private Rotation Multiply(Rotation other)
263         {
264             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Multiply__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
265             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266             return ret;
267         }
268
269         private Vector3 Multiply(Vector3 other)
270         {
271             Vector3 ret = new Vector3(NDalicPINVOKE.Rotation_Multiply__SWIG_1(swigCPtr, Vector3.getCPtr(other)), true);
272             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273             return ret;
274         }
275
276         private Rotation Divide(Rotation other)
277         {
278             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Divide__SWIG_0(swigCPtr, Rotation.getCPtr(other)), true);
279             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280             return ret;
281         }
282
283         private Rotation Multiply(float scale)
284         {
285             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Multiply__SWIG_2(swigCPtr, scale), true);
286             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287             return ret;
288         }
289
290         private Rotation Divide(float scale)
291         {
292             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Divide__SWIG_1(swigCPtr, scale), true);
293             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294             return ret;
295         }
296
297         private Rotation Subtract()
298         {
299             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Subtract__SWIG_1(swigCPtr), true);
300             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301             return ret;
302         }
303
304         private Rotation AddAssign(Rotation other)
305         {
306             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_AddAssign(swigCPtr, Rotation.getCPtr(other)), false);
307             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308             return ret;
309         }
310
311         private Rotation SubtractAssign(Rotation other)
312         {
313             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_SubtractAssign(swigCPtr, Rotation.getCPtr(other)), false);
314             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315             return ret;
316         }
317
318         private Rotation MultiplyAssign(Rotation other)
319         {
320             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_MultiplyAssign__SWIG_0(swigCPtr, Rotation.getCPtr(other)), false);
321             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322             return ret;
323         }
324
325         private Rotation MultiplyAssign(float scale)
326         {
327             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_MultiplyAssign__SWIG_1(swigCPtr, scale), false);
328             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329             return ret;
330         }
331
332         private Rotation DivideAssign(float scale)
333         {
334             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_DivideAssign(swigCPtr, scale), false);
335             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336             return ret;
337         }
338
339         private bool EqualTo(Rotation rhs)
340         {
341             bool ret = NDalicPINVOKE.Rotation_EqualTo(swigCPtr, Rotation.getCPtr(rhs));
342             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343             return ret;
344         }
345
346         private bool NotEqualTo(Rotation rhs)
347         {
348             bool ret = NDalicPINVOKE.Rotation_NotEqualTo(swigCPtr, Rotation.getCPtr(rhs));
349             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
350             return ret;
351         }
352
353         /// <summary>
354         /// Returns the length of the rotation.
355         /// </summary>
356         /// <returns>The length of the rotation.</returns>
357         public float Length()
358         {
359             float ret = NDalicPINVOKE.Rotation_Length(swigCPtr);
360             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361             return ret;
362         }
363
364         /// <summary>
365         /// Returns the squared length of the rotation.
366         /// </summary>
367         /// <returns>The squared length of the rotation.</returns>
368         public float LengthSquared()
369         {
370             float ret = NDalicPINVOKE.Rotation_LengthSquared(swigCPtr);
371             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
372             return ret;
373         }
374
375         /// <summary>
376         /// Normalizes this to unit length.
377         /// </summary>
378         public void Normalize()
379         {
380             NDalicPINVOKE.Rotation_Normalize(swigCPtr);
381             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
382         }
383
384         /// <summary>
385         /// Normalized.
386         /// </summary>
387         /// <returns>A normalized version of this rotation.</returns>
388         public Rotation Normalized()
389         {
390             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Normalized(swigCPtr), true);
391             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392             return ret;
393         }
394
395         /// <summary>
396         /// Conjugates this rotation.
397         /// </summary>
398         public void Conjugate()
399         {
400             NDalicPINVOKE.Rotation_Conjugate(swigCPtr);
401             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
402         }
403
404         /// <summary>
405         /// Inverts this rotation.
406         /// </summary>
407         public void Invert()
408         {
409             NDalicPINVOKE.Rotation_Invert(swigCPtr);
410             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
411         }
412
413         /// <summary>
414         /// Performs the logarithm of a rotation.
415         /// </summary>
416         /// <returns>The rotation representing the logarithm.</returns>
417         public Rotation Log()
418         {
419             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Log(swigCPtr), true);
420             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
421             return ret;
422         }
423
424         /// <summary>
425         /// Performs an exponent.
426         /// </summary>
427         /// <returns>The rotation representing the exponent.</returns>
428         public Rotation Exp()
429         {
430             Rotation ret = new Rotation(NDalicPINVOKE.Rotation_Exp(swigCPtr), true);
431             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
432             return ret;
433         }
434
435         /// <summary>
436         /// Returns the dot product of two rotations.
437         /// </summary>
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)
442         {
443             float ret = NDalicPINVOKE.Rotation_Dot(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
444             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
445             return ret;
446         }
447
448         /// <summary>
449         /// The linear iterpolation (using a straight line between the two rotations).
450         /// </summary>
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)
456         {
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();
459             return ret;
460         }
461
462         /// <summary>
463         /// The spherical linear interpolation (using the shortest arc of a great circle between the two rotations).
464         /// </summary>
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)
470         {
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();
473             return ret;
474         }
475
476         /// <summary>
477         /// This version of slerp, used by squad, does not check for theta > 90.
478         /// </summary>
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)
484         {
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();
487             return ret;
488         }
489
490         /// <summary>
491         /// The spherical cubic interpolation.
492         /// </summary>
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)
500         {
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();
503             return ret;
504         }
505
506         /// <summary>
507         /// Returns the shortest angle between two rotations in radians.
508         /// </summary>
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)
513         {
514             float ret = NDalicPINVOKE.Rotation_AngleBetween(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
515             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
516             return ret;
517         }
518
519     }
520
521 }