2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.ComponentModel;
19 using Tizen.NUI.Binding;
24 /// The Rotation class.
26 /// <since_tizen> 3 </since_tizen>
27 [Binding.TypeConverter(typeof(RotationTypeConverter))]
28 public class Rotation : Disposable
32 /// The default constructor.
34 /// <since_tizen> 3 </since_tizen>
35 public Rotation() : this(Interop.Rotation.NewRotation(), true)
37 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
41 /// The constructor from an axis and angle.
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)
48 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
52 /// The constructor of Rotation which describes minimum rotation to align v0 with v1.
54 /// <param name="v0">The first normalized vector.</param>
55 /// <param name="v1">The second normalized vector.</param>
57 /// v0 and v1 should be normalized.
59 [EditorBrowsable(EditorBrowsableState.Never)]
60 public Rotation(Vector3 v0, Vector3 v1) : this(Interop.Rotation.NewRotation2(Vector3.getCPtr(v0), Vector3.getCPtr(v1)), true)
62 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66 /// The constructor of Rotation from Euler angles.
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)
74 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
78 /// (0.0f,0.0f,0.0f,1.0f).
80 /// <since_tizen> 3 </since_tizen>
81 public static Rotation IDENTITY
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());
93 /// The addition operator.
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)
101 return arg1?.Add(arg2);
105 /// The subtraction operator.
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)
113 return arg1?.Subtract(arg2);
117 /// The unary negation operator.
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)
124 return arg1?.Subtract();
128 /// The multiplication operator.
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)
136 return arg1?.Multiply(arg2);
140 /// The multiplication operator.
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)
148 return arg1?.Multiply(arg2);
152 /// The scale operator.
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)
160 return arg1?.Multiply(arg2);
164 /// The division operator.
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)
172 return arg1?.Divide(arg2);
176 /// The scale operator.
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)
184 return arg1?.Divide(arg2);
188 /// Returns the dot product of two rotations.
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)
196 float ret = Interop.Rotation.Dot(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
197 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202 /// The linear interpolation (using a straight line between the two rotations).
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)
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();
217 /// The spherical linear interpolation (using the shortest arc of a great circle between the two rotations).
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)
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();
232 /// This version of slerp, used by squad, does not check for theta > 90.
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)
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();
247 /// The spherical cubic interpolation.
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)
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();
264 /// Returns the shortest angle between two rotations in radians.
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)
272 float ret = Interop.Rotation.AngleBetween(Rotation.getCPtr(q1), Rotation.getCPtr(q2));
273 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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)
287 Vector3 ret = new Vector3(Interop.Rotation.RotateVector3(SwigCPtr, Vector3.getCPtr(vector)), true);
288 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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)
302 Vector4 ret = new Vector4(Interop.Rotation.RotateVector4(SwigCPtr, Vector4.getCPtr(vector)), true);
303 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 /// Helper to check if this is an identity quaternion.
310 /// <returns>True if this is identity quaternion.</returns>
311 /// <since_tizen> 3 </since_tizen>
312 public bool IsIdentity()
314 bool ret = Interop.Rotation.IsIdentity(SwigCPtr);
315 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 /// Converts the quaternion to an axis or angle pair.
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)
328 bool ret = Interop.Rotation.GetAxisAngle(SwigCPtr, Vector3.getCPtr(axis), Radian.getCPtr(angle));
329 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 /// Returns the length of the rotation.
336 /// <returns>The length of the rotation.</returns>
337 /// <since_tizen> 3 </since_tizen>
338 public float Length()
340 float ret = Interop.Rotation.Length(SwigCPtr);
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346 /// Returns the squared length of the rotation.
348 /// <returns>The squared length of the rotation.</returns>
349 /// <since_tizen> 3 </since_tizen>
350 public float LengthSquared()
352 float ret = Interop.Rotation.LengthSquared(SwigCPtr);
353 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358 /// Normalizes this to unit length.
360 /// <since_tizen> 3 </since_tizen>
361 public void Normalize()
363 Interop.Rotation.Normalize(SwigCPtr);
364 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370 /// <returns>A normalized version of this rotation.</returns>
371 /// <since_tizen> 3 </since_tizen>
372 public Rotation Normalized()
374 Rotation ret = new Rotation(Interop.Rotation.Normalized(SwigCPtr), true);
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380 /// Conjugates this rotation.
382 /// <since_tizen> 3 </since_tizen>
383 public void Conjugate()
385 Interop.Rotation.Conjugate(SwigCPtr);
386 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
390 /// Inverts this rotation.
392 /// <since_tizen> 3 </since_tizen>
395 Interop.Rotation.Invert(SwigCPtr);
396 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 /// Performs the logarithm of a rotation.
402 /// <returns>The rotation representing the logarithm.</returns>
403 /// <since_tizen> 3 </since_tizen>
404 public Rotation Log()
406 Rotation ret = new Rotation(Interop.Rotation.Log(SwigCPtr), true);
407 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
412 /// Performs an exponent.
414 /// <returns>The rotation representing the exponent.</returns>
415 /// <since_tizen> 3 </since_tizen>
416 public Rotation Exp()
418 Rotation ret = new Rotation(Interop.Rotation.Exp(SwigCPtr), true);
419 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
423 internal Rotation(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
427 /// This will not be public opened.
428 [EditorBrowsable(EditorBrowsableState.Never)]
429 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
431 Interop.Rotation.DeleteRotation(swigCPtr);
434 private Rotation Add(Rotation other)
436 Rotation ret = new Rotation(Interop.Rotation.Add(SwigCPtr, Rotation.getCPtr(other)), true);
437 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
441 private Rotation Subtract(Rotation other)
443 Rotation ret = new Rotation(Interop.Rotation.Subtract(SwigCPtr, Rotation.getCPtr(other)), true);
444 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
448 private Rotation Multiply(Rotation other)
450 Rotation ret = new Rotation(Interop.Rotation.MultiplyQuaternion(SwigCPtr, Rotation.getCPtr(other)), true);
451 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
455 private Vector3 Multiply(Vector3 other)
457 Vector3 ret = new Vector3(Interop.Rotation.MultiplyVector3(SwigCPtr, Vector3.getCPtr(other)), true);
458 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
462 private Rotation Divide(Rotation other)
464 Rotation ret = new Rotation(Interop.Rotation.Divide(SwigCPtr, Rotation.getCPtr(other)), true);
465 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469 private Rotation Multiply(float scale)
471 Rotation ret = new Rotation(Interop.Rotation.Multiply(SwigCPtr, scale), true);
472 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
476 private Rotation Divide(float scale)
478 Rotation ret = new Rotation(Interop.Rotation.Divide(SwigCPtr, scale), true);
479 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483 private Rotation Subtract()
485 Rotation ret = new Rotation(Interop.Rotation.Subtract(SwigCPtr), true);
486 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
490 private Rotation AddAssign(Rotation other)
492 Rotation ret = new Rotation(Interop.Rotation.AddAssign(SwigCPtr, Rotation.getCPtr(other)), false);
493 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
497 private Rotation SubtractAssign(Rotation other)
499 Rotation ret = new Rotation(Interop.Rotation.SubtractAssign(SwigCPtr, Rotation.getCPtr(other)), false);
500 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
504 private Rotation MultiplyAssign(Rotation other)
506 Rotation ret = new Rotation(Interop.Rotation.MultiplyAssign(SwigCPtr, Rotation.getCPtr(other)), false);
507 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
511 private Rotation MultiplyAssign(float scale)
513 Rotation ret = new Rotation(Interop.Rotation.MultiplyAssign(SwigCPtr, scale), false);
514 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
518 private Rotation DivideAssign(float scale)
520 Rotation ret = new Rotation(Interop.Rotation.DivideAssign(SwigCPtr, scale), false);
521 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
525 private bool EqualTo(Rotation rhs)
527 bool ret = Interop.Rotation.EqualTo(SwigCPtr, Rotation.getCPtr(rhs));
528 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
532 private bool NotEqualTo(Rotation rhs)
534 bool ret = Interop.Rotation.NotEqualTo(SwigCPtr, Rotation.getCPtr(rhs));
535 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();