@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/Line3.js
CHANGED
|
@@ -3,137 +3,138 @@
|
|
|
3
3
|
import * as math from '../math.js';
|
|
4
4
|
import { Vec3 } from './Vec3.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Line3.prototype.getMagnitude = function () {
|
|
12
|
-
return this.p0.distance(this.p1);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
Line3.prototype.getSphereIntersection = function (sphere) {
|
|
16
|
-
var p0 = this.p0,
|
|
17
|
-
p1 = this.p1;
|
|
18
|
-
|
|
19
|
-
var cx = sphere.x,
|
|
20
|
-
cy = sphere.y,
|
|
21
|
-
cz = sphere.z;
|
|
22
|
-
|
|
23
|
-
var px = p0.x,
|
|
24
|
-
py = p0.y,
|
|
25
|
-
pz = p0.z;
|
|
26
|
-
|
|
27
|
-
var vx = p1.x - px,
|
|
28
|
-
vy = p1.y - py,
|
|
29
|
-
vz = p1.z - pz;
|
|
30
|
-
|
|
31
|
-
var A = vx * vx + vy * vy + vz * vz,
|
|
32
|
-
B = 2.0 * (px * vx + py * vy + pz * vz - vx * cx - vy * cy - vz * cz),
|
|
33
|
-
C = px * px - 2 * px * cx + cx * cx + py * py - 2 * py * cy + cy * cy +
|
|
34
|
-
pz * pz - 2 * pz * cz + cz * cz - sphere.radius * sphere.radius;
|
|
35
|
-
var D = B * B - 4 * A * C;
|
|
36
|
-
|
|
37
|
-
if (D < 0) {
|
|
38
|
-
return null;
|
|
6
|
+
export class Line3 {
|
|
7
|
+
constructor(p0, p1) {
|
|
8
|
+
this.p0 = p0 || new Vec3();
|
|
9
|
+
this.p1 = p1 || new Vec3();
|
|
39
10
|
}
|
|
40
11
|
|
|
41
|
-
|
|
12
|
+
getMagnitude() {
|
|
13
|
+
return this.p0.distance(this.p1);
|
|
14
|
+
}
|
|
42
15
|
|
|
43
|
-
|
|
44
|
-
p0
|
|
45
|
-
|
|
46
|
-
p0.z * (1 - t1) + t1 * p1.z);
|
|
16
|
+
getSphereIntersection(sphere) {
|
|
17
|
+
var p0 = this.p0,
|
|
18
|
+
p1 = this.p1;
|
|
47
19
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
20
|
+
var cx = sphere.x,
|
|
21
|
+
cy = sphere.y,
|
|
22
|
+
cz = sphere.z;
|
|
51
23
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
p0.y * (1 - t2) + t2 * p1.y,
|
|
56
|
-
p0.z * (1 - t2) + t2 * p1.z);
|
|
24
|
+
var px = p0.x,
|
|
25
|
+
py = p0.y,
|
|
26
|
+
pz = p0.z;
|
|
57
27
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
28
|
+
var vx = p1.x - px,
|
|
29
|
+
vy = p1.y - py,
|
|
30
|
+
vz = p1.z - pz;
|
|
62
31
|
|
|
63
|
-
|
|
64
|
-
|
|
32
|
+
var A = vx * vx + vy * vy + vz * vz,
|
|
33
|
+
B = 2.0 * (px * vx + py * vy + pz * vz - vx * cx - vy * cy - vz * cz),
|
|
34
|
+
C = px * px - 2 * px * cx + cx * cx + py * py - 2 * py * cy + cy * cy +
|
|
35
|
+
pz * pz - 2 * pz * cz + cz * cz - sphere.radius * sphere.radius;
|
|
36
|
+
var D = B * B - 4 * A * C;
|
|
65
37
|
|
|
66
|
-
|
|
38
|
+
if (D < 0) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
67
41
|
|
|
68
|
-
|
|
69
|
-
p43 = line.p1.sub(line.p0);
|
|
42
|
+
var t1 = (-B - Math.Sqrt(D)) / (2.0 * A);
|
|
70
43
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
44
|
+
var solution1 = new Vec3(
|
|
45
|
+
p0.x * (1 - t1) + t1 * p1.x,
|
|
46
|
+
p0.y * (1 - t1) + t1 * p1.y,
|
|
47
|
+
p0.z * (1 - t1) + t1 * p1.z);
|
|
74
48
|
|
|
75
|
-
|
|
49
|
+
if (D == 0) {
|
|
50
|
+
return solution1;
|
|
51
|
+
}
|
|
76
52
|
|
|
77
|
-
|
|
78
|
-
|
|
53
|
+
var t2 = (-B + Math.Sqrt(D)) / (2.0 * A);
|
|
54
|
+
var solution2 = new Vec3(
|
|
55
|
+
p0.x * (1 - t2) + t2 * p1.x,
|
|
56
|
+
p0.y * (1 - t2) + t2 * p1.y,
|
|
57
|
+
p0.z * (1 - t2) + t2 * p1.z);
|
|
58
|
+
|
|
59
|
+
// prefer a solution that's on the line segment itself
|
|
60
|
+
if (Math.Abs(t1 - 0.5) < Math.abs(t2 - 0.5)) {
|
|
61
|
+
return [solution1, solution2];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return [solution2, solution1];
|
|
79
65
|
}
|
|
80
66
|
|
|
81
|
-
|
|
82
|
-
d4321 = p43.x * p21.x + p43.y * p21.y + p43.z * p21.z,
|
|
83
|
-
d1321 = p13.x * p21.x + p13.y * p21.y + p13.z * p21.z,
|
|
84
|
-
d4343 = p43.x * p43.x + p43.y * p43.y + p43.z * p43.z,
|
|
85
|
-
d2121 = p21.x * p21.x + p21.y * p21.y + p21.z * p21.z;
|
|
67
|
+
intersects(line, res, res2) {
|
|
86
68
|
|
|
87
|
-
|
|
69
|
+
let p13 = this.p0.sub(line.p0),
|
|
70
|
+
p43 = line.p1.sub(line.p0);
|
|
88
71
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
72
|
+
if (Math.abs(p43.x) < math.EPSILON10 && Math.abs(p43.y) < math.EPSILON10 && Math.abs(p43.z) < math.EPSILON10) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
92
75
|
|
|
93
|
-
|
|
76
|
+
let p21 = this.p1.sub(this.p0);
|
|
94
77
|
|
|
95
|
-
|
|
78
|
+
if (Math.abs(p21.x) < math.EPSILON10 && Math.abs(p21.y) < math.EPSILON10 && Math.abs(p21.z) < math.EPSILON10) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
96
81
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
82
|
+
let d1343 = p13.x * p43.x + p13.y * p43.y + p13.z * p43.z,
|
|
83
|
+
d4321 = p43.x * p21.x + p43.y * p21.y + p43.z * p21.z,
|
|
84
|
+
d1321 = p13.x * p21.x + p13.y * p21.y + p13.z * p21.z,
|
|
85
|
+
d4343 = p43.x * p43.x + p43.y * p43.y + p43.z * p43.z,
|
|
86
|
+
d2121 = p21.x * p21.x + p21.y * p21.y + p21.z * p21.z;
|
|
100
87
|
|
|
101
|
-
|
|
88
|
+
let denom = d2121 * d4343 - d4321 * d4321;
|
|
102
89
|
|
|
103
|
-
|
|
90
|
+
if (Math.abs(denom) < math.EPSILON10) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
104
93
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
94
|
+
let numer = d1343 * d4321 - d1321 * d4343;
|
|
95
|
+
|
|
96
|
+
let mua = numer / denom;
|
|
97
|
+
|
|
98
|
+
res.x = this.p0.x + mua * p21.x;
|
|
99
|
+
res.y = this.p0.y + mua * p21.y;
|
|
100
|
+
res.z = this.p0.z + mua * p21.z;
|
|
101
|
+
|
|
102
|
+
if (res2) {
|
|
103
|
+
|
|
104
|
+
let mub = (d1343 + d4321 * mua) / d4343;
|
|
105
|
+
|
|
106
|
+
res2.x = line.p0.x + mub * p43.x;
|
|
107
|
+
res2.y = line.p0.y + mub * p43.y;
|
|
108
|
+
res2.z = line.p0.z + mub * p43.z;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return true;
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
|
|
111
|
-
};
|
|
114
|
+
getNearestDistancePoint(point, res) {
|
|
112
115
|
|
|
113
|
-
|
|
116
|
+
let p0 = this.p0,
|
|
117
|
+
p1 = this.p1;
|
|
114
118
|
|
|
115
|
-
|
|
116
|
-
p1 = this.p1;
|
|
119
|
+
let mag = this.getMagnitude();
|
|
117
120
|
|
|
118
|
-
|
|
121
|
+
let u =
|
|
122
|
+
(
|
|
123
|
+
((point.x - p0.x) * (p1.x - p0.x)) +
|
|
124
|
+
((point.y - p0.y) * (p1.y - p0.y)) +
|
|
125
|
+
((point.z - p0.z) * (p1.z - p0.z))
|
|
126
|
+
) /
|
|
127
|
+
(mag * mag);
|
|
119
128
|
|
|
120
|
-
|
|
121
|
-
(
|
|
122
|
-
|
|
123
|
-
((point.y - p0.y) * (p1.y - p0.y)) +
|
|
124
|
-
((point.z - p0.z) * (p1.z - p0.z))
|
|
125
|
-
) /
|
|
126
|
-
(mag * mag);
|
|
129
|
+
res.x = p0.x + u * (p1.x - p0.x);
|
|
130
|
+
res.y = p0.y + u * (p1.y - p0.y);
|
|
131
|
+
res.z = p0.z + u * (p1.z - p0.z);
|
|
127
132
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
if (u < 0.0 || u > 1.0) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
131
136
|
|
|
132
|
-
|
|
133
|
-
return false;
|
|
137
|
+
return true;
|
|
134
138
|
}
|
|
135
139
|
|
|
136
|
-
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export { Line3 };
|
|
140
|
+
}
|
package/src/og/math/Mat3.js
CHANGED
|
@@ -2,142 +2,155 @@
|
|
|
2
2
|
* @module og/math/Mat3
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
"use strict";
|
|
6
6
|
|
|
7
|
-
import { Mat4 } from
|
|
8
|
-
import { Vec3 } from
|
|
7
|
+
import { Mat4 } from "./Mat4.js";
|
|
8
|
+
import { Vec3 } from "./Vec3.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Class represents a 3x3 matrix.
|
|
12
12
|
* @class
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
export class Mat3 {
|
|
15
|
+
constructor() {
|
|
16
|
+
/**
|
|
17
|
+
* A 3x3 matrix, indexable as a column-major order array.
|
|
18
|
+
* @public
|
|
19
|
+
* @type {Array.<number>}
|
|
20
|
+
*/
|
|
21
|
+
this._m = new Array(9);
|
|
22
|
+
}
|
|
23
|
+
|
|
15
24
|
/**
|
|
16
|
-
*
|
|
25
|
+
* Sets column-major order array matrix.
|
|
17
26
|
* @public
|
|
18
|
-
* @
|
|
27
|
+
* @param {Array.<number>} m - Matrix array.
|
|
28
|
+
* @returns {Mat3}
|
|
19
29
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
set(m) {
|
|
31
|
+
this._m[0] = m[0];
|
|
32
|
+
this._m[1] = m[1];
|
|
33
|
+
this._m[2] = m[2];
|
|
34
|
+
this._m[3] = m[3];
|
|
35
|
+
this._m[4] = m[4];
|
|
36
|
+
this._m[5] = m[5];
|
|
37
|
+
this._m[6] = m[6];
|
|
38
|
+
this._m[7] = m[7];
|
|
39
|
+
this._m[8] = m[8];
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
28
42
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Mat3.prototype.set = function (m) {
|
|
40
|
-
this._m[0] = m[0];
|
|
41
|
-
this._m[1] = m[1];
|
|
42
|
-
this._m[2] = m[2];
|
|
43
|
-
this._m[3] = m[3];
|
|
44
|
-
this._m[4] = m[4];
|
|
45
|
-
this._m[5] = m[5];
|
|
46
|
-
this._m[6] = m[6];
|
|
47
|
-
this._m[7] = m[7];
|
|
48
|
-
this._m[8] = m[8];
|
|
49
|
-
return this;
|
|
50
|
-
};
|
|
43
|
+
/**
|
|
44
|
+
* Duplicates a Mat3 instance.
|
|
45
|
+
* @public
|
|
46
|
+
* @returns {Mat3}
|
|
47
|
+
*/
|
|
48
|
+
clone() {
|
|
49
|
+
var res = new Mat3();
|
|
50
|
+
res.set(this);
|
|
51
|
+
return res;
|
|
52
|
+
}
|
|
51
53
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
54
|
+
/**
|
|
55
|
+
* Copy matrix.
|
|
56
|
+
* @public
|
|
57
|
+
* @param {Mat3} a - Matrix to copy.
|
|
58
|
+
* @returns {Mat3}
|
|
59
|
+
*/
|
|
60
|
+
copy(a) {
|
|
61
|
+
return this.set(a._m);
|
|
62
|
+
}
|
|
62
63
|
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Creates trasposed matrix from the current.
|
|
66
|
+
* @public
|
|
67
|
+
* @returns {Mat3}
|
|
68
|
+
*/
|
|
69
|
+
transposeTo() {
|
|
70
|
+
var res = new Mat3();
|
|
71
|
+
var m = this._m;
|
|
72
|
+
res._m[0] = m[0];
|
|
73
|
+
res._m[1] = m[3];
|
|
74
|
+
res._m[2] = m[6];
|
|
75
|
+
res._m[3] = m[1];
|
|
76
|
+
res._m[4] = m[4];
|
|
77
|
+
res._m[5] = m[7];
|
|
78
|
+
res._m[6] = m[2];
|
|
79
|
+
res._m[7] = m[5];
|
|
80
|
+
res._m[8] = m[8];
|
|
81
|
+
return res;
|
|
82
|
+
}
|
|
72
83
|
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Sets matrix to identity.
|
|
86
|
+
* @public
|
|
87
|
+
* @returns {Mat3}
|
|
88
|
+
*/
|
|
89
|
+
setIdentity() {
|
|
90
|
+
this._m[0] = 1;
|
|
91
|
+
this._m[1] = 0;
|
|
92
|
+
this._m[2] = 0;
|
|
93
|
+
this._m[3] = 0;
|
|
94
|
+
this._m[4] = 1;
|
|
95
|
+
this._m[5] = 0;
|
|
96
|
+
this._m[6] = 0;
|
|
97
|
+
this._m[7] = 0;
|
|
98
|
+
this._m[8] = 1;
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
86
101
|
|
|
87
|
-
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Multiply to 3d vector.
|
|
104
|
+
* @public
|
|
105
|
+
* @params {Vec3} p - 3d vector.
|
|
106
|
+
* @returns {Vec3}
|
|
107
|
+
*/
|
|
108
|
+
mulVec(p) {
|
|
109
|
+
var d = p.x,
|
|
110
|
+
e = p.y,
|
|
111
|
+
g = p.z;
|
|
112
|
+
var m = this._m;
|
|
113
|
+
return new Vec3(
|
|
114
|
+
m[0] * d + m[3] * e + m[6] * g,
|
|
115
|
+
m[1] * d + m[4] * e + m[7] * g,
|
|
116
|
+
m[2] * d + m[5] * e + m[8] * g
|
|
117
|
+
);
|
|
118
|
+
}
|
|
98
119
|
|
|
99
|
-
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Converts to 4x4 matrix.
|
|
122
|
+
* @public
|
|
123
|
+
* @returns {Mat4}
|
|
124
|
+
*/
|
|
125
|
+
toMatrix4() {
|
|
126
|
+
var res = new Mat4();
|
|
127
|
+
var b = res._m;
|
|
128
|
+
var a = this._m;
|
|
129
|
+
b[0] = a[0];
|
|
130
|
+
b[1] = a[1];
|
|
131
|
+
b[2] = a[2];
|
|
132
|
+
b[3] = 0;
|
|
133
|
+
b[4] = a[3];
|
|
134
|
+
b[5] = a[4];
|
|
135
|
+
b[6] = a[5];
|
|
136
|
+
b[7] = 0;
|
|
137
|
+
b[8] = a[6];
|
|
138
|
+
b[9] = a[7];
|
|
139
|
+
b[10] = a[8];
|
|
140
|
+
b[11] = 0;
|
|
141
|
+
b[12] = 0;
|
|
142
|
+
b[13] = 0;
|
|
143
|
+
b[14] = 0;
|
|
144
|
+
b[15] = 1;
|
|
145
|
+
return res;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
114
148
|
|
|
115
149
|
/**
|
|
116
|
-
*
|
|
117
|
-
* @
|
|
118
|
-
* @
|
|
150
|
+
* Mat3 factory.
|
|
151
|
+
* @static
|
|
152
|
+
* @return {Mat3}
|
|
119
153
|
*/
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
var a = this._m;
|
|
124
|
-
b[0] = a[0];
|
|
125
|
-
b[1] = a[1];
|
|
126
|
-
b[2] = a[2];
|
|
127
|
-
b[3] = 0;
|
|
128
|
-
b[4] = a[3];
|
|
129
|
-
b[5] = a[4];
|
|
130
|
-
b[6] = a[5];
|
|
131
|
-
b[7] = 0;
|
|
132
|
-
b[8] = a[6];
|
|
133
|
-
b[9] = a[7];
|
|
134
|
-
b[10] = a[8];
|
|
135
|
-
b[11] = 0;
|
|
136
|
-
b[12] = 0;
|
|
137
|
-
b[13] = 0;
|
|
138
|
-
b[14] = 0;
|
|
139
|
-
b[15] = 1;
|
|
140
|
-
return res;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
export { Mat3 };
|
|
154
|
+
export function mat3() {
|
|
155
|
+
return new Mat3();
|
|
156
|
+
}
|