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