@openglobus/og 0.11.2 → 0.11.7
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 +13 -13
- package/src/og/Clock.js +10 -10
- package/src/og/Events.js +8 -6
- package/src/og/Extent.js +82 -41
- package/src/og/Globe.js +25 -13
- package/src/og/ImageCanvas.js +22 -16
- package/src/og/LonLat.js +16 -13
- package/src/og/Popup.js +21 -14
- package/src/og/QueueArray.js +6 -2
- package/src/og/Rectangle.js +11 -6
- package/src/og/Stack.js +5 -2
- package/src/og/ajax.js +21 -33
- package/src/og/astro/astro.js +5 -5
- package/src/og/astro/earth.js +22 -16
- package/src/og/astro/jd.js +23 -18
- package/src/og/astro/orbit.js +13 -11
- package/src/og/astro/rotation.js +17 -8
- package/src/og/bv/Box.js +7 -3
- package/src/og/bv/Sphere.js +14 -11
- package/src/og/camera/Camera.js +51 -54
- package/src/og/camera/Frustum.js +29 -18
- package/src/og/camera/PlanetCamera.js +32 -23
- package/src/og/control/CompassButton.js +5 -1
- package/src/og/control/Control.js +12 -10
- package/src/og/control/DebugInfo.js +4 -1
- package/src/og/control/EarthCoordinates.js +54 -33
- package/src/og/control/KeyboardNavigation.js +10 -10
- package/src/og/control/LayerSwitcher.js +22 -21
- package/src/og/control/Lighting.js +34 -3
- package/src/og/control/MouseNavigation.js +1 -1
- package/src/og/control/ScaleControl.js +1 -1
- package/src/og/control/SegmentBoundVisualization.js +6 -7
- package/src/og/control/ShowFps.js +13 -8
- package/src/og/control/SimpleNavigation.js +6 -8
- package/src/og/control/Sun.js +25 -15
- package/src/og/control/ToggleWireframe.js +4 -4
- package/src/og/control/TouchNavigation.js +44 -33
- package/src/og/control/ZoomControl.js +41 -25
- package/src/og/ellipsoid/Ellipsoid.js +162 -66
- package/src/og/ellipsoid/wgs84.js +4 -4
- package/src/og/entity/BaseBillboard.js +100 -56
- package/src/og/entity/Billboard.js +14 -10
- package/src/og/entity/BillboardHandler.js +317 -60
- package/src/og/entity/Entity.js +100 -68
- package/src/og/entity/EntityCollection.js +70 -47
- package/src/og/entity/GeoObject.js +228 -0
- package/src/og/entity/GeoObjectHandler.js +910 -0
- package/src/og/entity/Geometry.js +27 -24
- package/src/og/entity/GeometryHandler.js +596 -124
- package/src/og/entity/Label.js +80 -49
- package/src/og/entity/LabelHandler.js +45 -244
- package/src/og/entity/LabelWorker.js +218 -0
- package/src/og/entity/Object3d.js +504 -0
- package/src/og/entity/PointCloud.js +80 -32
- package/src/og/entity/PointCloudHandler.js +8 -8
- package/src/og/entity/Polyline.js +16 -16
- package/src/og/entity/Ray.js +60 -27
- package/src/og/entity/Strip.js +77 -48
- package/src/og/entity/StripHandler.js +26 -26
- package/src/og/entity/index.js +8 -16
- package/src/og/layer/BaseGeoImage.js +54 -23
- package/src/og/layer/CanvasTiles.js +24 -24
- package/src/og/layer/GeoImage.js +9 -9
- package/src/og/layer/GeoVideo.js +3 -3
- package/src/og/layer/KML.js +63 -37
- package/src/og/layer/Layer.js +44 -21
- package/src/og/layer/Material.js +23 -20
- package/src/og/layer/Vector.js +114 -68
- package/src/og/layer/WMS.js +34 -17
- package/src/og/layer/XYZ.js +48 -46
- package/src/og/light/LightSource.js +46 -39
- package/src/og/math/Mat3.js +34 -22
- package/src/og/math/Mat4.js +603 -459
- package/src/og/math/Plane.js +21 -20
- package/src/og/math/Quat.js +182 -139
- package/src/og/math/Ray.js +38 -33
- package/src/og/math/Vec2.js +85 -75
- package/src/og/math/Vec3.js +142 -112
- package/src/og/math/Vec4.js +27 -31
- package/src/og/math/coder.js +10 -10
- package/src/og/math.js +12 -12
- package/src/og/proj/EPSG3857.js +4 -4
- package/src/og/proj/EPSG4326.js +4 -4
- package/src/og/proj/Proj.js +4 -6
- package/src/og/quadTree/Node.js +8 -8
- package/src/og/renderer/Renderer.js +59 -52
- package/src/og/renderer/RendererEvents.js +50 -27
- package/src/og/scene/BaseNode.js +7 -8
- package/src/og/scene/Planet.js +102 -103
- package/src/og/scene/RenderNode.js +28 -21
- package/src/og/segment/Segment.js +26 -21
- package/src/og/segment/SegmentLonLat.js +5 -5
- package/src/og/shaders/drawnode.js +135 -142
- package/src/og/shaders/geoObject.js +211 -0
- package/src/og/shaders/pointCloud.js +41 -41
- package/src/og/shaders/shape.js +12 -18
- package/src/og/shaders/skybox.js +36 -36
- package/src/og/shaders/toneMapping.js +1 -0
- package/src/og/shapes/BaseShape.js +126 -54
- package/src/og/shapes/Icosphere.js +29 -14
- package/src/og/shapes/Sphere.js +12 -15
- package/src/og/terrain/BilTerrain.js +1 -0
- package/src/og/terrain/EmptyTerrain.js +2 -2
- package/src/og/terrain/GlobusTerrain.js +9 -9
- package/src/og/utils/FontAtlas.js +6 -2
- package/src/og/utils/TextureAtlas.js +22 -24
- package/src/og/utils/VectorTileCreator.js +1 -3
- package/src/og/utils/shared.js +16 -16
- package/src/og/webgl/Framebuffer.js +88 -40
- package/src/og/webgl/Handler.js +243 -169
- package/src/og/webgl/Multisample.js +47 -19
- package/src/og/webgl/Program.js +79 -34
- package/src/og/webgl/ProgramController.js +17 -13
- package/src/og/webgl/callbacks.js +8 -8
- package/src/og/inherits.js +0 -8
- package/src/og/utils/polylabel.js +0 -176
- package/types/Clock.d.ts +0 -90
- package/types/Deferred.d.ts +0 -6
- package/types/Events.d.ts +0 -73
- package/types/Extent.d.ts +0 -166
- package/types/Globe.d.ts +0 -75
- package/types/ImageCanvas.d.ts +0 -121
- package/types/Lock.d.ts +0 -12
- package/types/LonLat.d.ts +0 -108
- package/types/Popup.d.ts +0 -38
- package/types/QueueArray.d.ts +0 -15
- package/types/Rectangle.d.ts +0 -74
- package/types/Stack.d.ts +0 -15
- package/types/ajax.d.ts +0 -24
- package/types/arial.d.ts +0 -48
- package/types/astro/astro.d.ts +0 -38
- package/types/astro/earth.d.ts +0 -6
- package/types/astro/jd.d.ts +0 -254
- package/types/bv/Box.d.ts +0 -25
- package/types/bv/Sphere.d.ts +0 -38
- package/types/bv/index.d.ts +0 -3
- package/types/camera/Camera.d.ts +0 -303
- package/types/camera/Frustum.d.ts +0 -129
- package/types/camera/PlanetCamera.d.ts +0 -223
- package/types/camera/index.d.ts +0 -3
- package/types/cons.d.ts +0 -40
- package/types/control/CompassButton.d.ts +0 -18
- package/types/control/Control.d.ts +0 -101
- package/types/control/DebugInfo.d.ts +0 -16
- package/types/control/EarthCoordinates.d.ts +0 -47
- package/types/control/EarthNavigation.d.ts +0 -42
- package/types/control/GeoImageDragControl.d.ts +0 -6
- package/types/control/KeyboardNavigation.d.ts +0 -22
- package/types/control/LayerSwitcher.d.ts +0 -23
- package/types/control/Lighting.d.ts +0 -16
- package/types/control/MouseNavigation.d.ts +0 -51
- package/types/control/ScaleControl.d.ts +0 -22
- package/types/control/ShowFps.d.ts +0 -12
- package/types/control/SimpleNavigation.d.ts +0 -28
- package/types/control/Sun.d.ts +0 -52
- package/types/control/ToggleWireframe.d.ts +0 -12
- package/types/control/TouchNavigation.d.ts +0 -50
- package/types/control/ZoomControl.d.ts +0 -28
- package/types/control/index.d.ts +0 -17
- package/types/ellipsoid/Ellipsoid.d.ts +0 -142
- package/types/ellipsoid/index.d.ts +0 -3
- package/types/ellipsoid/wgs84.d.ts +0 -5
- package/types/entity/BaseBillboard.d.ts +0 -208
- package/types/entity/Billboard.d.ts +0 -94
- package/types/entity/BillboardHandler.d.ts +0 -74
- package/types/entity/Entity.d.ts +0 -331
- package/types/entity/EntityCollection.d.ts +0 -303
- package/types/entity/Geometry.d.ts +0 -73
- package/types/entity/GeometryHandler.d.ts +0 -76
- package/types/entity/Label.d.ts +0 -194
- package/types/entity/LabelHandler.d.ts +0 -24
- package/types/entity/PointCloud.d.ts +0 -174
- package/types/entity/PointCloudHandler.d.ts +0 -38
- package/types/entity/Polyline.d.ts +0 -304
- package/types/entity/PolylineHandler.d.ts +0 -18
- package/types/entity/Ray.d.ts +0 -123
- package/types/entity/RayHandler.d.ts +0 -67
- package/types/entity/ShapeHandler.d.ts +0 -22
- package/types/entity/Strip.d.ts +0 -118
- package/types/entity/StripHandler.d.ts +0 -38
- package/types/entity/index.d.ts +0 -8
- package/types/index.core.d.ts +0 -65
- package/types/index.d.ts +0 -45
- package/types/index.webgl.d.ts +0 -7
- package/types/inherits.d.ts +0 -4
- package/types/input/KeyboardHandler.d.ts +0 -10
- package/types/input/MouseHandler.d.ts +0 -5
- package/types/input/TouchHandler.d.ts +0 -5
- package/types/input/input.d.ts +0 -34
- package/types/layer/BaseGeoImage.d.ts +0 -107
- package/types/layer/CanvasTiles.d.ts +0 -75
- package/types/layer/GeoImage.d.ts +0 -65
- package/types/layer/GeoTexture2d.d.ts +0 -8
- package/types/layer/GeoVideo.d.ts +0 -80
- package/types/layer/KML.d.ts +0 -58
- package/types/layer/Layer.d.ts +0 -321
- package/types/layer/Material.d.ts +0 -48
- package/types/layer/Vector.d.ts +0 -228
- package/types/layer/WMS.d.ts +0 -66
- package/types/layer/XYZ.d.ts +0 -130
- package/types/layer/index.d.ts +0 -10
- package/types/light/LightSource.d.ts +0 -177
- package/types/math/Line2.d.ts +0 -11
- package/types/math/Line3.d.ts +0 -10
- package/types/math/Mat3.d.ts +0 -63
- package/types/math/Mat4.d.ts +0 -173
- package/types/math/Plane.d.ts +0 -17
- package/types/math/Quat.d.ts +0 -376
- package/types/math/Ray.d.ts +0 -81
- package/types/math/Vec2.d.ts +0 -308
- package/types/math/Vec3.d.ts +0 -459
- package/types/math/Vec4.d.ts +0 -161
- package/types/math/coder.d.ts +0 -42
- package/types/math/index.d.ts +0 -11
- package/types/math.d.ts +0 -261
- package/types/mercator.d.ts +0 -92
- package/types/proj/EPSG3857.d.ts +0 -5
- package/types/proj/EPSG4326.d.ts +0 -5
- package/types/proj/Proj.d.ts +0 -42
- package/types/quadTree/EntityCollectionNode.d.ts +0 -34
- package/types/quadTree/Node.d.ts +0 -61
- package/types/quadTree/quadTree.d.ts +0 -40
- package/types/renderer/Renderer.d.ts +0 -296
- package/types/renderer/RendererEvents.d.ts +0 -230
- package/types/res/images.d.ts +0 -3
- package/types/scene/Axes.d.ts +0 -11
- package/types/scene/BaseNode.d.ts +0 -60
- package/types/scene/Planet.d.ts +0 -574
- package/types/scene/RenderNode.d.ts +0 -143
- package/types/scene/SkyBox.d.ts +0 -10
- package/types/scene/index.d.ts +0 -4
- package/types/segment/Segment.d.ts +0 -271
- package/types/segment/SegmentLonLat.d.ts +0 -62
- package/types/segment/segmentHelper.d.ts +0 -13
- package/types/shaders/billboard.d.ts +0 -3
- package/types/shaders/depth.d.ts +0 -2
- package/types/shaders/drawnode.d.ts +0 -7
- package/types/shaders/label.d.ts +0 -4
- package/types/shaders/pointCloud.d.ts +0 -2
- package/types/shaders/polyline.d.ts +0 -3
- package/types/shaders/ray.d.ts +0 -2
- package/types/shaders/screenFrame.d.ts +0 -2
- package/types/shaders/shape.d.ts +0 -4
- package/types/shaders/skybox.d.ts +0 -2
- package/types/shaders/toneMapping.d.ts +0 -2
- package/types/shapes/BaseShape.d.ts +0 -247
- package/types/shapes/Sphere.d.ts +0 -41
- package/types/terrain/BilTerrain.d.ts +0 -8
- package/types/terrain/EmptyTerrain.d.ts +0 -72
- package/types/terrain/Geoid.d.ts +0 -26
- package/types/terrain/GlobusTerrain.d.ts +0 -153
- package/types/terrain/MapboxTerrain.d.ts +0 -8
- package/types/terrain/index.d.ts +0 -5
- package/types/utils/FontAtlas.d.ts +0 -14
- package/types/utils/GeoImageCreator.d.ts +0 -30
- package/types/utils/ImagesCacheManager.d.ts +0 -10
- package/types/utils/Loader.d.ts +0 -25
- package/types/utils/NormalMapCreator.d.ts +0 -39
- package/types/utils/PlainSegmentWorker.d.ts +0 -10
- package/types/utils/TerrainWorker.d.ts +0 -9
- package/types/utils/TextureAtlas.d.ts +0 -111
- package/types/utils/VectorTileCreator.d.ts +0 -16
- package/types/utils/colorTable.d.ts +0 -143
- package/types/utils/earcut.d.ts +0 -6
- package/types/utils/shared.d.ts +0 -230
- package/types/webgl/Framebuffer.d.ts +0 -135
- package/types/webgl/Handler.d.ts +0 -372
- package/types/webgl/Multisample.d.ts +0 -89
- package/types/webgl/Program.d.ts +0 -155
- package/types/webgl/ProgramController.d.ts +0 -84
- package/types/webgl/callbacks.d.ts +0 -1
- package/types/webgl/index.d.ts +0 -6
- package/types/webgl/types.d.ts +0 -2
package/src/og/math/Ray.js
CHANGED
|
@@ -2,51 +2,58 @@
|
|
|
2
2
|
* @module og/math/Ray
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
"use strict";
|
|
6
6
|
|
|
7
|
-
import * as math from
|
|
8
|
-
import { Vec3 } from
|
|
7
|
+
import * as math from "../math.js";
|
|
8
|
+
import { Vec3 } from "./Vec3.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Represents a ray that extends infinitely from the provided origin in the provided direction.
|
|
12
12
|
* @class
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {
|
|
13
|
+
* @param {Vec3} origin - The origin of the ray.
|
|
14
|
+
* @param {Vec3} direction - The direction of the ray.
|
|
15
15
|
*/
|
|
16
16
|
export class Ray {
|
|
17
17
|
constructor(origin, direction) {
|
|
18
|
-
|
|
19
18
|
/**
|
|
20
19
|
* The origin of the ray.
|
|
21
20
|
* @public
|
|
22
|
-
* @type {
|
|
21
|
+
* @type {Vec3}
|
|
23
22
|
*/
|
|
24
23
|
this.origin = origin || new Vec3();
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* The direction of the ray.
|
|
28
27
|
* @public
|
|
29
|
-
* @type {
|
|
28
|
+
* @type {Vec3}
|
|
30
29
|
*/
|
|
31
30
|
this.direction = direction || new Vec3();
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
/** @const */
|
|
35
|
-
static get OUTSIDE() {
|
|
34
|
+
static get OUTSIDE() {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
36
37
|
|
|
37
38
|
/** @const */
|
|
38
|
-
static get INSIDE() {
|
|
39
|
+
static get INSIDE() {
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
39
42
|
/** @const */
|
|
40
|
-
static get INPLANE() {
|
|
43
|
+
static get INPLANE() {
|
|
44
|
+
return 2;
|
|
45
|
+
}
|
|
41
46
|
/** @const */
|
|
42
|
-
static get AWAY() {
|
|
47
|
+
static get AWAY() {
|
|
48
|
+
return 3;
|
|
49
|
+
}
|
|
43
50
|
|
|
44
51
|
/**
|
|
45
52
|
* Sets a ray parameters.
|
|
46
53
|
* @public
|
|
47
|
-
* @param {
|
|
48
|
-
* @param {
|
|
49
|
-
* @returns {
|
|
54
|
+
* @param {Vec3} origin - The origin of the ray.
|
|
55
|
+
* @param {Vec3} direction - The direction of the ray.
|
|
56
|
+
* @returns {Ray}
|
|
50
57
|
*/
|
|
51
58
|
set(origin, direction) {
|
|
52
59
|
this.origin = origin;
|
|
@@ -58,7 +65,7 @@ export class Ray {
|
|
|
58
65
|
* Computes the point along the ray on the distance.
|
|
59
66
|
* @public
|
|
60
67
|
* @param {number} distance - Point distance.
|
|
61
|
-
* @returns {
|
|
68
|
+
* @returns {Vec3}
|
|
62
69
|
*/
|
|
63
70
|
getPoint(distance) {
|
|
64
71
|
return Vec3.add(this.origin, this.direction.scaleTo(distance));
|
|
@@ -67,11 +74,11 @@ export class Ray {
|
|
|
67
74
|
/**
|
|
68
75
|
* Returns ray hit a triange result.
|
|
69
76
|
* @public
|
|
70
|
-
* @param {
|
|
71
|
-
* @param {
|
|
72
|
-
* @param {
|
|
73
|
-
* @param {
|
|
74
|
-
* @returns {number} - Hit code, could 0 - og.Ray.OUTSIDE, 1 - og.Ray.INSIDE,
|
|
77
|
+
* @param {Vec3} v0 - First triangle corner coordinate.
|
|
78
|
+
* @param {Vec3} v1 - Second triangle corner coordinate.
|
|
79
|
+
* @param {Vec3} v2 - Third triangle corner coordinate.
|
|
80
|
+
* @param {Vec3} res - Hit point object pointer that stores hit result.
|
|
81
|
+
* @returns {number} - Hit code, could 0 - og.Ray.OUTSIDE, 1 - og.Ray.INSIDE,
|
|
75
82
|
* 2 - og.Ray.INPLANE and 3 - og.Ray.AWAY(ray goes away from triangle).
|
|
76
83
|
*/
|
|
77
84
|
hitTriangle(v0, v1, v2, res, normal) {
|
|
@@ -120,7 +127,7 @@ export class Ray {
|
|
|
120
127
|
}
|
|
121
128
|
|
|
122
129
|
var t = (uv * wu - uu * wv) / D;
|
|
123
|
-
if (t < 0.0 ||
|
|
130
|
+
if (t < 0.0 || s + t > 1.0) {
|
|
124
131
|
return Ray.OUTSIDE;
|
|
125
132
|
}
|
|
126
133
|
|
|
@@ -130,10 +137,10 @@ export class Ray {
|
|
|
130
137
|
/**
|
|
131
138
|
* Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.
|
|
132
139
|
* @public
|
|
133
|
-
* @param {
|
|
134
|
-
* @param {
|
|
135
|
-
* @param {
|
|
136
|
-
* @param {
|
|
140
|
+
* @param {Vec3} v0 - First plane point.
|
|
141
|
+
* @param {Vec3} v1 - Second plane point.
|
|
142
|
+
* @param {Vec3} v2 - Third plane point.
|
|
143
|
+
* @param {Vec3} res - Hit point object pointer that stores hit result.
|
|
137
144
|
* @returns {number}
|
|
138
145
|
*/
|
|
139
146
|
hitPlane(v0, v1, v2, res) {
|
|
@@ -171,8 +178,8 @@ export class Ray {
|
|
|
171
178
|
/**
|
|
172
179
|
* Returns a ray hit sphere coordiante. If there isn't hit returns null.
|
|
173
180
|
* @public
|
|
174
|
-
* @param {
|
|
175
|
-
* @returns {
|
|
181
|
+
* @param {Sphere} sphere - Sphere object.
|
|
182
|
+
* @returns {Vec3}
|
|
176
183
|
*/
|
|
177
184
|
hitSphere(sphere) {
|
|
178
185
|
var r = sphere.radius,
|
|
@@ -218,17 +225,15 @@ export class Ray {
|
|
|
218
225
|
// TODO
|
|
219
226
|
//
|
|
220
227
|
}
|
|
221
|
-
|
|
222
228
|
}
|
|
223
229
|
|
|
224
230
|
/**
|
|
225
231
|
* Ray object creator.
|
|
226
232
|
* @function
|
|
227
|
-
* @param {
|
|
228
|
-
* @param {
|
|
229
|
-
* @returns {
|
|
233
|
+
* @param {Vec3} origin - The origin of the ray.
|
|
234
|
+
* @param {Vec3} direction - The direction of the ray.
|
|
235
|
+
* @returns {Ray}
|
|
230
236
|
*/
|
|
231
237
|
export function ray(origin, direction) {
|
|
232
238
|
return new Ray(origin, direction);
|
|
233
239
|
}
|
|
234
|
-
|
package/src/og/math/Vec2.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* @module og/math/Vec2
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
"use strict";
|
|
6
6
|
|
|
7
|
-
import { Vec3 } from
|
|
7
|
+
import { Vec3 } from "./Vec3.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Class represents a 3d vector.
|
|
@@ -13,9 +13,7 @@ import { Vec3 } from './Vec3.js';
|
|
|
13
13
|
* @param {number} [y] - Second value.
|
|
14
14
|
*/
|
|
15
15
|
export class Vec2 {
|
|
16
|
-
|
|
17
16
|
constructor(x, y) {
|
|
18
|
-
|
|
19
17
|
/**
|
|
20
18
|
* @public
|
|
21
19
|
* @type {number}
|
|
@@ -29,22 +27,32 @@ export class Vec2 {
|
|
|
29
27
|
this.y = y || 0.0;
|
|
30
28
|
}
|
|
31
29
|
/** @const */
|
|
32
|
-
static get UP() {
|
|
30
|
+
static get UP() {
|
|
31
|
+
return new Vec2(0, 1);
|
|
32
|
+
}
|
|
33
33
|
/** @const */
|
|
34
|
-
static get DOWN() {
|
|
34
|
+
static get DOWN() {
|
|
35
|
+
return new Vec2(0, -1);
|
|
36
|
+
}
|
|
35
37
|
/** @const */
|
|
36
|
-
static get RIGHT() {
|
|
38
|
+
static get RIGHT() {
|
|
39
|
+
return new Vec2(1, 0);
|
|
40
|
+
}
|
|
37
41
|
/** @const */
|
|
38
|
-
static get LEFT() {
|
|
42
|
+
static get LEFT() {
|
|
43
|
+
return new Vec2(-1, 0);
|
|
44
|
+
}
|
|
39
45
|
/** @const */
|
|
40
|
-
static get ZERO() {
|
|
46
|
+
static get ZERO() {
|
|
47
|
+
return new Vec2();
|
|
48
|
+
}
|
|
41
49
|
|
|
42
50
|
/**
|
|
43
51
|
* Returns summary vector.
|
|
44
52
|
* @static
|
|
45
|
-
* @param {
|
|
46
|
-
* @param {
|
|
47
|
-
* @returns {
|
|
53
|
+
* @param {math.Vec2} a - First vector.
|
|
54
|
+
* @param {math.Vec2} b - Second vector.
|
|
55
|
+
* @returns {math.Vec2} - Summary vector.
|
|
48
56
|
*/
|
|
49
57
|
static add(a, b) {
|
|
50
58
|
var res = new Vec2(a.x, a.y);
|
|
@@ -55,9 +63,9 @@ export class Vec2 {
|
|
|
55
63
|
/**
|
|
56
64
|
* Returns two vectors subtraction.
|
|
57
65
|
* @static
|
|
58
|
-
* @param {
|
|
59
|
-
* @param {
|
|
60
|
-
* @returns {
|
|
66
|
+
* @param {math.Vec2} a - First vector.
|
|
67
|
+
* @param {math.Vec2} b - Second vector.
|
|
68
|
+
* @returns {math.Vec2} - Vectors subtraction.
|
|
61
69
|
*/
|
|
62
70
|
static sub(a, b) {
|
|
63
71
|
var res = new Vec2(a.x, a.y);
|
|
@@ -68,9 +76,9 @@ export class Vec2 {
|
|
|
68
76
|
/**
|
|
69
77
|
* Returns scaled vector.
|
|
70
78
|
* @static
|
|
71
|
-
* @param {
|
|
79
|
+
* @param {math.Vec2} a - Input vector.
|
|
72
80
|
* @param {number} scale - Scale value.
|
|
73
|
-
* @returns {
|
|
81
|
+
* @returns {math.Vec2}
|
|
74
82
|
*/
|
|
75
83
|
static scale(a, scale) {
|
|
76
84
|
var res = new Vec2(a.x, a.y);
|
|
@@ -81,9 +89,9 @@ export class Vec2 {
|
|
|
81
89
|
/**
|
|
82
90
|
* Returns two vectors production.
|
|
83
91
|
* @static
|
|
84
|
-
* @param {
|
|
85
|
-
* @param {
|
|
86
|
-
* @returns {
|
|
92
|
+
* @param {math.Vec2} a - First vector.
|
|
93
|
+
* @param {math.Vec2} b - Second vector.
|
|
94
|
+
* @returns {math.Vec2}
|
|
87
95
|
*/
|
|
88
96
|
static mul(a, b) {
|
|
89
97
|
var res = new Vec2(a.x, a.y);
|
|
@@ -94,9 +102,9 @@ export class Vec2 {
|
|
|
94
102
|
/**
|
|
95
103
|
* Returns vector components division product one to another.
|
|
96
104
|
* @static
|
|
97
|
-
* @param {
|
|
98
|
-
* @param {
|
|
99
|
-
* @returns {
|
|
105
|
+
* @param {math.Vec2} a - First vector.
|
|
106
|
+
* @param {math.Vec2} b - Second vector.
|
|
107
|
+
* @returns {math.Vec2}
|
|
100
108
|
*/
|
|
101
109
|
static div(a, b) {
|
|
102
110
|
var res = new Vec2(a.x, a.y);
|
|
@@ -107,9 +115,9 @@ export class Vec2 {
|
|
|
107
115
|
/**
|
|
108
116
|
* Get projection of the first vector to the second.
|
|
109
117
|
* @static
|
|
110
|
-
* @param {
|
|
111
|
-
* @param {
|
|
112
|
-
* @returns {
|
|
118
|
+
* @param {math.Vec2} b - First vector.
|
|
119
|
+
* @param {math.Vec2} a - Second vector.
|
|
120
|
+
* @returns {math.Vec2}
|
|
113
121
|
*/
|
|
114
122
|
static proj_b_to_a(b, a) {
|
|
115
123
|
return a.scaleTo(a.dot(b) / a.dot(a));
|
|
@@ -118,8 +126,8 @@ export class Vec2 {
|
|
|
118
126
|
/**
|
|
119
127
|
* Gets angle between two vectors.
|
|
120
128
|
* @static
|
|
121
|
-
* @param {
|
|
122
|
-
* @param {
|
|
129
|
+
* @param {math.Vec2} a - First vector.
|
|
130
|
+
* @param {math.Vec2} b - Second vector.
|
|
123
131
|
* @returns {number}
|
|
124
132
|
*/
|
|
125
133
|
static angle(a, b) {
|
|
@@ -129,9 +137,9 @@ export class Vec2 {
|
|
|
129
137
|
/**
|
|
130
138
|
* Makes vectors normalized and orthogonal to each other.
|
|
131
139
|
* @static
|
|
132
|
-
* @param {
|
|
133
|
-
* @param {
|
|
134
|
-
* @returns {
|
|
140
|
+
* @param {math.Vec2} normal - Normal vector.
|
|
141
|
+
* @param {math.Vec2} tangent - Tangent vector.
|
|
142
|
+
* @returns {math.Vec2}
|
|
135
143
|
*/
|
|
136
144
|
static orthoNormalize(normal, tangent) {
|
|
137
145
|
normal = normal.norm();
|
|
@@ -142,7 +150,7 @@ export class Vec2 {
|
|
|
142
150
|
/**
|
|
143
151
|
* Converts to 3d vector, third value is 0.0.
|
|
144
152
|
* @public
|
|
145
|
-
* @returns {
|
|
153
|
+
* @returns {Vec3}
|
|
146
154
|
*/
|
|
147
155
|
toVector3() {
|
|
148
156
|
return new Vec3(this.x, this.y, 0);
|
|
@@ -151,7 +159,7 @@ export class Vec2 {
|
|
|
151
159
|
/**
|
|
152
160
|
* Returns clone vector.
|
|
153
161
|
* @public
|
|
154
|
-
* @returns {
|
|
162
|
+
* @returns {math.Vec2}
|
|
155
163
|
*/
|
|
156
164
|
clone() {
|
|
157
165
|
return new Vec2(this.x, this.y);
|
|
@@ -160,7 +168,7 @@ export class Vec2 {
|
|
|
160
168
|
/**
|
|
161
169
|
* Compares with vector. Returns true if it equals another.
|
|
162
170
|
* @public
|
|
163
|
-
* @param {
|
|
171
|
+
* @param {math.Vec2} p - Vector to compare.
|
|
164
172
|
* @returns {boolean}
|
|
165
173
|
*/
|
|
166
174
|
equal(p) {
|
|
@@ -169,8 +177,8 @@ export class Vec2 {
|
|
|
169
177
|
|
|
170
178
|
/**
|
|
171
179
|
* Copy input vector's values.
|
|
172
|
-
* @param {
|
|
173
|
-
* @returns {
|
|
180
|
+
* @param {math.Vec2} point2 - Vector to copy.
|
|
181
|
+
* @returns {math.Vec2}
|
|
174
182
|
*/
|
|
175
183
|
copy(point2) {
|
|
176
184
|
this.x = point2.x;
|
|
@@ -199,8 +207,8 @@ export class Vec2 {
|
|
|
199
207
|
/**
|
|
200
208
|
* Adds vector to the current.
|
|
201
209
|
* @public
|
|
202
|
-
* @param {
|
|
203
|
-
* @returns {
|
|
210
|
+
* @param {math.Vec2}
|
|
211
|
+
* @returns {math.Vec2}
|
|
204
212
|
*/
|
|
205
213
|
addA(v) {
|
|
206
214
|
this.x += v.x;
|
|
@@ -211,8 +219,8 @@ export class Vec2 {
|
|
|
211
219
|
/**
|
|
212
220
|
* Summarize two vectors.
|
|
213
221
|
* @public
|
|
214
|
-
* @param {
|
|
215
|
-
* @returns {
|
|
222
|
+
* @param {math.Vec2}
|
|
223
|
+
* @returns {math.Vec2}
|
|
216
224
|
*/
|
|
217
225
|
add(v) {
|
|
218
226
|
return new Vec2(this.x + v.x, this.y + v.y);
|
|
@@ -221,8 +229,8 @@ export class Vec2 {
|
|
|
221
229
|
/**
|
|
222
230
|
* Subtract vector from the current where results saved on the current instance.
|
|
223
231
|
* @public
|
|
224
|
-
* @param {
|
|
225
|
-
* @returns {
|
|
232
|
+
* @param {math.Vec2} v - Subtract vector.
|
|
233
|
+
* @returns {math.Vec2}
|
|
226
234
|
*/
|
|
227
235
|
subA(v) {
|
|
228
236
|
this.x -= v.x;
|
|
@@ -233,8 +241,8 @@ export class Vec2 {
|
|
|
233
241
|
/**
|
|
234
242
|
* Subtract vector from the current.
|
|
235
243
|
* @public
|
|
236
|
-
* @param {
|
|
237
|
-
* @returns {
|
|
244
|
+
* @param {math.Vec2} v - Subtract vector.
|
|
245
|
+
* @returns {math.Vec2}
|
|
238
246
|
*/
|
|
239
247
|
sub(v) {
|
|
240
248
|
return new Vec2(this.x - v.x, this.y - v.y);
|
|
@@ -244,7 +252,7 @@ export class Vec2 {
|
|
|
244
252
|
* Scale current vector.
|
|
245
253
|
* @public
|
|
246
254
|
* @param {number} scale - Scale value.
|
|
247
|
-
* @returns {
|
|
255
|
+
* @returns {math.Vec2}
|
|
248
256
|
*/
|
|
249
257
|
scale(scale) {
|
|
250
258
|
this.x *= scale;
|
|
@@ -256,7 +264,7 @@ export class Vec2 {
|
|
|
256
264
|
* Scale current vector to another instance.
|
|
257
265
|
* @public
|
|
258
266
|
* @param {number} scale - Scale value.
|
|
259
|
-
* @returns {
|
|
267
|
+
* @returns {math.Vec2}
|
|
260
268
|
*/
|
|
261
269
|
scaleTo(scale) {
|
|
262
270
|
return new Vec2(this.x * scale, this.y * scale);
|
|
@@ -265,8 +273,8 @@ export class Vec2 {
|
|
|
265
273
|
/**
|
|
266
274
|
* Multiply current vector object to another and store result in the current instance.
|
|
267
275
|
* @public
|
|
268
|
-
* @param {
|
|
269
|
-
* @returns {
|
|
276
|
+
* @param {math.Vec2} vec - Multiply vector.
|
|
277
|
+
* @returns {math.Vec2}
|
|
270
278
|
*/
|
|
271
279
|
mulA(vec) {
|
|
272
280
|
this.x *= vec.x;
|
|
@@ -277,8 +285,8 @@ export class Vec2 {
|
|
|
277
285
|
/**
|
|
278
286
|
* Multiply current vector object to another and returns new vector instance.
|
|
279
287
|
* @public
|
|
280
|
-
* @param {
|
|
281
|
-
* @returns {
|
|
288
|
+
* @param {math.Vec2} vec - Multiply vector.
|
|
289
|
+
* @returns {math.Vec2}
|
|
282
290
|
*/
|
|
283
291
|
mul(vec) {
|
|
284
292
|
return new Vec2(this.x * vec.x, this.y * vec.y);
|
|
@@ -287,8 +295,8 @@ export class Vec2 {
|
|
|
287
295
|
/**
|
|
288
296
|
* Divide current vector's components to another. Results stores in the current vector object.
|
|
289
297
|
* @public
|
|
290
|
-
* @param {
|
|
291
|
-
* @returns {
|
|
298
|
+
* @param {math.Vec2}
|
|
299
|
+
* @returns {math.Vec2}
|
|
292
300
|
*/
|
|
293
301
|
divA(vec) {
|
|
294
302
|
this.x /= vec.x;
|
|
@@ -299,7 +307,7 @@ export class Vec2 {
|
|
|
299
307
|
/**
|
|
300
308
|
* Gets vectors dot production.
|
|
301
309
|
* @public
|
|
302
|
-
* @param {
|
|
310
|
+
* @param {math.Vec2} v - Another vector.
|
|
303
311
|
* @returns {number}
|
|
304
312
|
*/
|
|
305
313
|
dot(v) {
|
|
@@ -319,8 +327,8 @@ export class Vec2 {
|
|
|
319
327
|
/**
|
|
320
328
|
* Gets vectors cross production.
|
|
321
329
|
* @public
|
|
322
|
-
* @param {
|
|
323
|
-
* @returns {
|
|
330
|
+
* @param {math.Vec2} v - Another vector.
|
|
331
|
+
* @returns {math.Vec2}
|
|
324
332
|
*/
|
|
325
333
|
cross(v) {
|
|
326
334
|
return this.x * v.y - this.y * v.x;
|
|
@@ -329,7 +337,7 @@ export class Vec2 {
|
|
|
329
337
|
/**
|
|
330
338
|
* Sets vector to zero.
|
|
331
339
|
* @public
|
|
332
|
-
* @returns {
|
|
340
|
+
* @returns {math.Vec2}
|
|
333
341
|
*/
|
|
334
342
|
clear() {
|
|
335
343
|
this.x = this.y = 0;
|
|
@@ -339,7 +347,7 @@ export class Vec2 {
|
|
|
339
347
|
/**
|
|
340
348
|
* Returns normalized vector.
|
|
341
349
|
* @public
|
|
342
|
-
* @returns {
|
|
350
|
+
* @returns {math.Vec2}
|
|
343
351
|
*/
|
|
344
352
|
normal() {
|
|
345
353
|
var res = new Vec2();
|
|
@@ -356,7 +364,7 @@ export class Vec2 {
|
|
|
356
364
|
/**
|
|
357
365
|
* Normalize current vector.
|
|
358
366
|
* @public
|
|
359
|
-
* @returns {
|
|
367
|
+
* @returns {math.Vec2}
|
|
360
368
|
*/
|
|
361
369
|
normalize() {
|
|
362
370
|
var length = 1.0 / this.length();
|
|
@@ -379,7 +387,7 @@ export class Vec2 {
|
|
|
379
387
|
/**
|
|
380
388
|
* Gets distance to point.
|
|
381
389
|
* @public
|
|
382
|
-
* @param {
|
|
390
|
+
* @param {math.Vec2} p - Distant point.
|
|
383
391
|
* @returns {number}
|
|
384
392
|
*/
|
|
385
393
|
distance(p) {
|
|
@@ -392,7 +400,7 @@ export class Vec2 {
|
|
|
392
400
|
* @public
|
|
393
401
|
* @param {number} x - Value X.
|
|
394
402
|
* @param {number} y - Value Y.
|
|
395
|
-
* @returns {
|
|
403
|
+
* @returns {math.Vec2}
|
|
396
404
|
*/
|
|
397
405
|
set(x, y) {
|
|
398
406
|
this.x = x;
|
|
@@ -403,7 +411,7 @@ export class Vec2 {
|
|
|
403
411
|
/**
|
|
404
412
|
* Negate current vector.
|
|
405
413
|
* @public
|
|
406
|
-
* @returns {
|
|
414
|
+
* @returns {math.Vec2}
|
|
407
415
|
*/
|
|
408
416
|
negate() {
|
|
409
417
|
this.x = -this.x;
|
|
@@ -414,7 +422,7 @@ export class Vec2 {
|
|
|
414
422
|
/**
|
|
415
423
|
* Negate current vector to another instance.
|
|
416
424
|
* @public
|
|
417
|
-
* @returns {
|
|
425
|
+
* @returns {math.Vec2}
|
|
418
426
|
*/
|
|
419
427
|
negateTo() {
|
|
420
428
|
return new Vec2(-this.x, -this.y);
|
|
@@ -423,9 +431,9 @@ export class Vec2 {
|
|
|
423
431
|
/**
|
|
424
432
|
* Gets projected point coordinates of the current vector on the ray.
|
|
425
433
|
* @public
|
|
426
|
-
* @param {
|
|
427
|
-
* @param {
|
|
428
|
-
* @returns {
|
|
434
|
+
* @param {math.Vec2} pos - Ray position.
|
|
435
|
+
* @param {math.Vec2} direction - Ray direction.
|
|
436
|
+
* @returns {math.Vec2}
|
|
429
437
|
*/
|
|
430
438
|
projToRay(pos, direction) {
|
|
431
439
|
var v = Vec2.proj_b_to_a(Vec2.sub(this, pos), direction);
|
|
@@ -436,7 +444,7 @@ export class Vec2 {
|
|
|
436
444
|
/**
|
|
437
445
|
* Gets angle between two vectors.
|
|
438
446
|
* @public
|
|
439
|
-
* @param {
|
|
447
|
+
* @param {math.Vec2} a - Another vector.
|
|
440
448
|
* @returns {number}
|
|
441
449
|
*/
|
|
442
450
|
angle(a) {
|
|
@@ -446,9 +454,9 @@ export class Vec2 {
|
|
|
446
454
|
/**
|
|
447
455
|
* Returns two vectors linear interpolation.
|
|
448
456
|
* @public
|
|
449
|
-
* @param {
|
|
457
|
+
* @param {math.Vec2} v2 - End vector.
|
|
450
458
|
* @param {number} l - Interpolate value.
|
|
451
|
-
* @returns {
|
|
459
|
+
* @returns {math.Vec2}
|
|
452
460
|
*/
|
|
453
461
|
lerp(v1, v2, l) {
|
|
454
462
|
var res = Vec2.clone(this);
|
|
@@ -462,17 +470,19 @@ export class Vec2 {
|
|
|
462
470
|
return res;
|
|
463
471
|
}
|
|
464
472
|
|
|
465
|
-
static get LERP_DELTA() {
|
|
473
|
+
static get LERP_DELTA() {
|
|
474
|
+
return 1e-6;
|
|
475
|
+
}
|
|
466
476
|
|
|
467
477
|
/**
|
|
468
478
|
* Spherically interpolates between two vectors.
|
|
469
|
-
* Interpolates between current and v2 vector by amount t. The difference between this and linear interpolation (aka, "lerp") is that
|
|
470
|
-
* the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated
|
|
479
|
+
* Interpolates between current and v2 vector by amount t. The difference between this and linear interpolation (aka, "lerp") is that
|
|
480
|
+
* the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated
|
|
471
481
|
* by the angle and its magnitude is interpolated between the magnitudes of from and to.
|
|
472
482
|
* @public
|
|
473
|
-
* @param {
|
|
483
|
+
* @param {math.Vec2} v2 -
|
|
474
484
|
* @param {number} t - The parameter t is clamped to the range [0, 1].
|
|
475
|
-
* @returns {
|
|
485
|
+
* @returns {math.Vec2}
|
|
476
486
|
*/
|
|
477
487
|
slerp(v2, t) {
|
|
478
488
|
var res = new Vec2();
|
|
@@ -488,7 +498,7 @@ export class Vec2 {
|
|
|
488
498
|
var omega, sinom, scale0, scale1;
|
|
489
499
|
var cosom = this.dot(v2);
|
|
490
500
|
|
|
491
|
-
if (
|
|
501
|
+
if (1.0 - cosom > Vec2.LERP_DELTA) {
|
|
492
502
|
omega = Math.acos(cosom);
|
|
493
503
|
sinom = Math.sin(omega);
|
|
494
504
|
scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
|
@@ -507,7 +517,7 @@ export class Vec2 {
|
|
|
507
517
|
* @function
|
|
508
518
|
* @param {number} [x] - First cvalue.
|
|
509
519
|
* @param {number} [y] - Second value.
|
|
510
|
-
* @returns {
|
|
520
|
+
* @returns {math.Vec2}
|
|
511
521
|
*/
|
|
512
522
|
export function vec2(x, y) {
|
|
513
523
|
return new Vec2(x, y);
|