@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/Ray.js
CHANGED
|
@@ -2,230 +2,238 @@
|
|
|
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
|
+
constructor(origin, direction) {
|
|
18
|
+
/**
|
|
19
|
+
* The origin of the ray.
|
|
20
|
+
* @public
|
|
21
|
+
* @type {Vec3}
|
|
22
|
+
*/
|
|
23
|
+
this.origin = origin || new Vec3();
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The direction of the ray.
|
|
27
|
+
* @public
|
|
28
|
+
* @type {Vec3}
|
|
29
|
+
*/
|
|
30
|
+
this.direction = direction || new Vec3();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @const */
|
|
34
|
+
static get OUTSIDE() {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @const */
|
|
39
|
+
static get INSIDE() {
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
/** @const */
|
|
43
|
+
static get INPLANE() {
|
|
44
|
+
return 2;
|
|
45
|
+
}
|
|
46
|
+
/** @const */
|
|
47
|
+
static get AWAY() {
|
|
48
|
+
return 3;
|
|
49
|
+
}
|
|
17
50
|
|
|
18
51
|
/**
|
|
19
|
-
*
|
|
52
|
+
* Sets a ray parameters.
|
|
20
53
|
* @public
|
|
21
|
-
* @
|
|
54
|
+
* @param {Vec3} origin - The origin of the ray.
|
|
55
|
+
* @param {Vec3} direction - The direction of the ray.
|
|
56
|
+
* @returns {Ray}
|
|
22
57
|
*/
|
|
23
|
-
|
|
58
|
+
set(origin, direction) {
|
|
59
|
+
this.origin = origin;
|
|
60
|
+
this.direction = direction;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
24
63
|
|
|
25
64
|
/**
|
|
26
|
-
*
|
|
65
|
+
* Computes the point along the ray on the distance.
|
|
27
66
|
* @public
|
|
28
|
-
* @
|
|
67
|
+
* @param {number} distance - Point distance.
|
|
68
|
+
* @returns {Vec3}
|
|
29
69
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
70
|
+
getPoint(distance) {
|
|
71
|
+
return Vec3.add(this.origin, this.direction.scaleTo(distance));
|
|
72
|
+
}
|
|
32
73
|
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Returns ray hit a triange result.
|
|
76
|
+
* @public
|
|
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,
|
|
82
|
+
* 2 - og.Ray.INPLANE and 3 - og.Ray.AWAY(ray goes away from triangle).
|
|
83
|
+
*/
|
|
84
|
+
hitTriangle(v0, v1, v2, res, normal) {
|
|
85
|
+
var u = v1.sub(v0);
|
|
86
|
+
var v = v2.sub(v0);
|
|
87
|
+
var n = u.cross(v);
|
|
88
|
+
|
|
89
|
+
var w0 = this.origin.sub(v0);
|
|
90
|
+
var a = -n.dot(w0);
|
|
91
|
+
var b = n.dot(this.direction);
|
|
92
|
+
|
|
93
|
+
// ray is parallel to triangle plane
|
|
94
|
+
if (Math.abs(b) < math.EPSILON10) {
|
|
95
|
+
if (a === 0) {
|
|
96
|
+
res.copy(this.origin);
|
|
97
|
+
// ray lies in triangle plane
|
|
98
|
+
return Ray.INPLANE;
|
|
99
|
+
} else {
|
|
100
|
+
// ray disjoint from plane
|
|
101
|
+
return Ray.OUTSIDE;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
43
104
|
|
|
44
|
-
|
|
45
|
-
Ray.OUTSIDE = 0;
|
|
46
|
-
/** @const */
|
|
47
|
-
Ray.INSIDE = 1;
|
|
48
|
-
/** @const */
|
|
49
|
-
Ray.INPLANE = 2;
|
|
50
|
-
/** @const */
|
|
51
|
-
Ray.AWAY = 3;
|
|
105
|
+
var r = a / b;
|
|
52
106
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
* @public
|
|
56
|
-
* @param {og.Vec3} origin - The origin of the ray.
|
|
57
|
-
* @param {og.Vec3} direction - The direction of the ray.
|
|
58
|
-
* @returns {og.Ray}
|
|
59
|
-
*/
|
|
60
|
-
Ray.prototype.set = function (origin, direction) {
|
|
61
|
-
this.origin = origin;
|
|
62
|
-
this.direction = direction;
|
|
63
|
-
return this;
|
|
64
|
-
};
|
|
107
|
+
// intersect point of ray and plane
|
|
108
|
+
res.copy(this.origin.add(this.direction.scaleTo(r)));
|
|
65
109
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* @returns {og.Vec3}
|
|
71
|
-
*/
|
|
72
|
-
Ray.prototype.getPoint = function (distance) {
|
|
73
|
-
return Vec3.add(this.origin, this.direction.scaleTo(distance));
|
|
74
|
-
};
|
|
110
|
+
// ray goes away from triangle
|
|
111
|
+
if (r < 0.0) {
|
|
112
|
+
return Ray.AWAY;
|
|
113
|
+
}
|
|
75
114
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
var u = v1.sub(v0);
|
|
88
|
-
var v = v2.sub(v0);
|
|
89
|
-
var n = u.cross(v);
|
|
90
|
-
|
|
91
|
-
var w0 = this.origin.sub(v0);
|
|
92
|
-
var a = -n.dot(w0);
|
|
93
|
-
var b = n.dot(this.direction);
|
|
94
|
-
|
|
95
|
-
// ray is parallel to triangle plane
|
|
96
|
-
if (Math.abs(b) < math.EPSILON10) {
|
|
97
|
-
if (a === 0) {
|
|
98
|
-
res.copy(this.origin);
|
|
99
|
-
// ray lies in triangle plane
|
|
100
|
-
return Ray.INPLANE;
|
|
101
|
-
} else {
|
|
102
|
-
// ray disjoint from plane
|
|
115
|
+
// is res point inside the triangle?
|
|
116
|
+
var uu = u.dot(u);
|
|
117
|
+
var uv = u.dot(v);
|
|
118
|
+
var vv = v.dot(v);
|
|
119
|
+
var w = res.sub(v0);
|
|
120
|
+
var wu = w.dot(u);
|
|
121
|
+
var wv = w.dot(v);
|
|
122
|
+
var D = uv * uv - uu * vv;
|
|
123
|
+
|
|
124
|
+
var s = (uv * wv - vv * wu) / D;
|
|
125
|
+
if (s < 0.0 || s > 1.0) {
|
|
103
126
|
return Ray.OUTSIDE;
|
|
104
127
|
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
var r = a / b;
|
|
108
128
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (r < 0.0) {
|
|
114
|
-
return Ray.AWAY;
|
|
115
|
-
}
|
|
129
|
+
var t = (uv * wu - uu * wv) / D;
|
|
130
|
+
if (t < 0.0 || s + t > 1.0) {
|
|
131
|
+
return Ray.OUTSIDE;
|
|
132
|
+
}
|
|
116
133
|
|
|
117
|
-
|
|
118
|
-
var uu = u.dot(u);
|
|
119
|
-
var uv = u.dot(v);
|
|
120
|
-
var vv = v.dot(v);
|
|
121
|
-
var w = res.sub(v0);
|
|
122
|
-
var wu = w.dot(u);
|
|
123
|
-
var wv = w.dot(v);
|
|
124
|
-
var D = uv * uv - uu * vv;
|
|
125
|
-
|
|
126
|
-
var s = (uv * wv - vv * wu) / D;
|
|
127
|
-
if (s < 0.0 || s > 1.0) {
|
|
128
|
-
return Ray.OUTSIDE;
|
|
134
|
+
return Ray.INSIDE;
|
|
129
135
|
}
|
|
130
136
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
/**
|
|
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.
|
|
139
|
+
* @public
|
|
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.
|
|
144
|
+
* @returns {number}
|
|
145
|
+
*/
|
|
146
|
+
hitPlane(v0, v1, v2, res) {
|
|
147
|
+
var u = Vec3.sub(v1, v0);
|
|
148
|
+
var v = Vec3.sub(v2, v0);
|
|
149
|
+
var n = u.cross(v);
|
|
150
|
+
|
|
151
|
+
var w0 = Vec3.sub(this.origin, v0);
|
|
152
|
+
var a = -n.dot(w0);
|
|
153
|
+
var b = n.dot(this.direction);
|
|
154
|
+
|
|
155
|
+
// ray is parallel to the plane
|
|
156
|
+
if (Math.abs(b) < math.EPSILON10) {
|
|
157
|
+
if (a === 0) {
|
|
158
|
+
return Ray.OUTSIDE;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
135
161
|
|
|
136
|
-
|
|
137
|
-
};
|
|
162
|
+
var r = a / b;
|
|
138
163
|
|
|
139
|
-
|
|
140
|
-
* Gets a ray hit a plane result. If the ray cross the plane returns 1 - og.Ray.INSIDE otherwise returns 0 - og.Ray.OUTSIDE.
|
|
141
|
-
* @public
|
|
142
|
-
* @param {og.Vec3} v0 - First plane point.
|
|
143
|
-
* @param {og.Vec3} v1 - Second plane point.
|
|
144
|
-
* @param {og.Vec3} v2 - Third plane point.
|
|
145
|
-
* @param {og.Vec3} res - Hit point object pointer that stores hit result.
|
|
146
|
-
* @returns {number}
|
|
147
|
-
*/
|
|
148
|
-
Ray.prototype.hitPlane = function (v0, v1, v2, res) {
|
|
149
|
-
var u = Vec3.sub(v1, v0);
|
|
150
|
-
var v = Vec3.sub(v2, v0);
|
|
151
|
-
var n = u.cross(v);
|
|
152
|
-
|
|
153
|
-
var w0 = Vec3.sub(this.origin, v0);
|
|
154
|
-
var a = -n.dot(w0);
|
|
155
|
-
var b = n.dot(this.direction);
|
|
156
|
-
|
|
157
|
-
// ray is parallel to the plane
|
|
158
|
-
if (Math.abs(b) < math.EPSILON10) {
|
|
159
|
-
if (a === 0) {
|
|
164
|
+
if (r < 0) {
|
|
160
165
|
return Ray.OUTSIDE;
|
|
161
166
|
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
var r = a / b;
|
|
165
|
-
|
|
166
|
-
if (r < 0) {
|
|
167
|
-
return Ray.OUTSIDE;
|
|
168
|
-
}
|
|
169
167
|
|
|
170
|
-
|
|
168
|
+
var d = this.direction.scaleTo(r);
|
|
171
169
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
170
|
+
// intersect point of ray and plane
|
|
171
|
+
res.x = this.origin.x + d.x;
|
|
172
|
+
res.y = this.origin.y + d.y;
|
|
173
|
+
res.z = this.origin.z + d.z;
|
|
176
174
|
|
|
177
|
-
|
|
178
|
-
}
|
|
175
|
+
return Ray.INSIDE;
|
|
176
|
+
}
|
|
179
177
|
|
|
180
|
-
/**
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
let pc = c.projToRay(o, vpc);
|
|
200
|
-
var lc = Vec3.sub(pc, c).length();
|
|
201
|
-
let dist = Math.sqrt(r * r - lc * lc);
|
|
202
|
-
let di1 = dist - Vec3.sub(pc, o).length();
|
|
203
|
-
let intersection = Vec3.add(o, d.scaleTo(di1));
|
|
204
|
-
return intersection;
|
|
205
|
-
} else {
|
|
206
|
-
let pc = c.projToRay(o, d);
|
|
207
|
-
var cpcl = Vec3.sub(c, pc).length();
|
|
208
|
-
if (cpcl > sphere.radius) {
|
|
209
|
-
return null;
|
|
210
|
-
} else {
|
|
211
|
-
let dist = Math.sqrt(r * r - cpcl * cpcl);
|
|
212
|
-
let di1;
|
|
213
|
-
pc.subA(o);
|
|
214
|
-
if (vpc.length() > r) {
|
|
215
|
-
di1 = pc.length() - dist;
|
|
216
|
-
} else {
|
|
217
|
-
di1 = pc.length() + dist;
|
|
178
|
+
/**
|
|
179
|
+
* Returns a ray hit sphere coordiante. If there isn't hit returns null.
|
|
180
|
+
* @public
|
|
181
|
+
* @param {Sphere} sphere - Sphere object.
|
|
182
|
+
* @returns {Vec3}
|
|
183
|
+
*/
|
|
184
|
+
hitSphere(sphere) {
|
|
185
|
+
var r = sphere.radius,
|
|
186
|
+
c = sphere.center,
|
|
187
|
+
o = this.origin,
|
|
188
|
+
d = this.direction;
|
|
189
|
+
var vpc = Vec3.sub(c, o);
|
|
190
|
+
if (vpc.dot(d) < 0) {
|
|
191
|
+
var l = vpc.length();
|
|
192
|
+
if (l > r) {
|
|
193
|
+
return null;
|
|
194
|
+
} else if (l === r) {
|
|
195
|
+
return o.clone();
|
|
218
196
|
}
|
|
197
|
+
let pc = c.projToRay(o, vpc);
|
|
198
|
+
var lc = Vec3.sub(pc, c).length();
|
|
199
|
+
let dist = Math.sqrt(r * r - lc * lc);
|
|
200
|
+
let di1 = dist - Vec3.sub(pc, o).length();
|
|
219
201
|
let intersection = Vec3.add(o, d.scaleTo(di1));
|
|
220
202
|
return intersection;
|
|
203
|
+
} else {
|
|
204
|
+
let pc = c.projToRay(o, d);
|
|
205
|
+
var cpcl = Vec3.sub(c, pc).length();
|
|
206
|
+
if (cpcl > sphere.radius) {
|
|
207
|
+
return null;
|
|
208
|
+
} else {
|
|
209
|
+
let dist = Math.sqrt(r * r - cpcl * cpcl);
|
|
210
|
+
let di1;
|
|
211
|
+
pc.subA(o);
|
|
212
|
+
if (vpc.length() > r) {
|
|
213
|
+
di1 = pc.length() - dist;
|
|
214
|
+
} else {
|
|
215
|
+
di1 = pc.length() + dist;
|
|
216
|
+
}
|
|
217
|
+
let intersection = Vec3.add(o, d.scaleTo(di1));
|
|
218
|
+
return intersection;
|
|
219
|
+
}
|
|
221
220
|
}
|
|
222
221
|
}
|
|
223
|
-
};
|
|
224
222
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
223
|
+
hitBox(box) {
|
|
224
|
+
//
|
|
225
|
+
// TODO
|
|
226
|
+
//
|
|
227
|
+
}
|
|
228
|
+
}
|
|
230
229
|
|
|
231
|
-
|
|
230
|
+
/**
|
|
231
|
+
* Ray object creator.
|
|
232
|
+
* @function
|
|
233
|
+
* @param {Vec3} origin - The origin of the ray.
|
|
234
|
+
* @param {Vec3} direction - The direction of the ray.
|
|
235
|
+
* @returns {Ray}
|
|
236
|
+
*/
|
|
237
|
+
export function ray(origin, direction) {
|
|
238
|
+
return new Ray(origin, direction);
|
|
239
|
+
}
|