Tanoda
LeapQuaternion.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9namespace Leap {
10 using System;
11
16 [Serializable]
17 public struct LeapQuaternion :
18 IEquatable<LeapQuaternion> {
19
24 public LeapQuaternion(float x, float y, float z, float w) :
25 this() {
26 this.x = x;
27 this.y = y;
28 this.z = z;
29 this.w = w;
30 }
31
36 public LeapQuaternion(LeapQuaternion quaternion) :
37 this() {
38 x = quaternion.x;
39 y = quaternion.y;
40 z = quaternion.z;
41 w = quaternion.w;
42 }
43
49 this() {
50 x = quaternion.x;
51 y = quaternion.y;
52 z = quaternion.z;
53 w = quaternion.w;
54 }
55
60 public override string ToString() {
61 return "(" + x + ", " + y + ", " + z + ", " + w + ")";
62 }
63
68 public bool Equals(LeapQuaternion v) {
69 return x.NearlyEquals(v.x) && y.NearlyEquals(v.y) && z.NearlyEquals(v.z) && w.NearlyEquals(v.w);
70 }
71 public override bool Equals(Object obj) {
72 return obj is LeapQuaternion && Equals((LeapQuaternion)obj);
73 }
74
80 public bool IsValid() {
81 return !(float.IsNaN(x) || float.IsInfinity(x) ||
82 float.IsNaN(y) || float.IsInfinity(y) ||
83 float.IsNaN(z) || float.IsInfinity(z) ||
84 float.IsNaN(w) || float.IsInfinity(w));
85 }
86
87 public float x;
88 public float y;
89 public float z;
90 public float w;
91
96 public float Magnitude {
97 get { return (float)Math.Sqrt(x * x + y * y + z * z + w * w); }
98 }
99
104 public float MagnitudeSquared {
105 get { return x * x + y * y + z * z + w * w; }
106 }
107
113 get {
114 float denom = MagnitudeSquared;
115 if (denom <= Constants.EPSILON) {
116 return Identity;
117 }
118 denom = 1.0f / (float)Math.Sqrt(denom);
119 return new LeapQuaternion(x * denom, y * denom, z * denom, w * denom);
120 }
121 }
122
129 return new LeapQuaternion(
130 w * rhs.x + x * rhs.w + y * rhs.z - z * rhs.y,
131 w * rhs.y + y * rhs.w + z * rhs.x - x * rhs.z,
132 w * rhs.z + z * rhs.w + x * rhs.y - y * rhs.x,
133 w * rhs.w - x * rhs.x - y * rhs.y - z * rhs.z);
134 }
135
140 public static readonly LeapQuaternion Identity = new LeapQuaternion(0, 0, 0, 1);
141
142 public override int GetHashCode() {
143 unchecked // Overflow is fine, just wrap
144 {
145 int hash = 17;
146 hash = hash * 23 + x.GetHashCode();
147 hash = hash * 23 + y.GetHashCode();
148 hash = hash * 23 + z.GetHashCode();
149 hash = hash * 23 + w.GetHashCode();
150
151 return hash;
152 }
153 }
154 }
155}
Es.InkPainter.Math Math
Definition: PaintTest.cs:7
UnityEngine.Object Object
The LeapQuaternion struct represents a rotation in three-dimensional space.
LeapQuaternion Multiply(LeapQuaternion rhs)
Concatenates the rotation described by this quaternion with the one provided and returns the result.
float MagnitudeSquared
The square of the magnitude, or length, of this quaternion.
LeapQuaternion Normalized
A normalized copy of this quaternion.
bool Equals(LeapQuaternion v)
Compare LeapQuaternion equality component-wise.
LeapQuaternion(LeapInternal.LEAP_QUATERNION quaternion)
Copies the specified LEAP_QUATERNION.
LeapQuaternion(LeapQuaternion quaternion)
Copies the specified LeapQuaternion.
static readonly LeapQuaternion Identity
The identity quaternion.
float Magnitude
The magnitude, or length, of this quaternion.
LeapQuaternion(float x, float y, float z, float w)
Creates a new LeapQuaternion with the specified component values.
bool IsValid()
Returns true if all of the quaternion's components are finite. If any component is NaN or infinite,...
override string ToString()
Returns a string containing this quaternion in a human readable format: (x, y, z).
override bool Equals(Object obj)
override int GetHashCode()