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