@openglobus/og 0.11.1 → 0.11.6
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/package.json +18 -20
- package/src/og/Clock.js +11 -11
- package/src/og/Deferred.js +1 -1
- package/src/og/Events.js +9 -7
- package/src/og/Extent.js +117 -72
- package/src/og/Globe.js +35 -22
- package/src/og/ImageCanvas.js +24 -18
- package/src/og/Lock.js +2 -2
- package/src/og/LonLat.js +40 -37
- package/src/og/Popup.js +21 -15
- package/src/og/QueueArray.js +7 -3
- package/src/og/Rectangle.js +11 -6
- package/src/og/Stack.js +8 -5
- package/src/og/ajax.js +21 -33
- package/src/og/astro/astro.js +5 -5
- package/src/og/astro/earth.js +23 -17
- package/src/og/astro/jd.js +44 -39
- package/src/og/astro/orbit.js +20 -18
- package/src/og/astro/rotation.js +17 -8
- package/src/og/bv/Box.js +7 -3
- package/src/og/bv/Sphere.js +17 -9
- package/src/og/camera/Camera.js +137 -86
- package/src/og/camera/Frustum.js +30 -19
- package/src/og/camera/PlanetCamera.js +30 -26
- package/src/og/control/CompassButton.js +8 -2
- package/src/og/control/Control.js +13 -11
- package/src/og/control/DebugInfo.js +4 -1
- package/src/og/control/EarthCoordinates.js +62 -41
- package/src/og/control/EarthNavigation.js +20 -22
- package/src/og/control/GeoImageDragControl.js +1 -1
- package/src/og/control/KeyboardNavigation.js +12 -12
- package/src/og/control/LayerSwitcher.js +24 -23
- package/src/og/control/Lighting.js +1 -1
- package/src/og/control/MouseNavigation.js +1 -1
- package/src/og/control/ScaleControl.js +1 -1
- package/src/og/control/SegmentBoundVisualization.js +8 -9
- package/src/og/control/ShowFps.js +15 -10
- package/src/og/control/SimpleNavigation.js +8 -10
- package/src/og/control/Sun.js +25 -15
- package/src/og/control/ToggleWireframe.js +5 -5
- package/src/og/control/TouchNavigation.js +58 -45
- package/src/og/control/ZoomControl.js +41 -25
- package/src/og/control/index.js +4 -0
- package/src/og/ellipsoid/Ellipsoid.js +181 -85
- package/src/og/ellipsoid/wgs84.js +4 -4
- package/src/og/entity/BaseBillboard.js +97 -44
- package/src/og/entity/Billboard.js +15 -11
- package/src/og/entity/BillboardHandler.js +314 -64
- package/src/og/entity/Entity.js +106 -74
- package/src/og/entity/EntityCollection.js +72 -49
- package/src/og/entity/GeoObject.js +228 -0
- package/src/og/entity/GeoObjectHandler.js +910 -0
- package/src/og/entity/Geometry.js +29 -26
- package/src/og/entity/GeometryHandler.js +598 -126
- package/src/og/entity/Label.js +74 -40
- package/src/og/entity/LabelHandler.js +47 -246
- package/src/og/entity/LabelWorker.js +213 -0
- package/src/og/entity/Object3d.js +504 -0
- package/src/og/entity/PointCloud.js +81 -33
- package/src/og/entity/PointCloudHandler.js +9 -9
- package/src/og/entity/Polyline.js +39 -39
- package/src/og/entity/Ray.js +61 -28
- package/src/og/entity/ShapeHandler.js +1 -1
- package/src/og/entity/Strip.js +77 -48
- package/src/og/entity/StripHandler.js +27 -27
- package/src/og/entity/index.js +8 -16
- package/src/og/input/KeyboardHandler.js +107 -104
- package/src/og/input/MouseHandler.js +81 -78
- package/src/og/input/TouchHandler.js +55 -51
- package/src/og/layer/BaseGeoImage.js +61 -30
- package/src/og/layer/CanvasTiles.js +26 -24
- package/src/og/layer/GeoImage.js +10 -10
- package/src/og/layer/GeoTexture2d.js +1 -1
- package/src/og/layer/GeoVideo.js +3 -3
- package/src/og/layer/KML.js +66 -40
- package/src/og/layer/Layer.js +27 -17
- package/src/og/layer/Material.js +93 -61
- package/src/og/layer/Vector.js +118 -72
- package/src/og/layer/WMS.js +36 -19
- package/src/og/layer/XYZ.js +55 -48
- package/src/og/light/LightSource.js +47 -40
- package/src/og/math/Line2.js +24 -24
- package/src/og/math/Line3.js +103 -102
- package/src/og/math/Mat3.js +134 -121
- package/src/og/math/Mat4.js +603 -459
- package/src/og/math/Plane.js +21 -20
- package/src/og/math/Quat.js +980 -927
- package/src/og/math/Ray.js +195 -187
- package/src/og/math/Vec2.js +127 -117
- package/src/og/math/Vec3.js +206 -176
- package/src/og/math/Vec4.js +49 -53
- package/src/og/math/coder.js +18 -18
- package/src/og/math.js +12 -12
- package/src/og/mercator.js +11 -11
- package/src/og/proj/EPSG3857.js +4 -4
- package/src/og/proj/EPSG4326.js +4 -4
- package/src/og/proj/Proj.js +31 -31
- package/src/og/quadTree/EntityCollectionNode.js +310 -300
- package/src/og/quadTree/Node.js +1008 -993
- package/src/og/renderer/Renderer.js +768 -747
- package/src/og/renderer/RendererEvents.js +9 -6
- package/src/og/scene/Axes.js +1 -1
- package/src/og/scene/BaseNode.js +8 -9
- package/src/og/scene/Planet.js +115 -87
- package/src/og/scene/RenderNode.js +29 -22
- package/src/og/scene/SkyBox.js +1 -1
- package/src/og/segment/Segment.js +1886 -1878
- package/src/og/segment/SegmentLonLat.js +298 -268
- package/src/og/segment/segmentHelper.js +11 -11
- package/src/og/shaders/bloom.js +1 -1
- package/src/og/shaders/blur.js +2 -2
- package/src/og/shaders/depth.js +1 -1
- package/src/og/shaders/geoObject.js +211 -0
- package/src/og/shaders/label.js +1 -1
- package/src/og/shaders/lumFilter.js +1 -1
- package/src/og/shaders/pointCloud.js +42 -42
- package/src/og/shaders/screenFrame.js +1 -1
- package/src/og/shaders/shape.js +15 -21
- package/src/og/shaders/skybox.js +37 -37
- package/src/og/shaders/toneMapping.js +1 -1
- package/src/og/shapes/BaseShape.js +129 -57
- package/src/og/shapes/Icosphere.js +30 -15
- package/src/og/shapes/Sphere.js +13 -16
- package/src/og/terrain/BilTerrain.js +2 -1
- package/src/og/terrain/EmptyTerrain.js +2 -2
- package/src/og/terrain/Geoid.js +2 -2
- package/src/og/terrain/GlobusTerrain.js +10 -10
- package/src/og/terrain/MapboxTerrain.js +1 -1
- package/src/og/utils/GeoImageCreator.js +9 -9
- package/src/og/utils/Loader.js +6 -6
- package/src/og/utils/NormalMapCreator.js +13 -13
- package/src/og/utils/TerrainWorker.js +1 -1
- package/src/og/utils/TextureAtlas.js +20 -22
- package/src/og/utils/VectorTileCreator.js +5 -5
- package/src/og/utils/earcut.js +1 -1
- package/src/og/utils/shared.js +15 -15
- package/src/og/webgl/Framebuffer.js +101 -53
- package/src/og/webgl/Handler.js +125 -85
- package/src/og/webgl/Multisample.js +55 -27
- package/src/og/webgl/Program.js +80 -35
- package/src/og/webgl/ProgramController.js +27 -23
- package/src/og/webgl/callbacks.js +8 -8
- package/types/Clock.d.ts +6 -2
- package/types/Deferred.d.ts +1 -1
- package/types/Events.d.ts +8 -4
- package/types/Extent.d.ts +37 -33
- package/types/Globe.d.ts +15 -13
- package/types/ImageCanvas.d.ts +5 -3
- package/types/LonLat.d.ts +24 -24
- package/types/Popup.d.ts +4 -0
- package/types/QueueArray.d.ts +6 -2
- package/types/Rectangle.d.ts +10 -4
- package/types/Stack.d.ts +4 -0
- package/types/ajax.d.ts +1 -1
- package/types/astro/earth.d.ts +3 -2
- package/types/bv/Box.d.ts +10 -5
- package/types/bv/Sphere.d.ts +13 -7
- package/types/camera/Camera.d.ts +90 -81
- package/types/camera/Frustum.d.ts +26 -22
- package/types/camera/PlanetCamera.d.ts +49 -53
- package/types/control/CompassButton.d.ts +4 -4
- package/types/control/Control.d.ts +7 -4
- package/types/control/DebugInfo.d.ts +3 -4
- package/types/control/EarthCoordinates.d.ts +6 -6
- package/types/control/EarthNavigation.d.ts +42 -0
- package/types/control/KeyboardNavigation.d.ts +3 -4
- package/types/control/LayerSwitcher.d.ts +3 -5
- package/types/control/Lighting.d.ts +3 -3
- package/types/control/MouseNavigation.d.ts +47 -0
- package/types/control/ScaleControl.d.ts +3 -3
- package/types/control/ShowFps.d.ts +3 -4
- package/types/control/SimpleNavigation.d.ts +3 -6
- package/types/control/Sun.d.ts +8 -10
- package/types/control/ToggleWireframe.d.ts +3 -3
- package/types/control/TouchNavigation.d.ts +48 -0
- package/types/control/ZoomControl.d.ts +3 -4
- package/types/control/index.d.ts +3 -1
- package/types/ellipsoid/Ellipsoid.d.ts +47 -43
- package/types/ellipsoid/wgs84.d.ts +3 -2
- package/types/entity/BaseBillboard.d.ts +41 -34
- package/types/entity/Billboard.d.ts +7 -7
- package/types/entity/BillboardHandler.d.ts +4 -0
- package/types/entity/Entity.d.ts +101 -83
- package/types/entity/EntityCollection.d.ts +57 -43
- package/types/entity/GeoObject.d.ts +111 -0
- package/types/entity/GeoObjectHandler.d.ts +77 -0
- package/types/entity/Geometry.d.ts +9 -7
- package/types/entity/GeometryHandler.d.ts +2 -2
- package/types/entity/Label.d.ts +24 -29
- package/types/entity/LabelHandler.d.ts +9 -2
- package/types/entity/LabelWorker.d.ts +9 -0
- package/types/entity/PointCloud.d.ts +8 -8
- package/types/entity/PointCloudHandler.d.ts +3 -3
- package/types/entity/Polyline.d.ts +58 -55
- package/types/entity/Ray.d.ts +19 -18
- package/types/entity/Strip.d.ts +8 -7
- package/types/entity/StripHandler.d.ts +3 -3
- package/types/entity/index.d.ts +7 -7
- package/types/input/KeyboardHandler.d.ts +10 -0
- package/types/input/MouseHandler.d.ts +5 -0
- package/types/input/TouchHandler.d.ts +5 -0
- package/types/layer/BaseGeoImage.d.ts +23 -35
- package/types/layer/CanvasTiles.d.ts +15 -22
- package/types/layer/GeoImage.d.ts +5 -18
- package/types/layer/GeoVideo.d.ts +5 -30
- package/types/layer/KML.d.ts +20 -15
- package/types/layer/Layer.d.ts +326 -0
- package/types/layer/Material.d.ts +45 -0
- package/types/layer/Vector.d.ts +208 -0
- package/types/layer/WMS.d.ts +4 -7
- package/types/layer/XYZ.d.ts +19 -25
- package/types/light/LightSource.d.ts +54 -53
- package/types/math/Line2.d.ts +11 -0
- package/types/math/Line3.d.ts +10 -0
- package/types/math/Mat3.d.ts +30 -18
- package/types/math/Mat4.d.ts +71 -52
- package/types/math/Plane.d.ts +5 -4
- package/types/math/Quat.d.ts +379 -0
- package/types/math/Ray.d.ts +82 -0
- package/types/math/Vec2.d.ts +102 -101
- package/types/math/Vec3.d.ts +143 -142
- package/types/math/Vec4.d.ts +40 -39
- package/types/math/coder.d.ts +12 -11
- package/types/math.d.ts +8 -8
- package/types/mercator.d.ts +3 -3
- package/types/proj/EPSG3857.d.ts +3 -2
- package/types/proj/EPSG4326.d.ts +3 -2
- package/types/proj/Proj.d.ts +42 -0
- package/types/quadTree/EntityCollectionNode.d.ts +34 -0
- package/types/quadTree/Node.d.ts +61 -0
- package/types/renderer/Renderer.d.ts +300 -0
- package/types/renderer/RendererEvents.d.ts +10 -7
- package/types/scene/BaseNode.d.ts +9 -9
- package/types/scene/Planet.d.ts +131 -126
- package/types/scene/RenderNode.d.ts +22 -23
- package/types/segment/Segment.d.ts +279 -0
- package/types/segment/SegmentLonLat.d.ts +16 -0
- package/types/shaders/geoObject.d.ts +3 -0
- package/types/shapes/BaseShape.d.ts +43 -40
- package/types/shapes/Sphere.d.ts +7 -7
- package/types/terrain/BilTerrain.d.ts +0 -1
- package/types/terrain/EmptyTerrain.d.ts +4 -4
- package/types/terrain/GlobusTerrain.d.ts +17 -54
- package/types/terrain/MapboxTerrain.d.ts +0 -1
- package/types/utils/GeoImageCreator.d.ts +3 -2
- package/types/utils/TextureAtlas.d.ts +8 -8
- package/types/utils/shared.d.ts +25 -24
- package/types/webgl/Framebuffer.d.ts +5 -5
- package/types/webgl/Handler.d.ts +68 -43
- package/types/webgl/Multisample.d.ts +5 -5
- package/types/webgl/Program.d.ts +8 -2
- package/types/webgl/ProgramController.d.ts +18 -13
- package/src/og/inherits.js +0 -8
- package/src/og/utils/polylabel.js +0 -176
- package/types/inherits.d.ts +0 -4
package/src/og/math/Vec3.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* @module og/math/Vec3
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
"use strict";
|
|
6
6
|
|
|
7
|
-
import { Vec4 } from
|
|
8
|
-
import { Quat } from
|
|
7
|
+
import { Vec4 } from "./Vec4.js";
|
|
8
|
+
import { Quat } from "./Quat.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Class represents a 3d vector.
|
|
@@ -15,9 +15,7 @@ import { Quat } from './Quat.js';
|
|
|
15
15
|
* @param {number} [z] - Third value.
|
|
16
16
|
*/
|
|
17
17
|
export class Vec3 {
|
|
18
|
-
|
|
19
18
|
constructor(x, y, z) {
|
|
20
|
-
|
|
21
19
|
/**
|
|
22
20
|
* @public
|
|
23
21
|
* @type {number}
|
|
@@ -35,28 +33,48 @@ export class Vec3 {
|
|
|
35
33
|
* @type {number}
|
|
36
34
|
*/
|
|
37
35
|
this.z = z || 0.0;
|
|
38
|
-
}
|
|
36
|
+
}
|
|
39
37
|
|
|
40
38
|
/** @const */
|
|
41
|
-
static get UP() {
|
|
39
|
+
static get UP() {
|
|
40
|
+
return new Vec3(0, 1, 0);
|
|
41
|
+
}
|
|
42
42
|
/** @const */
|
|
43
|
-
static get DOWN() {
|
|
43
|
+
static get DOWN() {
|
|
44
|
+
return new Vec3(0, -1, 0);
|
|
45
|
+
}
|
|
44
46
|
/** @const */
|
|
45
|
-
static get RIGHT() {
|
|
47
|
+
static get RIGHT() {
|
|
48
|
+
return new Vec3(1, 0, 0);
|
|
49
|
+
}
|
|
46
50
|
/** @const */
|
|
47
|
-
static get LEFT() {
|
|
51
|
+
static get LEFT() {
|
|
52
|
+
return new Vec3(-1, 0, 0);
|
|
53
|
+
}
|
|
48
54
|
/** @const */
|
|
49
|
-
static get FORWARD() {
|
|
55
|
+
static get FORWARD() {
|
|
56
|
+
return new Vec3(0, 0, -1);
|
|
57
|
+
}
|
|
50
58
|
/** @const */
|
|
51
|
-
static get BACKWARD() {
|
|
59
|
+
static get BACKWARD() {
|
|
60
|
+
return new Vec3(0, 0, 1);
|
|
61
|
+
}
|
|
52
62
|
/** @const */
|
|
53
|
-
static get ZERO() {
|
|
63
|
+
static get ZERO() {
|
|
64
|
+
return new Vec3();
|
|
65
|
+
}
|
|
54
66
|
/** @const */
|
|
55
|
-
static get UNIT_X() {
|
|
67
|
+
static get UNIT_X() {
|
|
68
|
+
return new Vec3(1, 0, 0);
|
|
69
|
+
}
|
|
56
70
|
/** @const */
|
|
57
|
-
static get UNIT_Y() {
|
|
71
|
+
static get UNIT_Y() {
|
|
72
|
+
return new Vec3(0, 1, 0);
|
|
73
|
+
}
|
|
58
74
|
/** @const */
|
|
59
|
-
static get UNIT_Z() {
|
|
75
|
+
static get UNIT_Z() {
|
|
76
|
+
return new Vec3(0, 0, 1);
|
|
77
|
+
}
|
|
60
78
|
|
|
61
79
|
/**
|
|
62
80
|
* Separate 63 bit Vec3 to two Vec3 32 bit float values.
|
|
@@ -64,11 +82,12 @@ export class Vec3 {
|
|
|
64
82
|
* @param {number} value - Double type value.
|
|
65
83
|
* @param {Vec3} high - Out vector high values.
|
|
66
84
|
* @param {Vec3} low - Out vector low values.
|
|
67
|
-
* @returns {Array.<number
|
|
85
|
+
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
|
68
86
|
*/
|
|
69
87
|
static doubleToTwoFloats(v, high, low) {
|
|
70
|
-
|
|
71
|
-
|
|
88
|
+
let x = v.x,
|
|
89
|
+
y = v.y,
|
|
90
|
+
z = v.z;
|
|
72
91
|
|
|
73
92
|
if (x >= 0.0) {
|
|
74
93
|
let doubleHigh = Math.floor(x / 65536.0) * 65536.0;
|
|
@@ -99,7 +118,7 @@ export class Vec3 {
|
|
|
99
118
|
high.z = Math.fround(-doubleHigh);
|
|
100
119
|
low.z = Math.fround(z + doubleHigh);
|
|
101
120
|
}
|
|
102
|
-
}
|
|
121
|
+
}
|
|
103
122
|
|
|
104
123
|
/**
|
|
105
124
|
* Separate 63 bit Vec3 to two Vec3 32 bit float values.
|
|
@@ -107,11 +126,12 @@ export class Vec3 {
|
|
|
107
126
|
* @param {number} value - Double type value.
|
|
108
127
|
* @param {Float32Array} high - Out vector high values.
|
|
109
128
|
* @param {Float32Array} low - Out vector low values.
|
|
110
|
-
* @returns {Array.<number
|
|
129
|
+
* @returns {Array.<number>} Encoded array. (exactly 2 entries)
|
|
111
130
|
*/
|
|
112
131
|
static doubleToTwoFloat32Array(v, high, low) {
|
|
113
|
-
|
|
114
|
-
|
|
132
|
+
let x = v.x,
|
|
133
|
+
y = v.y,
|
|
134
|
+
z = v.z;
|
|
115
135
|
|
|
116
136
|
if (x >= 0.0) {
|
|
117
137
|
let doubleHigh = Math.floor(x / 65536.0) * 65536.0;
|
|
@@ -142,111 +162,111 @@ export class Vec3 {
|
|
|
142
162
|
high[2] = Math.fround(-doubleHigh);
|
|
143
163
|
low[2] = Math.fround(z + doubleHigh);
|
|
144
164
|
}
|
|
145
|
-
}
|
|
165
|
+
}
|
|
146
166
|
|
|
147
167
|
/**
|
|
148
168
|
* Creates 3d vector from array.
|
|
149
169
|
* @function
|
|
150
|
-
* @param {Array.<number
|
|
151
|
-
* @returns {
|
|
170
|
+
* @param {Array.<number>} arr - Input array (exactly 3 entries)
|
|
171
|
+
* @returns {Vec3} -
|
|
152
172
|
*/
|
|
153
173
|
static fromVec(arr) {
|
|
154
174
|
return new Vec3(arr[0], arr[1], arr[2]);
|
|
155
|
-
}
|
|
175
|
+
}
|
|
156
176
|
|
|
157
177
|
/**
|
|
158
178
|
* Gets angle between two vectors.
|
|
159
179
|
* @static
|
|
160
|
-
* @param {
|
|
161
|
-
* @param {
|
|
180
|
+
* @param {Vec3} a - First vector.
|
|
181
|
+
* @param {Vec3} b - Second vector.
|
|
162
182
|
* @returns {number} -
|
|
163
183
|
*/
|
|
164
184
|
static angle(a, b) {
|
|
165
185
|
return Math.acos(a.dot(b) / Math.sqrt(a.length2() * b.length2()));
|
|
166
|
-
}
|
|
186
|
+
}
|
|
167
187
|
|
|
168
188
|
/**
|
|
169
189
|
* Returns two vectors linear interpolation.
|
|
170
190
|
* @static
|
|
171
|
-
* @param {
|
|
172
|
-
* @param {
|
|
191
|
+
* @param {Vec3} v1 - Start vector.
|
|
192
|
+
* @param {Vec3} v2 - End vector.
|
|
173
193
|
* @param {number} l - Interpolate value.
|
|
174
|
-
* @returns {
|
|
194
|
+
* @returns {Vec3} -
|
|
175
195
|
*/
|
|
176
196
|
static lerp(v1, v2, l) {
|
|
177
197
|
return Vec3(v1.x + (v2.x - v1.x) * l, v1.y + (v2.y - v1.y) * l, v1.z + (v2.z - v1.z) * l);
|
|
178
|
-
}
|
|
198
|
+
}
|
|
179
199
|
|
|
180
200
|
/**
|
|
181
201
|
* Returns summary vector.
|
|
182
202
|
* @static
|
|
183
|
-
* @param {
|
|
184
|
-
* @param {
|
|
185
|
-
* @returns {
|
|
203
|
+
* @param {Vec3} a - First vector.
|
|
204
|
+
* @param {Vec3} b - Second vector.
|
|
205
|
+
* @returns {Vec3} - Summary vector.
|
|
186
206
|
*/
|
|
187
207
|
static add(a, b) {
|
|
188
208
|
var res = new Vec3(a.x, a.y, a.z);
|
|
189
209
|
res.addA(b);
|
|
190
210
|
return res;
|
|
191
|
-
}
|
|
211
|
+
}
|
|
192
212
|
|
|
193
213
|
/**
|
|
194
214
|
* Returns two vectors subtraction.
|
|
195
215
|
* @static
|
|
196
|
-
* @param {
|
|
197
|
-
* @param {
|
|
198
|
-
* @returns {
|
|
216
|
+
* @param {Vec3} a - First vector.
|
|
217
|
+
* @param {Vec3} b - Second vector.
|
|
218
|
+
* @returns {Vec3} - Vectors subtraction.
|
|
199
219
|
*/
|
|
200
220
|
static sub(a, b) {
|
|
201
221
|
var res = new Vec3(a.x, a.y, a.z);
|
|
202
222
|
res.subA(b);
|
|
203
223
|
return res;
|
|
204
|
-
}
|
|
224
|
+
}
|
|
205
225
|
|
|
206
226
|
/**
|
|
207
227
|
* Returns scaled vector.
|
|
208
228
|
* @static
|
|
209
|
-
* @param {
|
|
229
|
+
* @param {Vec3} a - Input vector.
|
|
210
230
|
* @param {number} scale - Scale value.
|
|
211
|
-
* @returns {
|
|
231
|
+
* @returns {Vec3} -
|
|
212
232
|
*/
|
|
213
233
|
static scale(a, scale) {
|
|
214
234
|
var res = new Vec3(a.x, a.y, a.z);
|
|
215
235
|
res.scale(scale);
|
|
216
236
|
return res;
|
|
217
|
-
}
|
|
237
|
+
}
|
|
218
238
|
|
|
219
239
|
/**
|
|
220
240
|
* Returns two vectors production.
|
|
221
241
|
* @static
|
|
222
|
-
* @param {
|
|
223
|
-
* @param {
|
|
224
|
-
* @returns {
|
|
242
|
+
* @param {Vec3} a - First vector.
|
|
243
|
+
* @param {Vec3} b - Second vector.
|
|
244
|
+
* @returns {Vec3} -
|
|
225
245
|
*/
|
|
226
246
|
static mul(a, b) {
|
|
227
247
|
var res = new Vec3(a.x, a.y, a.z);
|
|
228
248
|
res.mulA(b);
|
|
229
249
|
return res;
|
|
230
|
-
}
|
|
250
|
+
}
|
|
231
251
|
|
|
232
252
|
/**
|
|
233
253
|
* Returns true if two vectors are non collinear.
|
|
234
254
|
* @public
|
|
235
|
-
* @param {
|
|
236
|
-
* @param {
|
|
237
|
-
* @returns {
|
|
255
|
+
* @param {Vec3} a - First vector.
|
|
256
|
+
* @param {Vec3} b - Second vector.
|
|
257
|
+
* @returns {Vec3} -
|
|
238
258
|
*/
|
|
239
259
|
static noncollinear(a, b) {
|
|
240
260
|
return a.y * b.z - a.z * b.y || a.z * b.x - a.x * b.z || a.x * b.y - a.y * b.z;
|
|
241
|
-
}
|
|
261
|
+
}
|
|
242
262
|
|
|
243
263
|
/**
|
|
244
264
|
* Get projection of the vector to plane where n - normal to the plane.
|
|
245
265
|
* @static
|
|
246
|
-
* @param {
|
|
247
|
-
* @param {
|
|
248
|
-
|
|
249
|
-
* @returns {
|
|
266
|
+
* @param {Vec3} b - Vector to project.
|
|
267
|
+
* @param {Vec3} n - Plane normal.
|
|
268
|
+
* @param {Vec3} [def] - Default value for non existed result.
|
|
269
|
+
* @returns {Vec3} -
|
|
250
270
|
*/
|
|
251
271
|
static proj_b_to_plane(b, n, def) {
|
|
252
272
|
var res = b.sub(n.scaleTo(n.dot(b) / n.dot(n)));
|
|
@@ -254,63 +274,63 @@ export class Vec3 {
|
|
|
254
274
|
return new Vec3(def.x, def.y, def.z);
|
|
255
275
|
}
|
|
256
276
|
return res;
|
|
257
|
-
}
|
|
277
|
+
}
|
|
258
278
|
|
|
259
279
|
/**
|
|
260
280
|
* Get projection of the first vector to the second.
|
|
261
281
|
* @static
|
|
262
|
-
* @param {
|
|
263
|
-
* @param {
|
|
264
|
-
* @returns {
|
|
282
|
+
* @param {Vec3} b - First vector.
|
|
283
|
+
* @param {Vec3} a - Second vector.
|
|
284
|
+
* @returns {Vec3} -
|
|
265
285
|
*/
|
|
266
286
|
static proj_b_to_a(b, a) {
|
|
267
287
|
return a.scaleTo(a.dot(b) / a.dot(a));
|
|
268
|
-
}
|
|
288
|
+
}
|
|
269
289
|
|
|
270
290
|
/**
|
|
271
291
|
* Makes vectors normalized and orthogonal to each other.
|
|
272
292
|
* Normalizes normal. Normalizes tangent and makes sure it is orthogonal to normal (that is, angle between them is 90 degrees).
|
|
273
293
|
* @static
|
|
274
|
-
* @param {
|
|
275
|
-
* @param {
|
|
276
|
-
* @returns {
|
|
294
|
+
* @param {Vec3} normal - Normal vector.
|
|
295
|
+
* @param {Vec3} tangent - Tangent vector.
|
|
296
|
+
* @returns {Vec3} -
|
|
277
297
|
*/
|
|
278
298
|
static orthoNormalize(normal, tangent) {
|
|
279
299
|
normal = normal.normal();
|
|
280
300
|
normal.scale(tangent.dot(normal));
|
|
281
301
|
return tangent.subA(normal).normalize();
|
|
282
|
-
}
|
|
302
|
+
}
|
|
283
303
|
|
|
284
304
|
/**
|
|
285
305
|
* Returns vector components division product one to another.
|
|
286
306
|
* @static
|
|
287
|
-
* @param {
|
|
288
|
-
* @param {
|
|
289
|
-
* @returns {
|
|
307
|
+
* @param {Vec3} a - First vector.
|
|
308
|
+
* @param {Vec3} b - Second vector.
|
|
309
|
+
* @returns {Vec3} -
|
|
290
310
|
*/
|
|
291
311
|
static div(a, b) {
|
|
292
312
|
var res = new Vec3(a.x, a.y, a.z);
|
|
293
313
|
res.divA(b);
|
|
294
314
|
return res;
|
|
295
|
-
}
|
|
315
|
+
}
|
|
296
316
|
|
|
297
317
|
/**
|
|
298
318
|
* Converts to 4d vector, Fourth value is 1.0.
|
|
299
319
|
* @public
|
|
300
|
-
* @returns {
|
|
320
|
+
* @returns {Vec4} -
|
|
301
321
|
*/
|
|
302
322
|
toVec4() {
|
|
303
323
|
return new Vec4(this.x, this.y, this.z, 1.0);
|
|
304
|
-
}
|
|
324
|
+
}
|
|
305
325
|
|
|
306
326
|
/**
|
|
307
327
|
* Returns clone vector.
|
|
308
328
|
* @public
|
|
309
|
-
* @returns {
|
|
329
|
+
* @returns {Vec3} -
|
|
310
330
|
*/
|
|
311
331
|
clone() {
|
|
312
332
|
return new Vec3(this.x, this.y, this.z);
|
|
313
|
-
}
|
|
333
|
+
}
|
|
314
334
|
|
|
315
335
|
/**
|
|
316
336
|
* Converts vector to text string.
|
|
@@ -319,7 +339,7 @@ export class Vec3 {
|
|
|
319
339
|
*/
|
|
320
340
|
toString() {
|
|
321
341
|
return "(" + this.x + "," + this.y + "," + this.z + ")";
|
|
322
|
-
}
|
|
342
|
+
}
|
|
323
343
|
|
|
324
344
|
/**
|
|
325
345
|
* Returns true if vector's values are zero.
|
|
@@ -328,39 +348,39 @@ export class Vec3 {
|
|
|
328
348
|
*/
|
|
329
349
|
isZero() {
|
|
330
350
|
return !(this.x || this.y || this.z);
|
|
331
|
-
}
|
|
351
|
+
}
|
|
332
352
|
|
|
333
353
|
/**
|
|
334
354
|
* Get projection of the first vector to the second.
|
|
335
355
|
* @static
|
|
336
|
-
* @param {
|
|
337
|
-
* @returns {
|
|
356
|
+
* @param {Vec3} a - Project vector.
|
|
357
|
+
* @returns {Vec3} -
|
|
338
358
|
*/
|
|
339
359
|
projToVec(a) {
|
|
340
360
|
return a.scaleTo(a.dot(this) / a.dot(a));
|
|
341
|
-
}
|
|
361
|
+
}
|
|
342
362
|
|
|
343
363
|
/**
|
|
344
364
|
* Compares with vector. Returns true if it equals another.
|
|
345
365
|
* @public
|
|
346
|
-
* @param {
|
|
366
|
+
* @param {Vec3} p - Vector to compare.
|
|
347
367
|
* @returns {boolean} -
|
|
348
368
|
*/
|
|
349
369
|
equal(p) {
|
|
350
370
|
return this.x === p.x && this.y === p.y && this.z === p.z;
|
|
351
|
-
}
|
|
371
|
+
}
|
|
352
372
|
|
|
353
373
|
/**
|
|
354
374
|
* Copy input vector's values.
|
|
355
|
-
* @param {
|
|
356
|
-
* @returns {
|
|
375
|
+
* @param {Vec3} point3 - Vector to copy.
|
|
376
|
+
* @returns {Vec3} -
|
|
357
377
|
*/
|
|
358
378
|
copy(point3) {
|
|
359
379
|
this.x = point3.x;
|
|
360
380
|
this.y = point3.y;
|
|
361
381
|
this.z = point3.z;
|
|
362
382
|
return this;
|
|
363
|
-
}
|
|
383
|
+
}
|
|
364
384
|
|
|
365
385
|
/**
|
|
366
386
|
* Gets vector's length.
|
|
@@ -369,7 +389,7 @@ export class Vec3 {
|
|
|
369
389
|
*/
|
|
370
390
|
length() {
|
|
371
391
|
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
372
|
-
}
|
|
392
|
+
}
|
|
373
393
|
|
|
374
394
|
/**
|
|
375
395
|
* Returns squared vector's length.
|
|
@@ -378,157 +398,157 @@ export class Vec3 {
|
|
|
378
398
|
*/
|
|
379
399
|
length2() {
|
|
380
400
|
return this.x * this.x + this.y * this.y + this.z * this.z;
|
|
381
|
-
}
|
|
401
|
+
}
|
|
382
402
|
|
|
383
403
|
/**
|
|
384
404
|
* Converts vector's values to a quaternion object.
|
|
385
405
|
* @public
|
|
386
|
-
* @returns {
|
|
406
|
+
* @returns {Quat} -
|
|
387
407
|
*/
|
|
388
408
|
getQuat() {
|
|
389
409
|
return new Quat(this.x, this.y, this.z);
|
|
390
|
-
}
|
|
410
|
+
}
|
|
391
411
|
|
|
392
412
|
/**
|
|
393
413
|
* Adds vector to the current.
|
|
394
414
|
* @public
|
|
395
|
-
* @param {
|
|
396
|
-
* @returns {
|
|
415
|
+
* @param {Vec3} point3 - Point to add.
|
|
416
|
+
* @returns {Vec3} -
|
|
397
417
|
*/
|
|
398
418
|
addA(point3) {
|
|
399
419
|
this.x += point3.x;
|
|
400
420
|
this.y += point3.y;
|
|
401
421
|
this.z += point3.z;
|
|
402
422
|
return this;
|
|
403
|
-
}
|
|
423
|
+
}
|
|
404
424
|
|
|
405
425
|
/**
|
|
406
426
|
* Gets two vectors summarization.
|
|
407
427
|
* @public
|
|
408
|
-
* @param {
|
|
409
|
-
* @returns {
|
|
428
|
+
* @param {Vec3} point3 - Vector to add.
|
|
429
|
+
* @returns {Vec3} Returns a sum vector.
|
|
410
430
|
*/
|
|
411
431
|
add(point3) {
|
|
412
432
|
return new Vec3(this.x + point3.x, this.y + point3.y, this.z + point3.z);
|
|
413
|
-
}
|
|
433
|
+
}
|
|
414
434
|
|
|
415
435
|
/**
|
|
416
436
|
* Subtract vector from the current.
|
|
417
437
|
* @public
|
|
418
|
-
* @param {
|
|
419
|
-
* @returns {
|
|
438
|
+
* @param {Vec3} point3 - Subtract vector.
|
|
439
|
+
* @returns {Vec3} -
|
|
420
440
|
*/
|
|
421
441
|
subA(point3) {
|
|
422
442
|
this.x -= point3.x;
|
|
423
443
|
this.y -= point3.y;
|
|
424
444
|
this.z -= point3.z;
|
|
425
445
|
return this;
|
|
426
|
-
}
|
|
446
|
+
}
|
|
427
447
|
|
|
428
448
|
/**
|
|
429
449
|
* Gets vector subtraction.
|
|
430
450
|
* @public
|
|
431
|
-
* @param {
|
|
432
|
-
* @return {
|
|
451
|
+
* @param {Vec3} point3 - Subtract vector.
|
|
452
|
+
* @return {Vec3} Returns new instance of a subtraction
|
|
433
453
|
*/
|
|
434
454
|
sub(point3) {
|
|
435
455
|
return new Vec3(this.x - point3.x, this.y - point3.y, this.z - point3.z);
|
|
436
|
-
}
|
|
456
|
+
}
|
|
437
457
|
|
|
438
458
|
/**
|
|
439
459
|
* Scale current vector.
|
|
440
460
|
* @public
|
|
441
461
|
* @param {number} scale - Scale value.
|
|
442
|
-
* @returns {
|
|
462
|
+
* @returns {Vec3} -
|
|
443
463
|
*/
|
|
444
464
|
scale(scale) {
|
|
445
465
|
this.x *= scale;
|
|
446
466
|
this.y *= scale;
|
|
447
467
|
this.z *= scale;
|
|
448
468
|
return this;
|
|
449
|
-
}
|
|
469
|
+
}
|
|
450
470
|
|
|
451
471
|
/**
|
|
452
472
|
* Scale current vector to another instance.
|
|
453
473
|
* @public
|
|
454
474
|
* @param {number} scale - Scale value.
|
|
455
|
-
* @returns {
|
|
475
|
+
* @returns {Vec3} -
|
|
456
476
|
*/
|
|
457
477
|
scaleTo(scale) {
|
|
458
478
|
return new Vec3(this.x * scale, this.y * scale, this.z * scale);
|
|
459
|
-
}
|
|
479
|
+
}
|
|
460
480
|
|
|
461
481
|
/**
|
|
462
482
|
* Multiply current vector object to another and store result in the current instance.
|
|
463
483
|
* @public
|
|
464
|
-
* @param {
|
|
465
|
-
* @returns {
|
|
484
|
+
* @param {Vec3} vec - Multiply vector.
|
|
485
|
+
* @returns {Vec3} -
|
|
466
486
|
*/
|
|
467
487
|
mulA(vec) {
|
|
468
488
|
this.x *= vec.x;
|
|
469
489
|
this.y *= vec.y;
|
|
470
490
|
this.z *= vec.z;
|
|
471
491
|
return this;
|
|
472
|
-
}
|
|
492
|
+
}
|
|
473
493
|
|
|
474
494
|
/**
|
|
475
495
|
* Multiply current vector object to another and returns new vector instance.
|
|
476
496
|
* @public
|
|
477
|
-
* @param {
|
|
478
|
-
* @returns {
|
|
497
|
+
* @param {Vec3} vec - Multiply vector.
|
|
498
|
+
* @returns {Vec3} -
|
|
479
499
|
*/
|
|
480
500
|
mul(vec) {
|
|
481
501
|
return new Vec3(this.x * vec.x, this.y * vec.y, this.z * vec.z);
|
|
482
|
-
}
|
|
502
|
+
}
|
|
483
503
|
|
|
484
504
|
/**
|
|
485
505
|
* Divide current vector's components to another. Results stores in the current vector object.
|
|
486
506
|
* @public
|
|
487
|
-
* @param {
|
|
488
|
-
* @returns {
|
|
507
|
+
* @param {Vec3} vec - Div vector.
|
|
508
|
+
* @returns {Vec3} -
|
|
489
509
|
*/
|
|
490
510
|
divA(vec) {
|
|
491
511
|
this.x /= vec.x;
|
|
492
512
|
this.y /= vec.y;
|
|
493
513
|
this.z /= vec.z;
|
|
494
514
|
return this;
|
|
495
|
-
}
|
|
515
|
+
}
|
|
496
516
|
|
|
497
517
|
/**
|
|
498
518
|
* Divide current vector's components to another and returns new vector instance.
|
|
499
519
|
* @public
|
|
500
|
-
* @param {
|
|
501
|
-
* @returns {
|
|
520
|
+
* @param {Vec3} vec - Div vector.
|
|
521
|
+
* @returns {Vec3} -
|
|
502
522
|
*/
|
|
503
523
|
div(vec) {
|
|
504
524
|
return new Vec3(this.x / vec.x, this.y / vec.y, this.z / vec.z);
|
|
505
|
-
}
|
|
525
|
+
}
|
|
506
526
|
|
|
507
527
|
/**
|
|
508
528
|
* Gets vectors dot production.
|
|
509
529
|
* @public
|
|
510
|
-
* @param {
|
|
530
|
+
* @param {Vec3} point3 - Another vector.
|
|
511
531
|
* @returns {number} -
|
|
512
532
|
*/
|
|
513
533
|
dot(point3) {
|
|
514
534
|
return point3.x * this.x + point3.y * this.y + point3.z * this.z;
|
|
515
|
-
}
|
|
535
|
+
}
|
|
516
536
|
|
|
517
537
|
/**
|
|
518
538
|
* Gets vectors dot production.
|
|
519
539
|
* @public
|
|
520
|
-
* @param {Array.<number
|
|
540
|
+
* @param {Array.<number>} arr - Array vector. (exactly 3 entries)
|
|
521
541
|
* @returns {number} -
|
|
522
542
|
*/
|
|
523
543
|
dotArr(arr) {
|
|
524
544
|
return arr[0] * this.x + arr[1] * this.y + arr[2] * this.z;
|
|
525
|
-
}
|
|
545
|
+
}
|
|
526
546
|
|
|
527
547
|
/**
|
|
528
548
|
* Gets vectors cross production.
|
|
529
549
|
* @public
|
|
530
|
-
* @param {
|
|
531
|
-
* @returns {
|
|
550
|
+
* @param {Vec3} point3 - Another vector.
|
|
551
|
+
* @returns {Vec3} -
|
|
532
552
|
*/
|
|
533
553
|
cross(point3) {
|
|
534
554
|
return new Vec3(
|
|
@@ -536,22 +556,22 @@ export class Vec3 {
|
|
|
536
556
|
this.z * point3.x - this.x * point3.z,
|
|
537
557
|
this.x * point3.y - this.y * point3.x
|
|
538
558
|
);
|
|
539
|
-
}
|
|
559
|
+
}
|
|
540
560
|
|
|
541
561
|
/**
|
|
542
562
|
* Sets vector to zero.
|
|
543
563
|
* @public
|
|
544
|
-
* @returns {
|
|
564
|
+
* @returns {Vec3} -
|
|
545
565
|
*/
|
|
546
566
|
clear() {
|
|
547
567
|
this.x = this.y = this.z = 0;
|
|
548
568
|
return this;
|
|
549
|
-
}
|
|
569
|
+
}
|
|
550
570
|
|
|
551
571
|
/**
|
|
552
572
|
* Returns normalized vector.
|
|
553
573
|
* @public
|
|
554
|
-
* @returns {
|
|
574
|
+
* @returns {Vec3} -
|
|
555
575
|
*/
|
|
556
576
|
getNormal() {
|
|
557
577
|
var res = new Vec3();
|
|
@@ -564,13 +584,13 @@ export class Vec3 {
|
|
|
564
584
|
res.z *= length;
|
|
565
585
|
|
|
566
586
|
return res;
|
|
567
|
-
}
|
|
587
|
+
}
|
|
568
588
|
|
|
569
589
|
/**
|
|
570
590
|
* Returns normalized vector.
|
|
571
591
|
* @deprecated
|
|
572
592
|
* @public
|
|
573
|
-
* @returns {
|
|
593
|
+
* @returns {Vec3} -
|
|
574
594
|
*/
|
|
575
595
|
normal() {
|
|
576
596
|
var res = new Vec3();
|
|
@@ -583,12 +603,12 @@ export class Vec3 {
|
|
|
583
603
|
res.z *= length;
|
|
584
604
|
|
|
585
605
|
return res;
|
|
586
|
-
}
|
|
606
|
+
}
|
|
587
607
|
|
|
588
608
|
/**
|
|
589
609
|
* Returns normalized negate vector.
|
|
590
610
|
* @public
|
|
591
|
-
* @returns {
|
|
611
|
+
* @returns {Vec3} -
|
|
592
612
|
*/
|
|
593
613
|
normalNegate() {
|
|
594
614
|
var res = new Vec3();
|
|
@@ -601,12 +621,12 @@ export class Vec3 {
|
|
|
601
621
|
res.z *= length;
|
|
602
622
|
|
|
603
623
|
return res;
|
|
604
|
-
}
|
|
624
|
+
}
|
|
605
625
|
|
|
606
626
|
/**
|
|
607
627
|
* Returns normalized negate scale vector.
|
|
608
628
|
* @public
|
|
609
|
-
* @returns {
|
|
629
|
+
* @returns {Vec3} -
|
|
610
630
|
*/
|
|
611
631
|
normalNegateScale(scale) {
|
|
612
632
|
var res = new Vec3();
|
|
@@ -619,12 +639,12 @@ export class Vec3 {
|
|
|
619
639
|
res.z *= length;
|
|
620
640
|
|
|
621
641
|
return res;
|
|
622
|
-
}
|
|
642
|
+
}
|
|
623
643
|
|
|
624
644
|
/**
|
|
625
645
|
* Returns normalized scale vector.
|
|
626
646
|
* @public
|
|
627
|
-
* @returns {
|
|
647
|
+
* @returns {Vec3} -
|
|
628
648
|
*/
|
|
629
649
|
normalScale(scale) {
|
|
630
650
|
var res = new Vec3();
|
|
@@ -637,12 +657,12 @@ export class Vec3 {
|
|
|
637
657
|
res.z *= length;
|
|
638
658
|
|
|
639
659
|
return res;
|
|
640
|
-
}
|
|
660
|
+
}
|
|
641
661
|
|
|
642
662
|
/**
|
|
643
663
|
* Normalize current vector.
|
|
644
664
|
* @public
|
|
645
|
-
* @returns {
|
|
665
|
+
* @returns {Vec3} -
|
|
646
666
|
*/
|
|
647
667
|
normalize() {
|
|
648
668
|
var length = 1.0 / this.length();
|
|
@@ -652,36 +672,36 @@ export class Vec3 {
|
|
|
652
672
|
this.z *= length;
|
|
653
673
|
|
|
654
674
|
return this;
|
|
655
|
-
}
|
|
675
|
+
}
|
|
656
676
|
|
|
657
677
|
/**
|
|
658
678
|
* Converts vector to a number array.
|
|
659
679
|
* @public
|
|
660
|
-
* @returns {Array.<number
|
|
680
|
+
* @returns {Array.<number>} - (exactly 3 entries)
|
|
661
681
|
* @deprecated
|
|
662
682
|
*/
|
|
663
683
|
toVec() {
|
|
664
684
|
return [this.x, this.y, this.z];
|
|
665
|
-
}
|
|
685
|
+
}
|
|
666
686
|
|
|
667
687
|
/**
|
|
668
688
|
* Converts vector to a number array.
|
|
669
689
|
* @public
|
|
670
|
-
* @returns {Array.<number
|
|
690
|
+
* @returns {Array.<number>} - (exactly 3 entries)
|
|
671
691
|
*/
|
|
672
692
|
toArray() {
|
|
673
693
|
return [this.x, this.y, this.z];
|
|
674
|
-
}
|
|
694
|
+
}
|
|
675
695
|
|
|
676
696
|
/**
|
|
677
697
|
* Gets distance to point.
|
|
678
698
|
* @public
|
|
679
|
-
* @param {
|
|
699
|
+
* @param {Vec3} point3 - Distant point.
|
|
680
700
|
* @returns {number} -
|
|
681
701
|
*/
|
|
682
702
|
distance(point3) {
|
|
683
703
|
return Vec3.sub(this, point3).length();
|
|
684
|
-
}
|
|
704
|
+
}
|
|
685
705
|
|
|
686
706
|
/**
|
|
687
707
|
* Sets vector's values.
|
|
@@ -689,93 +709,103 @@ export class Vec3 {
|
|
|
689
709
|
* @param {number} x - Value X.
|
|
690
710
|
* @param {number} y - Value Y.
|
|
691
711
|
* @param {number} z - Value Z.
|
|
692
|
-
* @returns {
|
|
712
|
+
* @returns {Vec3} -
|
|
693
713
|
*/
|
|
694
714
|
set(x, y, z) {
|
|
695
715
|
this.x = x;
|
|
696
716
|
this.y = y;
|
|
697
717
|
this.z = z;
|
|
698
718
|
return this;
|
|
699
|
-
}
|
|
719
|
+
}
|
|
700
720
|
|
|
701
721
|
/**
|
|
702
722
|
* Negate current vector.
|
|
703
723
|
* @public
|
|
704
|
-
* @returns {
|
|
724
|
+
* @returns {Vec3} -
|
|
705
725
|
*/
|
|
706
726
|
negate() {
|
|
707
727
|
this.x = -this.x;
|
|
708
728
|
this.y = -this.y;
|
|
709
729
|
this.z = -this.z;
|
|
710
730
|
return this;
|
|
711
|
-
}
|
|
731
|
+
}
|
|
712
732
|
|
|
713
733
|
/**
|
|
714
734
|
* Negate current vector to another instance.
|
|
715
735
|
* @public
|
|
716
|
-
* @returns {
|
|
736
|
+
* @returns {Vec3} -
|
|
717
737
|
*/
|
|
718
738
|
negateTo() {
|
|
719
739
|
return new Vec3(-this.x, -this.y, -this.z);
|
|
720
|
-
}
|
|
740
|
+
}
|
|
721
741
|
|
|
722
742
|
/**
|
|
723
743
|
* Gets projected point coordinates of the current vector on the ray.
|
|
724
744
|
* @public
|
|
725
|
-
* @param {
|
|
726
|
-
* @param {
|
|
727
|
-
* @returns {
|
|
745
|
+
* @param {Vec3} pos - Ray position.
|
|
746
|
+
* @param {Vec3} direction - Ray direction.
|
|
747
|
+
* @returns {Vec3} -
|
|
728
748
|
*/
|
|
729
749
|
projToRay(pos, direction) {
|
|
730
750
|
var v = Vec3.proj_b_to_a(Vec3.sub(this, pos), direction);
|
|
731
751
|
v.addA(pos);
|
|
732
752
|
return v;
|
|
733
|
-
}
|
|
753
|
+
}
|
|
734
754
|
|
|
735
755
|
/**
|
|
736
756
|
* Gets angle between two vectors.
|
|
737
757
|
* @public
|
|
738
|
-
* @param {
|
|
758
|
+
* @param {Vec3} a - Another vector.
|
|
739
759
|
* @returns {number} -
|
|
740
760
|
*/
|
|
741
761
|
angle(a) {
|
|
742
762
|
return Vec3.angle(this, a);
|
|
743
|
-
}
|
|
763
|
+
}
|
|
744
764
|
|
|
745
765
|
/**
|
|
746
766
|
* Returns two vectors linear interpolation.
|
|
747
767
|
* @public
|
|
748
|
-
* @param {
|
|
768
|
+
* @param {Vec3} v2 - End vector.
|
|
749
769
|
* @param {number} l - Interpolate value.
|
|
750
|
-
* @returns {
|
|
770
|
+
* @returns {Vec3} -
|
|
751
771
|
*/
|
|
752
772
|
lerp(v2, l) {
|
|
753
|
-
return new Vec3(
|
|
754
|
-
|
|
773
|
+
return new Vec3(
|
|
774
|
+
this.x + (v2.x - this.x) * l,
|
|
775
|
+
this.y + (v2.y - this.y) * l,
|
|
776
|
+
this.z + (v2.z - this.z) * l
|
|
777
|
+
);
|
|
778
|
+
}
|
|
755
779
|
|
|
756
780
|
/**
|
|
757
781
|
* Returns vector interpolation by v(t) = v1 * t + v2 * (1 - t)
|
|
758
782
|
* @public
|
|
759
|
-
* @param {
|
|
783
|
+
* @param {Vec3} v2 - End vector.
|
|
760
784
|
* @param {number} t - Interpolate value.
|
|
761
|
-
* @returns {
|
|
785
|
+
* @returns {Vec3} -
|
|
762
786
|
*/
|
|
763
787
|
smerp(v2, t) {
|
|
764
788
|
var one_d = 1 - t;
|
|
765
|
-
return new Vec3(
|
|
766
|
-
|
|
789
|
+
return new Vec3(
|
|
790
|
+
this.x * t + v2.x * one_d,
|
|
791
|
+
this.y * t + v2.y * one_d,
|
|
792
|
+
this.z * t + v2.z * one_d
|
|
793
|
+
);
|
|
794
|
+
}
|
|
767
795
|
|
|
768
|
-
static get LERP_DELTA() {
|
|
796
|
+
static get LERP_DELTA() {
|
|
797
|
+
return 1e-6;
|
|
798
|
+
}
|
|
769
799
|
|
|
770
800
|
/**
|
|
771
801
|
* Spherically interpolates between two vectors.
|
|
772
|
-
* Interpolates between current and v2 vector by amount t. The difference between this and linear interpolation (aka, "lerp") is that
|
|
773
|
-
* the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated
|
|
802
|
+
* Interpolates between current and v2 vector by amount t. The difference between this and linear interpolation (aka, "lerp") is that
|
|
803
|
+
* the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated
|
|
774
804
|
* by the angle and its magnitude is interpolated between the magnitudes of from and to.
|
|
775
805
|
* @public
|
|
776
|
-
* @param {
|
|
806
|
+
* @param {Vec3} v2 -
|
|
777
807
|
* @param {number} t - The parameter t is clamped to the range [0, 1].
|
|
778
|
-
* @returns {
|
|
808
|
+
* @returns {Vec3} -
|
|
779
809
|
*/
|
|
780
810
|
slerp(v2, t) {
|
|
781
811
|
var res = new Vec3();
|
|
@@ -791,7 +821,7 @@ export class Vec3 {
|
|
|
791
821
|
var omega, sinom, scale0, scale1;
|
|
792
822
|
var cosom = this.dot(v2);
|
|
793
823
|
|
|
794
|
-
if (
|
|
824
|
+
if (1.0 - cosom > Vec3.LERP_DELTA) {
|
|
795
825
|
omega = Math.acos(cosom);
|
|
796
826
|
sinom = Math.sin(omega);
|
|
797
827
|
scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
|
@@ -802,7 +832,7 @@ export class Vec3 {
|
|
|
802
832
|
}
|
|
803
833
|
|
|
804
834
|
return Vec3.add(this.scaleTo(scale0), v2.scale(scale1));
|
|
805
|
-
}
|
|
835
|
+
}
|
|
806
836
|
|
|
807
837
|
/**
|
|
808
838
|
* Gets the shortest arc quaternion to rotate this vector to the destination vector.
|
|
@@ -825,14 +855,15 @@ export class Vec3 {
|
|
|
825
855
|
return Quat.IDENTITY.clone();
|
|
826
856
|
}
|
|
827
857
|
|
|
828
|
-
if (d <
|
|
858
|
+
if (d < 1e-6 - 1.0) {
|
|
829
859
|
if (!fallbackAxis.isEqual(Vec3.ZERO)) {
|
|
830
860
|
// rotate 180 degrees about the fallback axis
|
|
831
861
|
return Quat.axisAngleToQuat(Math.PI, fallbackAxis);
|
|
832
862
|
} else {
|
|
833
863
|
// Generate an axis
|
|
834
864
|
let axis = Vec3.UNIT_X.cross(v0);
|
|
835
|
-
if (axis.isZero()) {
|
|
865
|
+
if (axis.isZero()) {
|
|
866
|
+
// pick another if colinear
|
|
836
867
|
axis = Vec3.UNIT_Y.cross(v0);
|
|
837
868
|
}
|
|
838
869
|
axis.normalize();
|
|
@@ -848,7 +879,7 @@ export class Vec3 {
|
|
|
848
879
|
q.normalise();
|
|
849
880
|
return q;
|
|
850
881
|
}
|
|
851
|
-
}
|
|
882
|
+
}
|
|
852
883
|
}
|
|
853
884
|
|
|
854
885
|
/**
|
|
@@ -857,9 +888,8 @@ export class Vec3 {
|
|
|
857
888
|
* @param {number} [x] - First cvalue.
|
|
858
889
|
* @param {number} [y] - Second value.
|
|
859
890
|
* @param {number} [z] - Third value.
|
|
860
|
-
* @returns {
|
|
891
|
+
* @returns {Vec3} -
|
|
861
892
|
*/
|
|
862
893
|
export function vec3(x, y, z) {
|
|
863
894
|
return new Vec3(x, y, z);
|
|
864
|
-
}
|
|
865
|
-
|
|
895
|
+
}
|