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