@vived/app 2.20.1 → 2.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Core/BaseApp/Boundary.d.ts +49 -0
- package/lib/Core/BaseApp/Boundary.js +2 -0
- package/lib/Core/BaseApp/Entity.d.ts +11 -0
- package/lib/Core/BaseApp/Entity.js +2 -0
- package/lib/Core/BaseApp/Errors/ErrorDuplicateSystemName.d.ts +3 -0
- package/lib/Core/BaseApp/Errors/ErrorDuplicateSystemName.js +12 -0
- package/lib/Core/BaseApp/Errors/ErrorNoHostHandler.d.ts +3 -0
- package/lib/Core/BaseApp/Errors/ErrorNoHostHandler.js +10 -0
- package/lib/Core/BaseApp/Errors/ErrorUnsupportedVersionNumber.d.ts +3 -0
- package/lib/Core/BaseApp/Errors/ErrorUnsupportedVersionNumber.js +10 -0
- package/lib/Core/BaseApp/Errors/index.d.ts +3 -0
- package/lib/Core/BaseApp/Errors/index.js +15 -0
- package/lib/Core/BaseApp/UseCase.d.ts +43 -0
- package/lib/Core/BaseApp/UseCase.js +250 -0
- package/lib/Core/BaseAppState/Boundary.d.ts +14 -0
- package/lib/Core/BaseAppState/Boundary.js +2 -0
- package/lib/Core/BaseAppState/Entity.d.ts +5 -0
- package/lib/Core/BaseAppState/Entity.js +2 -0
- package/lib/Core/BaseAppState/UseCase.d.ts +16 -0
- package/lib/Core/BaseAppState/UseCase.js +54 -0
- package/lib/Core/BaseAppState/UseCase_Imp.d.ts +16 -0
- package/lib/Core/BaseAppState/UseCase_Imp.js +54 -0
- package/lib/Core/DevicePreview/DevicePreviewUC_Imp.d.ts +16 -0
- package/lib/Core/DevicePreview/DevicePreviewUC_Imp.js +56 -0
- package/lib/Core/DevicePreview/boundary.d.ts +14 -0
- package/lib/Core/DevicePreview/boundary.js +2 -0
- package/lib/Core/DevicePreview/entity.d.ts +5 -0
- package/lib/Core/DevicePreview/entity.js +2 -0
- package/lib/Core/DispatchToHost/Entity.d.ts +4 -0
- package/lib/Core/DispatchToHost/Entity.js +2 -0
- package/lib/Core/DispatchToHost/UseCase.d.ts +12 -0
- package/lib/Core/DispatchToHost/UseCase.js +70 -0
- package/lib/Core/DispatchToHost/boundary.d.ts +9 -0
- package/lib/Core/DispatchToHost/boundary.js +2 -0
- package/lib/Core/Serilization/Boundary.d.ts +20 -0
- package/lib/Core/Serilization/Boundary.js +2 -0
- package/lib/Core/Serilization/Entity.d.ts +3 -0
- package/lib/Core/Serilization/Entity.js +2 -0
- package/lib/Core/Serilization/ErrorDuplicateSystemName.d.ts +3 -0
- package/lib/Core/Serilization/ErrorDuplicateSystemName.js +12 -0
- package/lib/Core/Serilization/ErrorUnsupportedVersionNumber.d.ts +3 -0
- package/lib/Core/Serilization/ErrorUnsupportedVersionNumber.js +10 -0
- package/lib/Core/Serilization/Errors.d.ts +6 -0
- package/lib/Core/Serilization/Errors.js +19 -0
- package/lib/Core/Serilization/UseCase.d.ts +10 -0
- package/lib/Core/Serilization/UseCase.js +52 -0
- package/lib/Core/Serilization/UseCase_Imp.d.ts +10 -0
- package/lib/Core/Serilization/UseCase_Imp.js +51 -0
- package/lib/Core/index.d.ts +3 -0
- package/lib/Core/index.js +19 -0
- package/lib/Entities/Color.d.ts +20 -0
- package/lib/Entities/Color.js +59 -0
- package/lib/Entities/LineSegment2D.d.ts +11 -0
- package/lib/Entities/LineSegment2D.js +70 -0
- package/lib/Entities/MouseSceneInput.d.ts +15 -0
- package/lib/Entities/MouseSceneInput.js +109 -0
- package/lib/Entities/OrbitCamera.d.ts +76 -0
- package/lib/Entities/OrbitCamera.js +243 -0
- package/lib/Entities/ParametricLine.d.ts +29 -0
- package/lib/Entities/ParametricLine.js +79 -0
- package/lib/Entities/ParametricPlane.d.ts +20 -0
- package/lib/Entities/ParametricPlane.js +63 -0
- package/lib/Entities/SceneRoot.d.ts +69 -0
- package/lib/Entities/SceneRoot.js +77 -0
- package/lib/Entities/TransformNode.d.ts +78 -0
- package/lib/Entities/TransformNode.js +217 -0
- package/lib/Entities/Vector2.d.ts +21 -0
- package/lib/Entities/Vector2.js +83 -0
- package/lib/Entities/Vector3.d.ts +19 -0
- package/lib/Entities/Vector3.js +75 -0
- package/lib/Entities/WorkPlane.d.ts +49 -0
- package/lib/Entities/WorkPlane.js +122 -0
- package/lib/Entities/index.d.ts +3 -0
- package/lib/Entities/index.js +3 -0
- package/lib/Interface/Controllers/appHandler.d.ts +12 -0
- package/lib/Interface/Controllers/appHandler.js +94 -0
- package/lib/Interface/Controllers/defaultAppHanlderFunctions.d.ts +3 -0
- package/lib/Interface/Controllers/defaultAppHanlderFunctions.js +31 -0
- package/lib/Interface/Controllers/dispatchStateChange.d.ts +2 -0
- package/lib/Interface/Controllers/dispatchStateChange.js +10 -0
- package/lib/Interface/Controllers/index.d.ts +9 -0
- package/lib/Interface/Controllers/index.js +21 -0
- package/lib/Interface/Controllers/makeAppHandler.d.ts +12 -0
- package/lib/Interface/Controllers/makeAppHandler.js +96 -0
- package/lib/Interface/Controllers/setDevicePreview.d.ts +2 -0
- package/lib/Interface/Controllers/setDevicePreview.js +14 -0
- package/lib/Interface/Controllers/setIsAuthoring.d.ts +2 -0
- package/lib/Interface/Controllers/setIsAuthoring.js +14 -0
- package/lib/Interface/Controllers/setState.d.ts +2 -0
- package/lib/Interface/Controllers/setState.js +21 -0
- package/lib/Interface/Controllers/showBabylonInspector.d.ts +2 -0
- package/lib/Interface/Controllers/showBabylonInspector.js +9 -0
- package/lib/Interface/Controllers/startApp.d.ts +1 -0
- package/lib/Interface/Controllers/startApp.js +9 -0
- package/lib/Interface/Controllers/stopApp.d.ts +2 -0
- package/lib/Interface/Controllers/stopApp.js +10 -0
- package/lib/Interface/PresentationManagers/DevicePreviewPM.d.ts +13 -0
- package/lib/Interface/PresentationManagers/DevicePreviewPM.js +25 -0
- package/lib/Interface/PresentationManagers/IsAuthoringPM.d.ts +10 -0
- package/lib/Interface/PresentationManagers/IsAuthoringPM.js +23 -0
- package/lib/Interface/PresentationManagers/ShowBabylonInspectorPM.d.ts +10 -0
- package/lib/Interface/PresentationManagers/ShowBabylonInspectorPM.js +23 -0
- package/lib/Interface/PresentationManagers/index.d.ts +3 -0
- package/lib/Interface/PresentationManagers/index.js +15 -0
- package/lib/Interface/appHandler.d.ts +12 -0
- package/lib/Interface/appHandler.js +94 -0
- package/lib/Interface/index.d.ts +2 -0
- package/lib/Interface/index.js +14 -0
- package/lib/PresentationManagers/OrbitCameraPM.d.ts +14 -0
- package/lib/PresentationManagers/OrbitCameraPM.js +31 -0
- package/lib/PresentationManagers/TransformNodePM.d.ts +14 -0
- package/lib/PresentationManagers/TransformNodePM.js +23 -0
- package/lib/PresentationManagers/index.d.ts +1 -0
- package/lib/PresentationManagers/index.js +1 -0
- package/lib/UseCases/LerpOrbitCamera.d.ts +36 -0
- package/lib/UseCases/LerpOrbitCamera.js +71 -0
- package/lib/UseCases/OrbitCamera/LerpOrbitCamera.d.ts +36 -0
- package/lib/UseCases/OrbitCamera/LerpOrbitCamera.js +71 -0
- package/lib/UseCases/OrbitCamera/PixelDolly_OrbitCamera.d.ts +9 -0
- package/lib/UseCases/OrbitCamera/PixelDolly_OrbitCamera.js +31 -0
- package/lib/UseCases/OrbitCamera/PixelPlanePan_OrbitCamera.d.ts +10 -0
- package/lib/UseCases/OrbitCamera/PixelPlanePan_OrbitCamera.js +31 -0
- package/lib/UseCases/OrbitCamera/SerializeOrbitCamera.d.ts +22 -0
- package/lib/UseCases/OrbitCamera/SerializeOrbitCamera.js +81 -0
- package/lib/UseCases/OrbitCamera/index.d.ts +4 -0
- package/lib/UseCases/OrbitCamera/index.js +16 -0
- package/lib/UseCases/SceneRoot/SerializeSceneRoot.d.ts +18 -0
- package/lib/UseCases/SceneRoot/SerializeSceneRoot.js +48 -0
- package/lib/UseCases/SceneRoot/index.d.ts +1 -0
- package/lib/UseCases/SceneRoot/index.js +13 -0
- package/lib/UseCases/SerializeCamera.d.ts +21 -0
- package/lib/UseCases/SerializeCamera.js +59 -0
- package/lib/UseCases/SerializeOrbitCamera.d.ts +21 -0
- package/lib/UseCases/SerializeOrbitCamera.js +59 -0
- package/lib/UseCases/SerializedCamDemo.d.ts +0 -0
- package/lib/UseCases/SerializedCamDemo.js +1 -0
- package/lib/UseCases/index.d.ts +1 -0
- package/lib/UseCases/index.js +1 -0
- package/lib/ValueObjects/Angle.d.ts +18 -0
- package/lib/ValueObjects/Angle.js +26 -2
- package/lib/ValueObjects/Color.d.ts +46 -0
- package/lib/ValueObjects/Color.js +46 -0
- package/lib/ValueObjects/Matrix.d.ts +120 -0
- package/lib/ValueObjects/Matrix.js +423 -0
- package/lib/ValueObjects/Quaternion.d.ts +94 -0
- package/lib/ValueObjects/Quaternion.js +243 -0
- package/lib/ValueObjects/Vector2.d.ts +82 -0
- package/lib/ValueObjects/Vector2.js +82 -0
- package/lib/ValueObjects/Vector3.d.ts +107 -0
- package/lib/ValueObjects/Vector3.js +116 -0
- package/lib/ValueObjects/index.d.ts +2 -0
- package/lib/ValueObjects/index.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Quaternion = void 0;
|
|
4
|
+
const Angle_1 = require("./Angle");
|
|
5
|
+
const Matrix_1 = require("./Matrix");
|
|
6
|
+
const Vector3_1 = require("./Vector3");
|
|
7
|
+
class Quaternion {
|
|
8
|
+
constructor(x, y, z, w) {
|
|
9
|
+
this.x = x;
|
|
10
|
+
this.y = y;
|
|
11
|
+
this.z = z;
|
|
12
|
+
this.w = w;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Checks to see if two Quaternions are equal
|
|
16
|
+
* @param a Quaternion A
|
|
17
|
+
* @param b Quaternion B
|
|
18
|
+
* @returns True if they are equal, otherwise false
|
|
19
|
+
*/
|
|
20
|
+
static Equal(a, b) {
|
|
21
|
+
if (a.x === b.x && a.y === b.y && a.z === b.z && a.w === b.w) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Checks two quaternions to see if they are close
|
|
30
|
+
* @param a Quaterion A
|
|
31
|
+
* @param b Quaterion B
|
|
32
|
+
* @param threshold "Close" threshold. Defaults to 0.001
|
|
33
|
+
* @returns True if each of Quaterion's components are within the threshold of each other
|
|
34
|
+
*/
|
|
35
|
+
static Close(a, b, threshold = 0.001) {
|
|
36
|
+
const aArray = a.toArray();
|
|
37
|
+
const bArray = b.toArray();
|
|
38
|
+
let areClose = true;
|
|
39
|
+
for (let i = 0; i < 4; i++) {
|
|
40
|
+
let diff = aArray[i] - bArray[i];
|
|
41
|
+
if (diff < 0) {
|
|
42
|
+
diff = -diff;
|
|
43
|
+
}
|
|
44
|
+
if (diff > threshold) {
|
|
45
|
+
areClose = false;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return areClose;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Multiplies A*B
|
|
53
|
+
* @param a Quaterion A
|
|
54
|
+
* @param b Quaternion B
|
|
55
|
+
* @returns The result of A*B
|
|
56
|
+
*/
|
|
57
|
+
static Multiply(a, b) {
|
|
58
|
+
const x = a.x * b.w + a.y * b.z - a.z * b.y + a.w * b.x;
|
|
59
|
+
const y = -a.x * b.z + a.y * b.w + a.z * b.x + a.w * b.y;
|
|
60
|
+
const z = a.x * b.y - a.y * b.x + a.z * b.w + a.w * b.z;
|
|
61
|
+
const w = -a.x * b.x - a.y * b.y - a.z * b.z + a.w * b.w;
|
|
62
|
+
return Quaternion.FromArray([x, y, z, w]);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new Quaterion from an array of values
|
|
66
|
+
* @param values The four values of the Quaterion: [x,y,z,w]
|
|
67
|
+
* @returns A Quaterion
|
|
68
|
+
*/
|
|
69
|
+
static FromArray(values) {
|
|
70
|
+
return new Quaternion(values[0], values[1], values[2], values[3]);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates an Identity Quaternion
|
|
74
|
+
* @returns An Identity Quaternion
|
|
75
|
+
*/
|
|
76
|
+
static Identity() {
|
|
77
|
+
return new Quaternion(0, 0, 0, 1);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates an quaterion about an axis for a given angle
|
|
81
|
+
* @param axis The rotation axis
|
|
82
|
+
* @param angle The rotation angle
|
|
83
|
+
* @returns The resulting Quaterion
|
|
84
|
+
*/
|
|
85
|
+
static FromAngleAxis(axis, angle) {
|
|
86
|
+
const sin = Math.sin(angle.radians / 2);
|
|
87
|
+
const axisUnit = axis.unit;
|
|
88
|
+
const w = Math.cos(angle.radians / 2);
|
|
89
|
+
const x = axisUnit.x * sin;
|
|
90
|
+
const y = axisUnit.y * sin;
|
|
91
|
+
const z = axisUnit.z * sin;
|
|
92
|
+
return new Quaternion(x, y, z, w);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Froms up a Quaternion from the Yaw-Pitch-Roll (Tait-Bryan) convetion
|
|
96
|
+
* @param yaw defines the rotation around the y axis
|
|
97
|
+
* @param pitch defines the rotation around the x axis
|
|
98
|
+
* @param roll defines the rotation around the z axis
|
|
99
|
+
* @returns the resulting quaterion
|
|
100
|
+
*/
|
|
101
|
+
static FromYawPitchRoll(yaw, pitch, roll) {
|
|
102
|
+
const halfRoll = roll.radians * 0.5;
|
|
103
|
+
const halfPitch = pitch.radians * 0.5;
|
|
104
|
+
const halfYaw = yaw.radians * 0.5;
|
|
105
|
+
const sinRoll = Math.sin(halfRoll);
|
|
106
|
+
const cosRoll = Math.cos(halfRoll);
|
|
107
|
+
const sinPitch = Math.sin(halfPitch);
|
|
108
|
+
const cosPitch = Math.cos(halfPitch);
|
|
109
|
+
const sinYaw = Math.sin(halfYaw);
|
|
110
|
+
const cosYaw = Math.cos(halfYaw);
|
|
111
|
+
const x = cosYaw * sinPitch * cosRoll + sinYaw * cosPitch * sinRoll;
|
|
112
|
+
const y = sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll;
|
|
113
|
+
const z = cosYaw * cosPitch * sinRoll - sinYaw * sinPitch * cosRoll;
|
|
114
|
+
const w = cosYaw * cosPitch * cosRoll + sinYaw * sinPitch * sinRoll;
|
|
115
|
+
return new Quaternion(x, y, z, w);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Creates a Quaternion from three euler angles.
|
|
119
|
+
* @param x Rotation about the x axis
|
|
120
|
+
* @param y Rotation about the y axis
|
|
121
|
+
* @param z Rotation about the z axis
|
|
122
|
+
* @returns The Quaterion
|
|
123
|
+
*/
|
|
124
|
+
static FromEuler(x, y, z) {
|
|
125
|
+
return this.FromYawPitchRoll(y, x, z);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns a new Quaternion that is an invert of A
|
|
129
|
+
* @param a The quaternion to invert
|
|
130
|
+
* @returns The inverted Quaternion
|
|
131
|
+
*/
|
|
132
|
+
static Inverse(a) {
|
|
133
|
+
return new Quaternion(-a.x, -a.y, -a.z, a.w);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Spherically interpolates between two quaternions
|
|
137
|
+
* @param initial The initial quaternion
|
|
138
|
+
* @param final The final quaterion
|
|
139
|
+
* @param percent The percent along the slerp. 0 will return the initial quaterion and 1 will return the final quaterion
|
|
140
|
+
* @returns The interpolated quaterion
|
|
141
|
+
*/
|
|
142
|
+
static Slerp(initial, final, percent) {
|
|
143
|
+
let A;
|
|
144
|
+
let B;
|
|
145
|
+
let C = initial.x * final.x +
|
|
146
|
+
initial.y * final.y +
|
|
147
|
+
initial.z * final.z +
|
|
148
|
+
initial.w * final.w;
|
|
149
|
+
let flip = false;
|
|
150
|
+
if (C < 0) {
|
|
151
|
+
flip = true;
|
|
152
|
+
C = -C;
|
|
153
|
+
}
|
|
154
|
+
if (C > 0.999999) {
|
|
155
|
+
B = 1 - percent;
|
|
156
|
+
A = flip ? -percent : percent;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
const D = Math.acos(C);
|
|
160
|
+
const E = 1.0 / Math.sin(D);
|
|
161
|
+
B = Math.sin((1.0 - percent) * D) * E;
|
|
162
|
+
A = flip ? -Math.sin(percent * D) * E : Math.sin(percent * D) * E;
|
|
163
|
+
}
|
|
164
|
+
const x = B * initial.x + A * final.x;
|
|
165
|
+
const y = B * initial.y + A * final.y;
|
|
166
|
+
const z = B * initial.z + A * final.z;
|
|
167
|
+
const w = B * initial.w + A * final.w;
|
|
168
|
+
return new Quaternion(x, y, z, w);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Calculates a Quaternion from a rotation matrix
|
|
172
|
+
* @param rotationMatrix A normalized, non-scaled rotation matrix
|
|
173
|
+
* @returns The Quaterion
|
|
174
|
+
*/
|
|
175
|
+
static FromRotationMatrix(rotationMatrix) {
|
|
176
|
+
const m = rotationMatrix.m;
|
|
177
|
+
const m11 = m[0];
|
|
178
|
+
const m12 = m[4];
|
|
179
|
+
const m13 = m[8];
|
|
180
|
+
const m21 = m[1];
|
|
181
|
+
const m22 = m[5];
|
|
182
|
+
const m23 = m[9];
|
|
183
|
+
const m31 = m[2];
|
|
184
|
+
const m32 = m[6];
|
|
185
|
+
const m33 = m[10];
|
|
186
|
+
const trace = m11 + m22 + m33;
|
|
187
|
+
let s;
|
|
188
|
+
let x = 0;
|
|
189
|
+
let y = 0;
|
|
190
|
+
let z = 0;
|
|
191
|
+
let w = 0;
|
|
192
|
+
if (trace > 0) {
|
|
193
|
+
s = 0.5 / Math.sqrt(trace + 1.0);
|
|
194
|
+
w = 0.25 / s;
|
|
195
|
+
x = (m32 - m23) * s;
|
|
196
|
+
y = (m13 - m31) * s;
|
|
197
|
+
z = (m21 - m12) * s;
|
|
198
|
+
}
|
|
199
|
+
else if (m11 > m22 && m11 > m33) {
|
|
200
|
+
s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
|
|
201
|
+
w = (m32 - m23) / s;
|
|
202
|
+
x = 0.25 * s;
|
|
203
|
+
y = (m12 + m21) / s;
|
|
204
|
+
z = (m13 + m31) / s;
|
|
205
|
+
}
|
|
206
|
+
else if (m22 > m33) {
|
|
207
|
+
s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
|
|
208
|
+
w = (m13 - m31) / s;
|
|
209
|
+
x = (m12 + m21) / s;
|
|
210
|
+
y = 0.25 * s;
|
|
211
|
+
z = (m23 + m32) / s;
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
|
|
215
|
+
w = (m21 - m12) / s;
|
|
216
|
+
x = (m13 + m31) / s;
|
|
217
|
+
y = (m23 + m32) / s;
|
|
218
|
+
z = 0.25 * s;
|
|
219
|
+
}
|
|
220
|
+
return new Quaternion(x, y, z, w);
|
|
221
|
+
}
|
|
222
|
+
static ToRotationMatrix(quat) {
|
|
223
|
+
return Matrix_1.Matrix.Compose(Vector3_1.Vector3.One(), quat, Vector3_1.Vector3.Zero());
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Copy the quaternion to an array
|
|
227
|
+
* @returns an array populated with 4 elements from the quaternion coordinates
|
|
228
|
+
*/
|
|
229
|
+
toArray() {
|
|
230
|
+
return [this.x, this.y, this.z, this.w];
|
|
231
|
+
}
|
|
232
|
+
get angle() {
|
|
233
|
+
const angle = 2 * Math.acos(this.w);
|
|
234
|
+
return Angle_1.Angle.FromRadians(angle);
|
|
235
|
+
}
|
|
236
|
+
get axis() {
|
|
237
|
+
const x = this.x / Math.sqrt(1 - this.w * this.w);
|
|
238
|
+
const y = this.y / Math.sqrt(1 - this.w * this.w);
|
|
239
|
+
const z = this.z / Math.sqrt(1 - this.w * this.w);
|
|
240
|
+
return new Vector3_1.Vector3(x, y, z);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.Quaternion = Quaternion;
|
|
@@ -1,22 +1,104 @@
|
|
|
1
1
|
import { Angle } from ".";
|
|
2
2
|
export declare class Vector2 {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a zero vector
|
|
5
|
+
* @returns Vector [0,0]
|
|
6
|
+
*/
|
|
3
7
|
static Zero(): Vector2;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a one vector
|
|
10
|
+
* @returns Vector [1,1]
|
|
11
|
+
*/
|
|
4
12
|
static One(): Vector2;
|
|
13
|
+
/**
|
|
14
|
+
* Checks to see if Vector A equals Vector B
|
|
15
|
+
* @param a Vector A
|
|
16
|
+
* @param b Vector B
|
|
17
|
+
* @returns True if Vector A === Vector B
|
|
18
|
+
*/
|
|
5
19
|
static Equal(a: Vector2, b: Vector2): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Adds Vector B to Vector A
|
|
22
|
+
* @param a Vector A
|
|
23
|
+
* @param b Vector B
|
|
24
|
+
* @returns A + B
|
|
25
|
+
*/
|
|
6
26
|
static Add(a: Vector2, b: Vector2): Vector2;
|
|
27
|
+
/**
|
|
28
|
+
* Subtracts Vector B from Vector A
|
|
29
|
+
* @param a Vector A
|
|
30
|
+
* @param b Vector B
|
|
31
|
+
* @returns A - B
|
|
32
|
+
*/
|
|
7
33
|
static Subtract(a: Vector2, b: Vector2): Vector2;
|
|
34
|
+
/**
|
|
35
|
+
* Checks to see if Vector A is close to Vector B
|
|
36
|
+
* @param a Vector A
|
|
37
|
+
* @param b Vector B
|
|
38
|
+
* @param threshold Tolerance to define "close". Defaults to 0.01
|
|
39
|
+
* @returns True if A and B are close enough
|
|
40
|
+
*/
|
|
8
41
|
static Close: (a: Vector2, b: Vector2, threshold?: number) => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Rotates a vector by an angle
|
|
44
|
+
* @param vec The original vector
|
|
45
|
+
* @param angle The angle
|
|
46
|
+
* @returns A new Vector that has been rotated from the original by an angle
|
|
47
|
+
*/
|
|
9
48
|
static Rotate: (vec: Vector2, angle: Angle) => Vector2;
|
|
49
|
+
/**
|
|
50
|
+
* Scales a vector uniformly
|
|
51
|
+
* @param vector The original vector
|
|
52
|
+
* @param scale Scale factor
|
|
53
|
+
* @returns A new, scaled vector
|
|
54
|
+
*/
|
|
10
55
|
static Scale: (vector: Vector2, scale: number) => Vector2;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new vector of a given lenght and a unit that is equal to the original vector
|
|
58
|
+
* @param vector The original vector. This determines the unit of the final vector
|
|
59
|
+
* @param length The desired length of the final vector
|
|
60
|
+
* @returns The final vector
|
|
61
|
+
*/
|
|
11
62
|
static NewVectorOfLength: (vector: Vector2, length: number) => Vector2;
|
|
63
|
+
/**
|
|
64
|
+
* Calculate the dot product between Vectors A and B
|
|
65
|
+
* @param a Vector A
|
|
66
|
+
* @param b Vector B
|
|
67
|
+
* @returns The Dot product between A and B
|
|
68
|
+
*/
|
|
12
69
|
static Dot: (a: Vector2, b: Vector2) => number;
|
|
70
|
+
/**
|
|
71
|
+
* Calculates the dot product between Vectors A and B
|
|
72
|
+
* @param a Vector A
|
|
73
|
+
* @param b Vector B
|
|
74
|
+
* @returns A . B
|
|
75
|
+
*/
|
|
13
76
|
static AngleBetween: (a: Vector2, b: Vector2) => Angle;
|
|
77
|
+
/**
|
|
78
|
+
* Calculates the Cross product between Vectors A and B
|
|
79
|
+
* @param a Vector A
|
|
80
|
+
* @param b Vector B
|
|
81
|
+
* @returns A X B
|
|
82
|
+
*/
|
|
14
83
|
static Cross: (a: Vector2, b: Vector2) => number;
|
|
15
84
|
readonly x: number;
|
|
16
85
|
readonly y: number;
|
|
86
|
+
/**
|
|
87
|
+
* Get the magnitude (length) of the vector
|
|
88
|
+
*/
|
|
17
89
|
get magnitued(): number;
|
|
90
|
+
/**
|
|
91
|
+
* Get the unit vector
|
|
92
|
+
*/
|
|
18
93
|
get unit(): Vector2;
|
|
94
|
+
/**
|
|
95
|
+
* Returns the angle of the direction of this angle in degrees.
|
|
96
|
+
* A right vector [1,0] will return 0, a left vector [-1,0] will return 180, an up vector [0,1] will return 90 and a down vector [0,-1] will return -90
|
|
97
|
+
*/
|
|
19
98
|
get theta(): number;
|
|
99
|
+
/**
|
|
100
|
+
* Retuns the vector as an array of numbers [x,y]
|
|
101
|
+
*/
|
|
20
102
|
get array(): [number, number];
|
|
21
103
|
constructor(x: number, y: number);
|
|
22
104
|
}
|
|
@@ -7,12 +7,26 @@ class Vector2 {
|
|
|
7
7
|
this.x = x;
|
|
8
8
|
this.y = y;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates a zero vector
|
|
12
|
+
* @returns Vector [0,0]
|
|
13
|
+
*/
|
|
10
14
|
static Zero() {
|
|
11
15
|
return new Vector2(0, 0);
|
|
12
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a one vector
|
|
19
|
+
* @returns Vector [1,1]
|
|
20
|
+
*/
|
|
13
21
|
static One() {
|
|
14
22
|
return new Vector2(1, 1);
|
|
15
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Checks to see if Vector A equals Vector B
|
|
26
|
+
* @param a Vector A
|
|
27
|
+
* @param b Vector B
|
|
28
|
+
* @returns True if Vector A === Vector B
|
|
29
|
+
*/
|
|
16
30
|
static Equal(a, b) {
|
|
17
31
|
if (a.x !== b.x)
|
|
18
32
|
return false;
|
|
@@ -20,18 +34,36 @@ class Vector2 {
|
|
|
20
34
|
return false;
|
|
21
35
|
return true;
|
|
22
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Adds Vector B to Vector A
|
|
39
|
+
* @param a Vector A
|
|
40
|
+
* @param b Vector B
|
|
41
|
+
* @returns A + B
|
|
42
|
+
*/
|
|
23
43
|
static Add(a, b) {
|
|
24
44
|
return new Vector2(a.x + b.x, a.y + b.y);
|
|
25
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Subtracts Vector B from Vector A
|
|
48
|
+
* @param a Vector A
|
|
49
|
+
* @param b Vector B
|
|
50
|
+
* @returns A - B
|
|
51
|
+
*/
|
|
26
52
|
static Subtract(a, b) {
|
|
27
53
|
return new Vector2(a.x - b.x, a.y - b.y);
|
|
28
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Get the magnitude (length) of the vector
|
|
57
|
+
*/
|
|
29
58
|
get magnitued() {
|
|
30
59
|
const xSqr = this.x * this.x;
|
|
31
60
|
const ySqr = this.y * this.y;
|
|
32
61
|
const magnitude = Math.sqrt(xSqr + ySqr);
|
|
33
62
|
return magnitude;
|
|
34
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the unit vector
|
|
66
|
+
*/
|
|
35
67
|
get unit() {
|
|
36
68
|
const mag = this.magnitued;
|
|
37
69
|
if (mag === 0) {
|
|
@@ -41,14 +73,28 @@ class Vector2 {
|
|
|
41
73
|
const unitY = this.y / mag;
|
|
42
74
|
return new Vector2(unitX, unitY);
|
|
43
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns the angle of the direction of this angle in degrees.
|
|
78
|
+
* A right vector [1,0] will return 0, a left vector [-1,0] will return 180, an up vector [0,1] will return 90 and a down vector [0,-1] will return -90
|
|
79
|
+
*/
|
|
44
80
|
get theta() {
|
|
45
81
|
return (Math.atan2(this.y, this.x) * 180) / Math.PI;
|
|
46
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Retuns the vector as an array of numbers [x,y]
|
|
85
|
+
*/
|
|
47
86
|
get array() {
|
|
48
87
|
return [this.x, this.y];
|
|
49
88
|
}
|
|
50
89
|
}
|
|
51
90
|
exports.Vector2 = Vector2;
|
|
91
|
+
/**
|
|
92
|
+
* Checks to see if Vector A is close to Vector B
|
|
93
|
+
* @param a Vector A
|
|
94
|
+
* @param b Vector B
|
|
95
|
+
* @param threshold Tolerance to define "close". Defaults to 0.01
|
|
96
|
+
* @returns True if A and B are close enough
|
|
97
|
+
*/
|
|
52
98
|
Vector2.Close = (a, b, threshold = 0.01) => {
|
|
53
99
|
const diff = Vector2.Subtract(a, b);
|
|
54
100
|
const diffMag = diff.magnitued;
|
|
@@ -57,31 +103,67 @@ Vector2.Close = (a, b, threshold = 0.01) => {
|
|
|
57
103
|
else
|
|
58
104
|
return false;
|
|
59
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* Rotates a vector by an angle
|
|
108
|
+
* @param vec The original vector
|
|
109
|
+
* @param angle The angle
|
|
110
|
+
* @returns A new Vector that has been rotated from the original by an angle
|
|
111
|
+
*/
|
|
60
112
|
Vector2.Rotate = (vec, angle) => {
|
|
61
113
|
const x = vec.x * Math.cos(angle.radians) - vec.y * Math.sin(angle.radians);
|
|
62
114
|
const y = vec.x * Math.sin(angle.radians) + vec.y * Math.cos(angle.radians);
|
|
63
115
|
return new Vector2(x, y);
|
|
64
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* Scales a vector uniformly
|
|
119
|
+
* @param vector The original vector
|
|
120
|
+
* @param scale Scale factor
|
|
121
|
+
* @returns A new, scaled vector
|
|
122
|
+
*/
|
|
65
123
|
Vector2.Scale = (vector, scale) => {
|
|
66
124
|
const x = scale * vector.x;
|
|
67
125
|
const y = scale * vector.y;
|
|
68
126
|
return new Vector2(x, y);
|
|
69
127
|
};
|
|
128
|
+
/**
|
|
129
|
+
* Creates a new vector of a given lenght and a unit that is equal to the original vector
|
|
130
|
+
* @param vector The original vector. This determines the unit of the final vector
|
|
131
|
+
* @param length The desired length of the final vector
|
|
132
|
+
* @returns The final vector
|
|
133
|
+
*/
|
|
70
134
|
Vector2.NewVectorOfLength = (vector, length) => {
|
|
71
135
|
const unit = vector.unit;
|
|
72
136
|
const x = length * unit.x;
|
|
73
137
|
const y = length * unit.y;
|
|
74
138
|
return new Vector2(x, y);
|
|
75
139
|
};
|
|
140
|
+
/**
|
|
141
|
+
* Calculate the dot product between Vectors A and B
|
|
142
|
+
* @param a Vector A
|
|
143
|
+
* @param b Vector B
|
|
144
|
+
* @returns The Dot product between A and B
|
|
145
|
+
*/
|
|
76
146
|
Vector2.Dot = (a, b) => {
|
|
77
147
|
return a.x * b.x + a.y * b.y;
|
|
78
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* Calculates the dot product between Vectors A and B
|
|
151
|
+
* @param a Vector A
|
|
152
|
+
* @param b Vector B
|
|
153
|
+
* @returns A . B
|
|
154
|
+
*/
|
|
79
155
|
Vector2.AngleBetween = (a, b) => {
|
|
80
156
|
const dot = Vector2.Dot(a, b);
|
|
81
157
|
const magnitues = a.magnitued * b.magnitued;
|
|
82
158
|
const angRadians = Math.acos(dot / magnitues);
|
|
83
159
|
return _1.Angle.FromRadians(angRadians);
|
|
84
160
|
};
|
|
161
|
+
/**
|
|
162
|
+
* Calculates the Cross product between Vectors A and B
|
|
163
|
+
* @param a Vector A
|
|
164
|
+
* @param b Vector B
|
|
165
|
+
* @returns A X B
|
|
166
|
+
*/
|
|
85
167
|
Vector2.Cross = (a, b) => {
|
|
86
168
|
return a.x * b.y - a.y * b.x;
|
|
87
169
|
};
|
|
@@ -1,26 +1,133 @@
|
|
|
1
|
+
import { Matrix } from "./Matrix";
|
|
1
2
|
export declare class Vector3 {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a zero vector
|
|
5
|
+
* @returns Vector [0,0,0]
|
|
6
|
+
*/
|
|
2
7
|
static Zero(): Vector3;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a vector of ones
|
|
10
|
+
* @returns Vector [1,1,1]
|
|
11
|
+
*/
|
|
3
12
|
static One(): Vector3;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a Right vector (positive X)
|
|
15
|
+
* @param length optional length of the right unit. Default is 1
|
|
16
|
+
* @returns Vector [length, 0,0]
|
|
17
|
+
*/
|
|
4
18
|
static Right(length?: number): Vector3;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a Left vector (negative X)
|
|
21
|
+
* @param length optional length of the left unit. Default is 1
|
|
22
|
+
* @returns Vector [-length, 0, 0]
|
|
23
|
+
*/
|
|
5
24
|
static Left(length?: number): Vector3;
|
|
25
|
+
/**
|
|
26
|
+
* Creates an Up vector (positive Y)
|
|
27
|
+
* @param length optional length of the vector. Default is 1
|
|
28
|
+
* @returns Vector [0, length, 0]
|
|
29
|
+
*/
|
|
6
30
|
static Up(length?: number): Vector3;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a Down vector (negative Y)
|
|
33
|
+
* @param length optional length of the vector. Default is 1
|
|
34
|
+
* @returns Vector [0, -length, 0]
|
|
35
|
+
*/
|
|
7
36
|
static Down(length?: number): Vector3;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a Forward vector (positive Z)
|
|
39
|
+
* @param length optional length of the vector. Default is 1
|
|
40
|
+
* @returns Vector [0, 0, length]
|
|
41
|
+
*/
|
|
8
42
|
static Forward(length?: number): Vector3;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a Backward vector (negative Z)
|
|
45
|
+
* @param length optional length of the vector. Default is 1
|
|
46
|
+
* @returns Vector [0, 0, -length]
|
|
47
|
+
*/
|
|
9
48
|
static Backward(length?: number): Vector3;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a Vector from an array of components
|
|
51
|
+
* @param values The x, y, z components as an array
|
|
52
|
+
* @returns The Vector
|
|
53
|
+
*/
|
|
10
54
|
static FromArray(values: [number, number, number]): Vector3;
|
|
55
|
+
/**
|
|
56
|
+
* Adds Vector B to Vector A
|
|
57
|
+
* @param a Vector A
|
|
58
|
+
* @param b Vector B
|
|
59
|
+
* @return Result of A + B
|
|
60
|
+
*/
|
|
11
61
|
static Add: (a: Vector3, b: Vector3) => Vector3;
|
|
62
|
+
/**
|
|
63
|
+
* Subtracts Vector B from Vector A
|
|
64
|
+
* @param a Vector A
|
|
65
|
+
* @param b Vector B
|
|
66
|
+
* @return Result of A - B
|
|
67
|
+
*/
|
|
12
68
|
static Subtract: (a: Vector3, b: Vector3) => Vector3;
|
|
69
|
+
/**
|
|
70
|
+
* Checks to see if the two vectors are equal
|
|
71
|
+
* @param a Vector A
|
|
72
|
+
* @param b Vector B
|
|
73
|
+
* @return True if the two vectors are equal, otherwise false
|
|
74
|
+
*/
|
|
13
75
|
static Equal: (a: Vector3, b: Vector3) => boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Checks to see if the two vectors are close
|
|
78
|
+
* @param a Vector A
|
|
79
|
+
* @param b Vector B
|
|
80
|
+
* @param tolerance Tolerance for checking. Defaulted to 0.01
|
|
81
|
+
* @return True if the distance between the two vectors is less than the tolerance, otherwise false
|
|
82
|
+
*/
|
|
14
83
|
static Close: (a: Vector3, b: Vector3, tolerance?: number) => boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Calculates the Cross Product between two vectors
|
|
86
|
+
* @param a Vector A
|
|
87
|
+
* @param b Vector B
|
|
88
|
+
* @return the cross product between the two vectors
|
|
89
|
+
*/
|
|
15
90
|
static Cross: (a: Vector3, b: Vector3) => Vector3;
|
|
91
|
+
/**
|
|
92
|
+
* Calculates the Dot Product between two vectors
|
|
93
|
+
* @param a Vector A
|
|
94
|
+
* @param b Vector B
|
|
95
|
+
* @return the dot product between the two vectors
|
|
96
|
+
*/
|
|
16
97
|
static Dot: (a: Vector3, b: Vector3) => number;
|
|
98
|
+
/**
|
|
99
|
+
* Create a new vector that will have the same unit as the original vector but set to the desired length
|
|
100
|
+
* @param vec The original vector
|
|
101
|
+
* @param length Desired lenght of the final vector
|
|
102
|
+
* @return The resulting vector
|
|
103
|
+
*/
|
|
17
104
|
static NewVectorOfLength: (vec: Vector3, length: number) => Vector3;
|
|
105
|
+
static Transform: (vector: Vector3, matrix: Matrix) => Vector3;
|
|
106
|
+
/**
|
|
107
|
+
* Linearly inerpolates between two vectors
|
|
108
|
+
* @param initial The starting point
|
|
109
|
+
* @param final The end point
|
|
110
|
+
* @param percent Percent of the lerp. 0 will return initial and 1 will return final
|
|
111
|
+
* @return the LERP result Vector3
|
|
112
|
+
*/
|
|
18
113
|
static Lerp: (initial: Vector3, final: Vector3, percent: number) => Vector3;
|
|
19
114
|
readonly x: number;
|
|
20
115
|
readonly y: number;
|
|
21
116
|
readonly z: number;
|
|
117
|
+
/**
|
|
118
|
+
* Gets the magnitude of the Vector3
|
|
119
|
+
* @returns the magnitude of the Vector3
|
|
120
|
+
*/
|
|
22
121
|
get magnitued(): number;
|
|
122
|
+
/**
|
|
123
|
+
* Gets the unit vector for this Vector3
|
|
124
|
+
* @returns the unit vector
|
|
125
|
+
*/
|
|
23
126
|
get unit(): Vector3;
|
|
127
|
+
/**
|
|
128
|
+
* Gets the vector as an array
|
|
129
|
+
* @returns an array representing the vector
|
|
130
|
+
*/
|
|
24
131
|
get array(): [number, number, number];
|
|
25
132
|
constructor(x: number, y: number, z: number);
|
|
26
133
|
}
|