844ee1ee7767f9d84aa11252b981674e99958861
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Common / Rotation.cs
1 /*
2  * Copyright(c) 2019 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 System.ComponentModel;
19 using Tizen.NUI.Binding;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// The Rotation class.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     [Binding.TypeConverter(typeof(RotationTypeConverter))]
28     public class Rotation : Disposable
29     {
30
31         /// <summary>
32         /// The default constructor.
33         /// </summary>
34         /// <since_tizen> 3 </since_tizen>
35         public Rotation() : this(Interop.Rotation.NewRotation(), true)
36         {
37             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
38         }
39
40         /// <summary>
41         /// The constructor from an axis and angle.
42         /// </summary>
43         /// <param name="angle">The angle around the axis.</param>
44         /// <param name="axis">The vector of the axis.</param>
45         /// <since_tizen> 3 </since_tizen>
46         public Rotation(Radian angle, Vector3 axis) : this(Interop.Rotation.NewRotation(Radian.getCPtr(angle), Vector3.getCPtr(axis)), true)
47         {
48             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
49         }
50
51         /// <summary>
52         /// The constructor of Rotation which describes minimum rotation to align v0 with v1.
53         /// </summary>
54         /// <param name="v0">The first normalized vector.</param>
55         /// <param name="v1">The second normalized vector.</param>
56         /// <remarks>
57         /// v0 and v1 should be normalized.
58         /// </remarks>
59         [EditorBrowsable(EditorBrowsableState.Never)]
60         public Rotation(Vector3 v0, Vector3 v1) : this(Interop.Rotation.NewRotation2(Vector3.getCPtr(v0), Vector3.getCPtr(v1)), true)
61         {
62             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
63         }
64
65         /// <summary>
66         /// (0.0f,0.0f,0.0f,1.0f).
67         /// </summary>
68         /// <since_tizen> 3 </since_tizen>
69         public static Rotation IDENTITY
70         {
71             get
72             {
73                 global::System.IntPtr cPtr = Interop.Rotation.IdentityGet();
74                 Rotation ret = (cPtr == global::System.IntPtr.Zero) ? null : new Rotation(cPtr, false);
75                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
76                 return ret;
77             }
78         }
79
80         /// <summary>
81         /// The addition operator.
82         /// </summary>
83         /// <param name="arg1">The first rotation.</param>
84         /// <param name="arg2">The second rotation.</param>
85         /// <returns>The rotation containing the result of the addition.</returns>
86         /// <since_tizen> 3 </since_tizen>
87         public static Rotation operator +(Rotation arg1, Rotation arg2)
88         {
89             return arg1?.Add(arg2);
90         }
91
92         /// <summary>
93         /// The subtraction operator.
94         /// </summary>
95         /// <param name="arg1">The first rotation.</param>
96         /// <param name="arg2">The second rotation.</param>
97         /// <returns>The rotation containing the result of the subtraction.</returns>
98         /// <since_tizen> 3 </since_tizen>
99         public static Rotation operator -(Rotation arg1, Rotation arg2)
100         {
101             return arg1?.Subtract(arg2);
102         }
103
104         /// <summary>
105         /// The unary negation operator.
106         /// </summary>
107         /// <param name="arg1">The first rotation.</param>
108         /// <returns>The rotation containing the negated result.</returns>
109         /// <since_tizen> 3 </since_tizen>
110         public static Rotation operator -(Rotation arg1)
111         {
112             return arg1?.Subtract();
113         }
114
115         /// <summary>
116         /// The multiplication operator.
117         /// </summary>
118         /// <param name="arg1">The first rotation.</param>
119         /// <param name="arg2">The second rotation.</param>
120         /// <returns>The rotation containing the result of the multiplication.</returns>
121         /// <since_tizen> 3 </since_tizen>
122         public static Rotation operator *(Rotation arg1, Rotation arg2)
123         {
124             return arg1?.Multiply(arg2);
125         }
126
127         /// <summary>
128         /// The multiplication operator.
129         /// </summary>
130         /// <param name="arg1">Rotation.</param>
131         /// <param name="arg2">The vector to multiply.</param>
132         /// <returns>The rotation containing the result of the multiplication.</returns>
133         /// <since_tizen> 3 </since_tizen>
134         public static Vector3 operator *(Rotation arg1, Vector3 arg2)
135         {
136             return arg1?.Multiply(arg2);
137         }
138
139         /// <summary>
140         /// The scale operator.
141         /// </summary>
142         /// <param name="arg1">Rotation.</param>
143         /// <param name="arg2">A value to scale by.</param>
144         /// <returns>The rotation containing the result of scaling.</returns>
145         /// <since_tizen> 3 </since_tizen>
146         public static Rotation operator *(Rotation arg1, float arg2)
147         {
148             return arg1?.Multiply(arg2);
149         }
150
151         /// <summary>
152         /// The division operator.
153         /// </summary>
154         /// <param name="arg1">The first rotation.</param>
155         /// <param name="arg2">The second rotation.</param>
156         /// <returns>The rotation containing the result of scaling.</returns>
157         /// <since_tizen> 3 </since_tizen>
158         public static Rotation operator /(Rotation arg1, Rotation arg2)
159         {
160             return arg1?.Divide(arg2);
161         }
162
163         /// <summary>
164         /// The scale operator.
165         /// </summary>
166         /// <param name="arg1">Rotation.</param>
167         /// <param name="arg2">A value to scale by.</param>
168         /// <returns>The rotation containing the result of scaling.</returns>
169         /// <since_tizen> 3 </since_tizen>
170         public static Rotation operator /(Rotation arg1, float arg2)
171         {
172             return arg1?.Divide(arg2);
173         }
174
175         /// <summary>
176         /// Returns the dot product of two rotations.
177         /// </summary>
178         /// <param name="q1">The first rotation.</param>
179         /// <param name="q2">The second rotation.</param>
180         /// <returns>The dot product of the two rotations.</returns>
181         /// <since_tizen> 3 </since_tizen>
182         public static float Dot(Rotation q1, Rotation q2)
183         {
184             float ret = Interop.Rotation.Dot(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
185             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186             return ret;
187         }
188
189         /// <summary>
190         /// The linear interpolation (using a straight line between the two rotations).
191         /// </summary>
192         /// <param name="q1">The start rotation.</param>
193         /// <param name="q2">The end rotation.</param>
194         /// <param name="t">A progress value between 0 and 1.</param>
195         /// <returns>The interpolated rotation.</returns>
196         /// <since_tizen> 3 </since_tizen>
197         public static Rotation Lerp(Rotation q1, Rotation q2, float t)
198         {
199             Rotation ret = new Rotation(Interop.Rotation.Lerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
200             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201             return ret;
202         }
203
204         /// <summary>
205         /// The spherical linear interpolation (using the shortest arc of a great circle between the two rotations).
206         /// </summary>
207         /// <param name="q1">The start rotation.</param>
208         /// <param name="q2">The end rotation.</param>
209         /// <param name="progress">A progress value between 0 and 1.</param>
210         /// <returns>The interpolated rotation.</returns>
211         /// <since_tizen> 3 </since_tizen>
212         public static Rotation Slerp(Rotation q1, Rotation q2, float progress)
213         {
214             Rotation ret = new Rotation(Interop.Rotation.Slerp(Rotation.getCPtr(q1), Rotation.getCPtr(q2), progress), true);
215             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216             return ret;
217         }
218
219         /// <summary>
220         /// This version of slerp, used by squad, does not check for theta > 90.
221         /// </summary>
222         /// <param name="q1">The start rotation.</param>
223         /// <param name="q2">The end rotation.</param>
224         /// <param name="t">A progress value between 0 and 1.</param>
225         /// <returns>The interpolated rotation.</returns>
226         /// <since_tizen> 3 </since_tizen>
227         public static Rotation SlerpNoInvert(Rotation q1, Rotation q2, float t)
228         {
229             Rotation ret = new Rotation(Interop.Rotation.SlerpNoInvert(Rotation.getCPtr(q1), Rotation.getCPtr(q2), t), true);
230             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231             return ret;
232         }
233
234         /// <summary>
235         /// The spherical cubic interpolation.
236         /// </summary>
237         /// <param name="start">The start rotation.</param>
238         /// <param name="end">The end rotation.</param>
239         /// <param name="ctrl1">The control rotation for q1.</param>
240         /// <param name="ctrl2">The control rotation for q2.</param>
241         /// <param name="t">A progress value between 0 and 1.</param>
242         /// <returns>The interpolated rotation.</returns>
243         /// <since_tizen> 3 </since_tizen>
244         public static Rotation Squad(Rotation start, Rotation end, Rotation ctrl1, Rotation ctrl2, float t)
245         {
246             Rotation ret = new Rotation(Interop.Rotation.Squad(Rotation.getCPtr(start), Rotation.getCPtr(end), Rotation.getCPtr(ctrl1), Rotation.getCPtr(ctrl2), t), true);
247             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248             return ret;
249         }
250
251         /// <summary>
252         /// Returns the shortest angle between two rotations in radians.
253         /// </summary>
254         /// <param name="q1">The first rotation.</param>
255         /// <param name="q2">The second rotation.</param>
256         /// <returns>The angle between the two rotation.</returns>
257         /// <since_tizen> 3 </since_tizen>
258         public static float AngleBetween(Rotation q1, Rotation q2)
259         {
260             float ret = Interop.Rotation.AngleBetween(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
261             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262             return ret;
263         }
264
265         /// <summary>
266         /// Rotate a vector3 with the Rotation.
267         /// For example, if this Rotation has (0, 1, 0) rotation axis and Math.PI radian angle and the input vector is (1, 0, 0),
268         /// this Rotation method returns (-1, 0, 0) that is rotated along Y axis amount of Math.PI.
269         /// </summary>
270         /// <param name="vector">The vector of vector3 to be rotated with this Rotation</param>
271         /// <returns>Vector3 that is the rotation result of this rotation.</returns>
272         [EditorBrowsable(EditorBrowsableState.Never)]
273         public Vector3 Rotate(Vector3 vector)
274         {
275             Vector3 ret = new Vector3(Interop.Rotation.RotateVector3(SwigCPtr, Vector3.getCPtr(vector)), true);
276             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277             return ret;
278         }
279
280         /// <summary>
281         /// Rotate a vector4 with the Rotation.
282         /// For example, if this Rotation has (0, 1, 0) rotation axis and Math.PI radian angle and the input vector is (1, 0, 0, 0),
283         /// this Rotation method returns (-1, 0, 0, 0) that is rotated along Y axis amount of Math.PI.
284         /// </summary>
285         /// <param name="vector">The vector of vector4 to be rotated with this Rotation</param>
286         /// <returns>Vector4 that is the rotation result of this rotation.</returns>
287         [EditorBrowsable(EditorBrowsableState.Never)]
288         public Vector4 Rotate(Vector4 vector)
289         {
290             Vector4 ret = new Vector4(Interop.Rotation.RotateVector4(SwigCPtr, Vector4.getCPtr(vector)), true);
291             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292             return ret;
293         }
294
295         /// <summary>
296         /// Helper to check if this is an identity quaternion.
297         /// </summary>
298         /// <returns>True if this is identity quaternion.</returns>
299         /// <since_tizen> 3 </since_tizen>
300         public bool IsIdentity()
301         {
302             bool ret = Interop.Rotation.IsIdentity(SwigCPtr);
303             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304             return ret;
305         }
306
307         /// <summary>
308         /// Converts the quaternion to an axis or angle pair.
309         /// </summary>
310         /// <param name="axis">The result of an axis.</param>
311         /// <param name="angle">The result of angle in radians.</param>
312         /// <returns>True if converted correctly.</returns>
313         /// <since_tizen> 3 </since_tizen>
314         public bool GetAxisAngle(Vector3 axis, Radian angle)
315         {
316             bool ret = Interop.Rotation.GetAxisAngle(SwigCPtr, Vector3.getCPtr(axis), Radian.getCPtr(angle));
317             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318             return ret;
319         }
320
321         /// <summary>
322         /// Returns the length of the rotation.
323         /// </summary>
324         /// <returns>The length of the rotation.</returns>
325         /// <since_tizen> 3 </since_tizen>
326         public float Length()
327         {
328             float ret = Interop.Rotation.Length(SwigCPtr);
329             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330             return ret;
331         }
332
333         /// <summary>
334         /// Returns the squared length of the rotation.
335         /// </summary>
336         /// <returns>The squared length of the rotation.</returns>
337         /// <since_tizen> 3 </since_tizen>
338         public float LengthSquared()
339         {
340             float ret = Interop.Rotation.LengthSquared(SwigCPtr);
341             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342             return ret;
343         }
344
345         /// <summary>
346         /// Normalizes this to unit length.
347         /// </summary>
348         /// <since_tizen> 3 </since_tizen>
349         public void Normalize()
350         {
351             Interop.Rotation.Normalize(SwigCPtr);
352             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353         }
354
355         /// <summary>
356         /// Normalized.
357         /// </summary>
358         /// <returns>A normalized version of this rotation.</returns>
359         /// <since_tizen> 3 </since_tizen>
360         public Rotation Normalized()
361         {
362             Rotation ret = new Rotation(Interop.Rotation.Normalized(SwigCPtr), true);
363             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364             return ret;
365         }
366
367         /// <summary>
368         /// Conjugates this rotation.
369         /// </summary>
370         /// <since_tizen> 3 </since_tizen>
371         public void Conjugate()
372         {
373             Interop.Rotation.Conjugate(SwigCPtr);
374             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375         }
376
377         /// <summary>
378         /// Inverts this rotation.
379         /// </summary>
380         /// <since_tizen> 3 </since_tizen>
381         public void Invert()
382         {
383             Interop.Rotation.Invert(SwigCPtr);
384             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
385         }
386
387         /// <summary>
388         /// Performs the logarithm of a rotation.
389         /// </summary>
390         /// <returns>The rotation representing the logarithm.</returns>
391         /// <since_tizen> 3 </since_tizen>
392         public Rotation Log()
393         {
394             Rotation ret = new Rotation(Interop.Rotation.Log(SwigCPtr), true);
395             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396             return ret;
397         }
398
399         /// <summary>
400         /// Performs an exponent.
401         /// </summary>
402         /// <returns>The rotation representing the exponent.</returns>
403         /// <since_tizen> 3 </since_tizen>
404         public Rotation Exp()
405         {
406             Rotation ret = new Rotation(Interop.Rotation.Exp(SwigCPtr), true);
407             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408             return ret;
409         }
410
411         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rotation obj)
412         {
413             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
414         }
415
416         internal Rotation(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
417         {
418         }
419
420         /// This will not be public opened.
421         [EditorBrowsable(EditorBrowsableState.Never)]
422         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
423         {
424             Interop.Rotation.DeleteRotation(swigCPtr);
425         }
426
427         private Rotation Add(Rotation other)
428         {
429             Rotation ret = new Rotation(Interop.Rotation.Add(SwigCPtr, Rotation.getCPtr(other)), true);
430             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431             return ret;
432         }
433
434         private Rotation Subtract(Rotation other)
435         {
436             Rotation ret = new Rotation(Interop.Rotation.Subtract(SwigCPtr, Rotation.getCPtr(other)), true);
437             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
438             return ret;
439         }
440
441         private Rotation Multiply(Rotation other)
442         {
443             Rotation ret = new Rotation(Interop.Rotation.MultiplyQuaternion(SwigCPtr, Rotation.getCPtr(other)), true);
444             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
445             return ret;
446         }
447
448         private Vector3 Multiply(Vector3 other)
449         {
450             Vector3 ret = new Vector3(Interop.Rotation.MultiplyVector3(SwigCPtr, Vector3.getCPtr(other)), true);
451             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
452             return ret;
453         }
454
455         private Rotation Divide(Rotation other)
456         {
457             Rotation ret = new Rotation(Interop.Rotation.Divide(SwigCPtr, Rotation.getCPtr(other)), true);
458             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
459             return ret;
460         }
461
462         private Rotation Multiply(float scale)
463         {
464             Rotation ret = new Rotation(Interop.Rotation.Multiply(SwigCPtr, scale), true);
465             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
466             return ret;
467         }
468
469         private Rotation Divide(float scale)
470         {
471             Rotation ret = new Rotation(Interop.Rotation.Divide(SwigCPtr, scale), true);
472             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
473             return ret;
474         }
475
476         private Rotation Subtract()
477         {
478             Rotation ret = new Rotation(Interop.Rotation.Subtract(SwigCPtr), true);
479             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
480             return ret;
481         }
482
483         private Rotation AddAssign(Rotation other)
484         {
485             Rotation ret = new Rotation(Interop.Rotation.AddAssign(SwigCPtr, Rotation.getCPtr(other)), false);
486             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
487             return ret;
488         }
489
490         private Rotation SubtractAssign(Rotation other)
491         {
492             Rotation ret = new Rotation(Interop.Rotation.SubtractAssign(SwigCPtr, Rotation.getCPtr(other)), false);
493             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
494             return ret;
495         }
496
497         private Rotation MultiplyAssign(Rotation other)
498         {
499             Rotation ret = new Rotation(Interop.Rotation.MultiplyAssign(SwigCPtr, Rotation.getCPtr(other)), false);
500             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
501             return ret;
502         }
503
504         private Rotation MultiplyAssign(float scale)
505         {
506             Rotation ret = new Rotation(Interop.Rotation.MultiplyAssign(SwigCPtr, scale), false);
507             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
508             return ret;
509         }
510
511         private Rotation DivideAssign(float scale)
512         {
513             Rotation ret = new Rotation(Interop.Rotation.DivideAssign(SwigCPtr, scale), false);
514             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
515             return ret;
516         }
517
518         private bool EqualTo(Rotation rhs)
519         {
520             bool ret = Interop.Rotation.EqualTo(SwigCPtr, Rotation.getCPtr(rhs));
521             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
522             return ret;
523         }
524
525         private bool NotEqualTo(Rotation rhs)
526         {
527             bool ret = Interop.Rotation.NotEqualTo(SwigCPtr, Rotation.getCPtr(rhs));
528             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
529             return ret;
530         }
531     }
532 }