@openglobus/og 0.11.8 → 0.12.0
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/css/og.css +2 -0
- package/package.json +1 -1
- package/src/og/Globe.js +18 -6
- package/src/og/camera/Camera.js +70 -79
- package/src/og/camera/PlanetCamera.js +25 -30
- package/src/og/control/DebugInfo.js +2 -2
- package/src/og/control/EarthNavigation.js +26 -17
- package/src/og/control/MouseNavigation.js +11 -13
- package/src/og/control/MouseWheelZoomControl.js +5 -5
- package/src/og/control/Sun.js +3 -3
- package/src/og/entity/Entity.js +742 -742
- package/src/og/entity/GeoObjectHandler.js +102 -117
- package/src/og/entity/LabelHandler.js +2 -1
- package/src/og/layer/XYZ.js +20 -21
- package/src/og/math/Vec3.js +18 -2
- package/src/og/quadTree/Node.js +48 -93
- package/src/og/quadTree/quadTree.js +1 -1
- package/src/og/renderer/Renderer.js +3 -5
- package/src/og/scene/Planet.js +105 -118
- package/src/og/segment/Segment.js +57 -136
- package/src/og/shaders/drawnode.js +132 -221
- package/src/og/terrain/EmptyTerrain.js +3 -2
- package/src/og/terrain/GlobusTerrain.js +2 -0
- package/src/og/utils/Loader.js +1 -1
- package/src/og/utils/PlainSegmentWorker.js +0 -13
- package/src/og/webgl/Handler.js +13 -9
package/css/og.css
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openglobus/og",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "[OpenGlobus](http://www.openglobus.org/) is a javascript library designed to display interactive 3d maps and planets with map tiles, imagery and vector data, markers and 3d objects. It uses the WebGL technology, open source and completely free.",
|
|
5
5
|
"directories": {
|
|
6
6
|
"example": "./sandbox"
|
package/src/og/Globe.js
CHANGED
|
@@ -66,6 +66,7 @@ const PLANET_NAME_PREFIX = "globus_planet_";
|
|
|
66
66
|
* @param {Number} [options.maxEqualZoomAltitude=15000000.0] - Maximal altitude since segments on the screen bacame the same zoom level
|
|
67
67
|
* @param {Number} [options.minEqualZoomAltitude=10000.0] - Minimal altitude since segments on the screen bacame the same zoom level
|
|
68
68
|
* @param {Number} [options.minEqualZoomCameraSlope=0.8] - Minimal camera slope above te globe where segments on the screen bacame the same zoom level
|
|
69
|
+
* @param {Number} [options.loadingBatchSize=12] -
|
|
69
70
|
*/
|
|
70
71
|
|
|
71
72
|
class Globe {
|
|
@@ -97,7 +98,16 @@ class Globe {
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
this.div.appendChild(this._canvas);
|
|
100
|
-
this.div.classList.add("ogViewport");
|
|
101
|
+
this.div.classList.add("ogViewport");
|
|
102
|
+
|
|
103
|
+
document.addEventListener("visibilitychange", () => {
|
|
104
|
+
if (document.visibilityState === 'visible') {
|
|
105
|
+
this.renderer.handler.start();
|
|
106
|
+
this.renderer && this.renderer.resize();
|
|
107
|
+
} else {
|
|
108
|
+
this.renderer.handler.stop();
|
|
109
|
+
}
|
|
110
|
+
});
|
|
101
111
|
|
|
102
112
|
function _disableWheel(e) {
|
|
103
113
|
e.preventDefault();
|
|
@@ -120,7 +130,7 @@ class Globe {
|
|
|
120
130
|
*/
|
|
121
131
|
this.renderer = new Renderer(
|
|
122
132
|
new Handler(_canvasId, {
|
|
123
|
-
pixelRatio: window.devicePixelRatio,
|
|
133
|
+
pixelRatio: window.devicePixelRatio + 0.15,
|
|
124
134
|
context: {
|
|
125
135
|
alpha: false,
|
|
126
136
|
antialias: false,
|
|
@@ -162,7 +172,8 @@ class Globe {
|
|
|
162
172
|
// TODO:
|
|
163
173
|
} else {
|
|
164
174
|
this.planet = new Planet({
|
|
165
|
-
name: this._planetName,
|
|
175
|
+
name: this._planetName,
|
|
176
|
+
frustums: options.frustums,
|
|
166
177
|
ellipsoid: options.ellipsoid,
|
|
167
178
|
maxGridSize: options.maxGridSize,
|
|
168
179
|
useNightTexture: options.useNightTexture,
|
|
@@ -171,7 +182,8 @@ class Globe {
|
|
|
171
182
|
maxAltitude: options.maxAltitude || 15000000,
|
|
172
183
|
maxEqualZoomAltitude: options.maxEqualZoomAltitude,
|
|
173
184
|
minEqualZoomAltitude: options.minEqualZoomAltitude,
|
|
174
|
-
minEqualZoomCameraSlope: options.minEqualZoomCameraSlope
|
|
185
|
+
minEqualZoomCameraSlope: options.minEqualZoomCameraSlope,
|
|
186
|
+
loadingBatchSize: options.loadingBatchSize
|
|
175
187
|
});
|
|
176
188
|
}
|
|
177
189
|
|
|
@@ -193,8 +205,8 @@ class Globe {
|
|
|
193
205
|
options.useEarthNavigation
|
|
194
206
|
? new EarthNavigation()
|
|
195
207
|
: new MouseNavigation({
|
|
196
|
-
|
|
197
|
-
|
|
208
|
+
minSlope: options.minSlope
|
|
209
|
+
}),
|
|
198
210
|
new TouchNavigation(),
|
|
199
211
|
new EarthCoordinates(),
|
|
200
212
|
new ScaleControl(),
|
package/src/og/camera/Camera.js
CHANGED
|
@@ -98,26 +98,26 @@ class Camera {
|
|
|
98
98
|
* @protected
|
|
99
99
|
* @type {Vec3}
|
|
100
100
|
*/
|
|
101
|
-
this.
|
|
101
|
+
this._r = new Vec3(1.0, 0.0, 0.0); // up x n
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Camera up vector.
|
|
105
105
|
* @protected
|
|
106
106
|
* @type {Vec3}
|
|
107
107
|
*/
|
|
108
|
-
this.
|
|
108
|
+
this._u = new Vec3(0.0, 1.0, 0.0); // n x u - UP
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
111
|
* Camera forward vector.
|
|
112
112
|
* @protected
|
|
113
113
|
* @type {Vec3}
|
|
114
114
|
*/
|
|
115
|
-
this.
|
|
115
|
+
this._b = new Vec3(0.0, 0.0, 1.0); // eye - look - FORWARD
|
|
116
116
|
|
|
117
117
|
// Previous frame values
|
|
118
|
-
this._pu = this.
|
|
119
|
-
this._pv = this.
|
|
120
|
-
this._pn = this.
|
|
118
|
+
this._pu = this._r.clone();
|
|
119
|
+
this._pv = this._u.clone();
|
|
120
|
+
this._pn = this._b.clone();
|
|
121
121
|
this._peye = this.eye.clone();
|
|
122
122
|
this.isMoved = false;
|
|
123
123
|
|
|
@@ -173,9 +173,9 @@ class Camera {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
checkMoveEnd() {
|
|
176
|
-
var u = this.
|
|
177
|
-
v = this.
|
|
178
|
-
n = this.
|
|
176
|
+
var u = this._r,
|
|
177
|
+
v = this._u,
|
|
178
|
+
n = this._b,
|
|
179
179
|
eye = this.eye;
|
|
180
180
|
|
|
181
181
|
if (this._peye.equal(eye) && this._pu.equal(u) && this._pv.equal(v) && this._pn.equal(n)) {
|
|
@@ -216,27 +216,27 @@ class Camera {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
getUp() {
|
|
219
|
-
return this.
|
|
219
|
+
return this._u.clone();
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
getDown() {
|
|
223
|
-
return this.
|
|
223
|
+
return this._u.negateTo();
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
getRight() {
|
|
227
|
-
return this.
|
|
227
|
+
return this._r.clone();
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
getLeft() {
|
|
231
|
-
return this.
|
|
231
|
+
return this._r.negateTo();
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
getForward() {
|
|
235
|
-
return this.
|
|
235
|
+
return this._b.negateTo();
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
getBackward() {
|
|
239
|
-
return this.
|
|
239
|
+
return this._b.clone();
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
/**
|
|
@@ -245,9 +245,9 @@ class Camera {
|
|
|
245
245
|
* @virtual
|
|
246
246
|
*/
|
|
247
247
|
update() {
|
|
248
|
-
var u = this.
|
|
249
|
-
v = this.
|
|
250
|
-
n = this.
|
|
248
|
+
var u = this._r,
|
|
249
|
+
v = this._u,
|
|
250
|
+
n = this._b,
|
|
251
251
|
eye = this.eye;
|
|
252
252
|
|
|
253
253
|
Vec3.doubleToTwoFloat32Array(eye, this.eyeHigh, this.eyeLow);
|
|
@@ -321,12 +321,7 @@ class Camera {
|
|
|
321
321
|
this._tanViewAngle_hradOneByHeight =
|
|
322
322
|
this._tanViewAngle_hrad * this.renderer.handler._oneByHeight;
|
|
323
323
|
var c = this.renderer.handler.canvas;
|
|
324
|
-
this._projSizeConst =
|
|
325
|
-
Math.min(
|
|
326
|
-
c.clientWidth < 256 ? 256 : c.clientWidth,
|
|
327
|
-
c.clientHeight < 256 ? 256 : c.clientHeight
|
|
328
|
-
) /
|
|
329
|
-
(angle * math.RADIANS);
|
|
324
|
+
this._projSizeConst = Math.min(c.clientWidth < 256 ? 256 : c.clientWidth, c.clientHeight < 256 ? 256 : c.clientHeight) / (angle * math.RADIANS);
|
|
330
325
|
for (let i = 0, len = this.frustums.length; i < len; i++) {
|
|
331
326
|
this.frustums[i].setProjectionMatrix(
|
|
332
327
|
angle,
|
|
@@ -368,15 +363,15 @@ class Camera {
|
|
|
368
363
|
this.eye.x = eye.x;
|
|
369
364
|
this.eye.y = eye.y;
|
|
370
365
|
this.eye.z = eye.z;
|
|
371
|
-
look = look || this.
|
|
372
|
-
up = up || this.
|
|
373
|
-
this.
|
|
374
|
-
this.
|
|
375
|
-
this.
|
|
376
|
-
this.
|
|
377
|
-
this.
|
|
378
|
-
this.
|
|
379
|
-
this.
|
|
366
|
+
look = look || this._b;
|
|
367
|
+
up = up || this._u;
|
|
368
|
+
this._b.x = eye.x - look.x;
|
|
369
|
+
this._b.y = eye.y - look.y;
|
|
370
|
+
this._b.z = eye.z - look.z;
|
|
371
|
+
this._r.copy(up.cross(this._b));
|
|
372
|
+
this._b.normalize();
|
|
373
|
+
this._r.normalize();
|
|
374
|
+
this._u.copy(this._b.cross(this._r));
|
|
380
375
|
return this;
|
|
381
376
|
}
|
|
382
377
|
|
|
@@ -384,14 +379,14 @@ class Camera {
|
|
|
384
379
|
* Sets camera look point
|
|
385
380
|
* @public
|
|
386
381
|
* @param {Vec3} look - Look point
|
|
387
|
-
* @param {Vec3} [up] - Camera up vector otherwise camera current up vector(this.
|
|
382
|
+
* @param {Vec3} [up] - Camera up vector otherwise camera current up vector(this._u)
|
|
388
383
|
*/
|
|
389
384
|
look(look, up) {
|
|
390
|
-
this.
|
|
391
|
-
this.
|
|
392
|
-
this.
|
|
393
|
-
this.
|
|
394
|
-
this.
|
|
385
|
+
this._b.set(this.eye.x - look.x, this.eye.y - look.y, this.eye.z - look.z);
|
|
386
|
+
this._r.copy((up || this._u).cross(this._b));
|
|
387
|
+
this._b.normalize();
|
|
388
|
+
this._r.normalize();
|
|
389
|
+
this._u.copy(this._b.cross(this._r));
|
|
395
390
|
}
|
|
396
391
|
|
|
397
392
|
/**
|
|
@@ -402,9 +397,9 @@ class Camera {
|
|
|
402
397
|
* @param {number} dn - delta Z
|
|
403
398
|
*/
|
|
404
399
|
slide(du, dv, dn) {
|
|
405
|
-
this.eye.x += du * this.
|
|
406
|
-
this.eye.y += du * this.
|
|
407
|
-
this.eye.z += du * this.
|
|
400
|
+
this.eye.x += du * this._r.x + dv * this._u.x + dn * this._b.x;
|
|
401
|
+
this.eye.y += du * this._r.y + dv * this._u.y + dn * this._b.y;
|
|
402
|
+
this.eye.z += du * this._r.z + dv * this._u.z + dn * this._b.z;
|
|
408
403
|
}
|
|
409
404
|
|
|
410
405
|
/**
|
|
@@ -415,16 +410,16 @@ class Camera {
|
|
|
415
410
|
roll(angle) {
|
|
416
411
|
var cs = Math.cos(math.RADIANS * angle);
|
|
417
412
|
var sn = Math.sin(math.RADIANS * angle);
|
|
418
|
-
var t = this.
|
|
419
|
-
this.
|
|
420
|
-
cs * t.x - sn * this.
|
|
421
|
-
cs * t.y - sn * this.
|
|
422
|
-
cs * t.z - sn * this.
|
|
413
|
+
var t = this._r.clone();
|
|
414
|
+
this._r.set(
|
|
415
|
+
cs * t.x - sn * this._u.x,
|
|
416
|
+
cs * t.y - sn * this._u.y,
|
|
417
|
+
cs * t.z - sn * this._u.z
|
|
423
418
|
);
|
|
424
|
-
this.
|
|
425
|
-
sn * t.x + cs * this.
|
|
426
|
-
sn * t.y + cs * this.
|
|
427
|
-
sn * t.z + cs * this.
|
|
419
|
+
this._u.set(
|
|
420
|
+
sn * t.x + cs * this._u.x,
|
|
421
|
+
sn * t.y + cs * this._u.y,
|
|
422
|
+
sn * t.z + cs * this._u.z
|
|
428
423
|
);
|
|
429
424
|
}
|
|
430
425
|
|
|
@@ -436,16 +431,16 @@ class Camera {
|
|
|
436
431
|
pitch(angle) {
|
|
437
432
|
var cs = Math.cos(math.RADIANS * angle);
|
|
438
433
|
var sn = Math.sin(math.RADIANS * angle);
|
|
439
|
-
var t = this.
|
|
440
|
-
this.
|
|
441
|
-
cs * t.x - sn * this.
|
|
442
|
-
cs * t.y - sn * this.
|
|
443
|
-
cs * t.z - sn * this.
|
|
434
|
+
var t = this._b.clone();
|
|
435
|
+
this._b.set(
|
|
436
|
+
cs * t.x - sn * this._u.x,
|
|
437
|
+
cs * t.y - sn * this._u.y,
|
|
438
|
+
cs * t.z - sn * this._u.z
|
|
444
439
|
);
|
|
445
|
-
this.
|
|
446
|
-
sn * t.x + cs * this.
|
|
447
|
-
sn * t.y + cs * this.
|
|
448
|
-
sn * t.z + cs * this.
|
|
440
|
+
this._u.set(
|
|
441
|
+
sn * t.x + cs * this._u.x,
|
|
442
|
+
sn * t.y + cs * this._u.y,
|
|
443
|
+
sn * t.z + cs * this._u.z
|
|
449
444
|
);
|
|
450
445
|
}
|
|
451
446
|
|
|
@@ -457,16 +452,16 @@ class Camera {
|
|
|
457
452
|
yaw(angle) {
|
|
458
453
|
var cs = Math.cos(math.RADIANS * angle);
|
|
459
454
|
var sn = Math.sin(math.RADIANS * angle);
|
|
460
|
-
var t = this.
|
|
461
|
-
this.
|
|
462
|
-
cs * t.x - sn * this.
|
|
463
|
-
cs * t.y - sn * this.
|
|
464
|
-
cs * t.z - sn * this.
|
|
455
|
+
var t = this._r.clone();
|
|
456
|
+
this._r.set(
|
|
457
|
+
cs * t.x - sn * this._b.x,
|
|
458
|
+
cs * t.y - sn * this._b.y,
|
|
459
|
+
cs * t.z - sn * this._b.z
|
|
465
460
|
);
|
|
466
|
-
this.
|
|
467
|
-
sn * t.x + cs * this.
|
|
468
|
-
sn * t.y + cs * this.
|
|
469
|
-
sn * t.z + cs * this.
|
|
461
|
+
this._b.set(
|
|
462
|
+
sn * t.x + cs * this._b.x,
|
|
463
|
+
sn * t.y + cs * this._b.y,
|
|
464
|
+
sn * t.z + cs * this._b.z
|
|
470
465
|
);
|
|
471
466
|
}
|
|
472
467
|
|
|
@@ -485,12 +480,8 @@ class Camera {
|
|
|
485
480
|
var px = (x - w) / w,
|
|
486
481
|
py = -(y - h) / h;
|
|
487
482
|
|
|
488
|
-
var world1 = this.frustums[0]._inverseProjectionViewMatrix
|
|
489
|
-
|
|
490
|
-
.affinity(),
|
|
491
|
-
world2 = this.frustums[0]._inverseProjectionViewMatrix
|
|
492
|
-
.mulVec4(new Vec4(px, py, 0.0, 1.0))
|
|
493
|
-
.affinity();
|
|
483
|
+
var world1 = this.frustums[0]._inverseProjectionViewMatrix.mulVec4(new Vec4(px, py, -1.0, 1.0)).affinity(),
|
|
484
|
+
world2 = this.frustums[0]._inverseProjectionViewMatrix.mulVec4(new Vec4(px, py, 0.0, 1.0)).affinity();
|
|
494
485
|
|
|
495
486
|
return world2.subA(world1).toVec3().normalize();
|
|
496
487
|
}
|
|
@@ -520,16 +511,16 @@ class Camera {
|
|
|
520
511
|
center = center || Vec3.ZERO;
|
|
521
512
|
up = up || Vec3.UP;
|
|
522
513
|
|
|
523
|
-
var rot = new Mat4().setRotation(isArc ? this.
|
|
514
|
+
var rot = new Mat4().setRotation(isArc ? this._u : up, angle);
|
|
524
515
|
var tr = new Mat4().setIdentity().translate(center);
|
|
525
516
|
var ntr = new Mat4().setIdentity().translate(center.negateTo());
|
|
526
517
|
|
|
527
518
|
var trm = tr.mul(rot).mul(ntr);
|
|
528
519
|
|
|
529
520
|
this.eye = trm.mulVec3(this.eye);
|
|
530
|
-
this._v = rot.mulVec3(this._v).normalize();
|
|
531
521
|
this._u = rot.mulVec3(this._u).normalize();
|
|
532
|
-
this.
|
|
522
|
+
this._r = rot.mulVec3(this._r).normalize();
|
|
523
|
+
this._b = rot.mulVec3(this._b).normalize();
|
|
533
524
|
}
|
|
534
525
|
|
|
535
526
|
/**
|
|
@@ -551,7 +542,7 @@ class Camera {
|
|
|
551
542
|
* @param {Vec3} center - Point that the camera rotates around.
|
|
552
543
|
*/
|
|
553
544
|
rotateVertical(angle, center) {
|
|
554
|
-
this.rotateAround(angle, false, center, this.
|
|
545
|
+
this.rotateAround(angle, false, center, this._r);
|
|
555
546
|
}
|
|
556
547
|
|
|
557
548
|
/**
|
|
@@ -36,20 +36,15 @@ class PlanetCamera extends Camera {
|
|
|
36
36
|
* @param {Object} [options] - Planet camera options:
|
|
37
37
|
*/
|
|
38
38
|
constructor(planet, options) {
|
|
39
|
-
super(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
[1e6, 1e9]
|
|
49
|
-
] //[[1, 1e3 + 100], [1e3, 1e6 + 10000], [1e6, 1e9]]*/
|
|
50
|
-
},
|
|
51
|
-
options
|
|
52
|
-
)
|
|
39
|
+
super(planet.renderer, {
|
|
40
|
+
frustums: [
|
|
41
|
+
[1, 100 + 0.075],
|
|
42
|
+
[100, 1000 + 0.075],
|
|
43
|
+
[1000, 1e6 + 10000],
|
|
44
|
+
[1e6, 1e9]
|
|
45
|
+
], //[[1, 1e3 + 100], [1e3, 1e6 + 10000], [1e6, 1e9]]*/
|
|
46
|
+
...options
|
|
47
|
+
}
|
|
53
48
|
);
|
|
54
49
|
/**
|
|
55
50
|
* Assigned camera's planet.
|
|
@@ -144,7 +139,7 @@ class PlanetCamera extends Camera {
|
|
|
144
139
|
super.update();
|
|
145
140
|
this.updateGeodeticPosition();
|
|
146
141
|
this.eyeNorm = this.eye.normal();
|
|
147
|
-
this.slope = this.
|
|
142
|
+
this.slope = this._b.dot(this.eyeNorm);
|
|
148
143
|
this.events.dispatch(this.events.viewchange, this);
|
|
149
144
|
}
|
|
150
145
|
|
|
@@ -387,8 +382,8 @@ class PlanetCamera extends Camera {
|
|
|
387
382
|
var ground_a = this.planet.ellipsoid.lonLatToCartesian(
|
|
388
383
|
new LonLat(this._lonLat.lon, this._lonLat.lat)
|
|
389
384
|
);
|
|
390
|
-
var v_a = this.
|
|
391
|
-
n_a = this.
|
|
385
|
+
var v_a = this._u,
|
|
386
|
+
n_a = this._b;
|
|
392
387
|
|
|
393
388
|
var lonlat_b = this.planet.ellipsoid.cartesianToLonLat(cartesian);
|
|
394
389
|
var up_b = up || Vec3.UP;
|
|
@@ -543,18 +538,18 @@ class PlanetCamera extends Camera {
|
|
|
543
538
|
}
|
|
544
539
|
|
|
545
540
|
rotateVertical(angle, center, minSlope = 0) {
|
|
546
|
-
var rot = new Mat4().setRotation(this.
|
|
541
|
+
var rot = new Mat4().setRotation(this._r, angle);
|
|
547
542
|
var tr = new Mat4().setIdentity().translate(center);
|
|
548
543
|
var ntr = new Mat4().setIdentity().translate(center.negateTo());
|
|
549
544
|
var trm = tr.mul(rot).mul(ntr);
|
|
550
545
|
|
|
551
546
|
let eye = trm.mulVec3(this.eye);
|
|
552
|
-
let v = rot.mulVec3(this._v).normalize();
|
|
553
547
|
let u = rot.mulVec3(this._u).normalize();
|
|
554
|
-
let
|
|
548
|
+
let r = rot.mulVec3(this._r).normalize();
|
|
549
|
+
let b = rot.mulVec3(this._b).normalize();
|
|
555
550
|
|
|
556
551
|
let eyeNorm = eye.normal();
|
|
557
|
-
let slope =
|
|
552
|
+
let slope = b.dot(eyeNorm);
|
|
558
553
|
|
|
559
554
|
if (minSlope) {
|
|
560
555
|
let dSlope = slope - this.slope;
|
|
@@ -562,20 +557,20 @@ class PlanetCamera extends Camera {
|
|
|
562
557
|
if (slope < minSlope && dSlope < 0) return;
|
|
563
558
|
|
|
564
559
|
if (
|
|
565
|
-
(slope > 0.1 &&
|
|
560
|
+
(slope > 0.1 && u.dot(eyeNorm) > 0) ||
|
|
566
561
|
this.slope <= 0.1 ||
|
|
567
|
-
this.
|
|
562
|
+
this._u.dot(this.eye.normal()) <= 0.0
|
|
568
563
|
) {
|
|
569
564
|
this.eye = eye;
|
|
570
|
-
this._v = v;
|
|
571
565
|
this._u = u;
|
|
572
|
-
this.
|
|
566
|
+
this._r = r;
|
|
567
|
+
this._b = b;
|
|
573
568
|
}
|
|
574
569
|
} else {
|
|
575
570
|
this.eye = eye;
|
|
576
|
-
this._v = v;
|
|
577
571
|
this._u = u;
|
|
578
|
-
this.
|
|
572
|
+
this._r = r;
|
|
573
|
+
this._b = b;
|
|
579
574
|
}
|
|
580
575
|
}
|
|
581
576
|
|
|
@@ -592,9 +587,9 @@ class PlanetCamera extends Camera {
|
|
|
592
587
|
this.planet._normalMapCreator.lock(this._keyLock);
|
|
593
588
|
|
|
594
589
|
this.eye = this._framesArr[c].eye;
|
|
595
|
-
this.
|
|
596
|
-
this.
|
|
597
|
-
this.
|
|
590
|
+
this._r = this._framesArr[c].u;
|
|
591
|
+
this._u = this._framesArr[c].v;
|
|
592
|
+
this._b = this._framesArr[c].n;
|
|
598
593
|
|
|
599
594
|
if (this._frameCallback) {
|
|
600
595
|
this._frameCallback();
|
|
@@ -6,6 +6,7 @@ import { Quat } from "../math/Quat.js";
|
|
|
6
6
|
import { Ray } from "../math/Ray.js";
|
|
7
7
|
import { Vec3 } from "../math/Vec3.js";
|
|
8
8
|
import { Control } from "./Control.js";
|
|
9
|
+
import { Mat4 } from "../math/Mat4.js";
|
|
9
10
|
|
|
10
11
|
class Touch {
|
|
11
12
|
constructor() {
|
|
@@ -29,6 +30,7 @@ class EarthNavigation extends Control {
|
|
|
29
30
|
super(options);
|
|
30
31
|
|
|
31
32
|
this.grabbedPoint = new Vec3();
|
|
33
|
+
this.grabbedDir = new Vec3();
|
|
32
34
|
this.inertia = 0.007;
|
|
33
35
|
this.grabbedSpheroid = new Sphere();
|
|
34
36
|
this.planet = null;
|
|
@@ -39,11 +41,11 @@ class EarthNavigation extends Control {
|
|
|
39
41
|
this.currState = 0;
|
|
40
42
|
|
|
41
43
|
this.positionState = [
|
|
42
|
-
{ h: 17119745.303455353, max: 0.
|
|
43
|
-
{ h: 6866011, max: 0.
|
|
44
|
-
{ h: 3000000, max: 0.
|
|
45
|
-
{ h: 1000000, max: 0.
|
|
46
|
-
{ h: 500000, max: 0.
|
|
44
|
+
{ h: 17119745.303455353, max: 0.98, min: -0.98 },
|
|
45
|
+
{ h: 6866011, max: 0.98, min: -0.98 },
|
|
46
|
+
{ h: 3000000, max: 0.98, min: -0.98 },
|
|
47
|
+
{ h: 1000000, max: 0.98, min: -0.98 },
|
|
48
|
+
{ h: 500000, max: 0.98, min: -0.98 }
|
|
47
49
|
];
|
|
48
50
|
|
|
49
51
|
this.touches = [new Touch(), new Touch()];
|
|
@@ -163,9 +165,10 @@ class EarthNavigation extends Control {
|
|
|
163
165
|
}
|
|
164
166
|
}
|
|
165
167
|
|
|
166
|
-
onMouseLeftButtonClick() {
|
|
168
|
+
onMouseLeftButtonClick(e) {
|
|
167
169
|
this.renderer.handler.gl.canvas.classList.add("ogGrabbingPoiner");
|
|
168
170
|
this.grabbedPoint = this.planet.getCartesianFromMouseTerrain(true);
|
|
171
|
+
this.grabbedDir.copy(e.direction);
|
|
169
172
|
if (this.grabbedPoint) {
|
|
170
173
|
this.grabbedSpheroid.radius = this.grabbedPoint.length();
|
|
171
174
|
this.stopRotation();
|
|
@@ -195,24 +198,30 @@ class EarthNavigation extends Control {
|
|
|
195
198
|
var targetPoint = new Ray(cam.eye, e.direction).hitSphere(this.grabbedSpheroid);
|
|
196
199
|
|
|
197
200
|
if (targetPoint) {
|
|
198
|
-
|
|
199
|
-
|
|
201
|
+
|
|
202
|
+
this._a = Math.acos(this.grabbedPoint.y / this.grabbedSpheroid.radius) -
|
|
200
203
|
Math.acos(targetPoint.y / this.grabbedSpheroid.radius);
|
|
201
204
|
|
|
202
|
-
this._vRot = Quat.axisAngleToQuat(cam._u, this._a);
|
|
205
|
+
let rot = this._vRot = Quat.axisAngleToQuat(cam._u, this._a);
|
|
206
|
+
|
|
207
|
+
cam.set(rot.mulVec3(cam.eye), Vec3.ZERO, rot.mulVec3(cam.getUp()));
|
|
208
|
+
//cam.update();
|
|
209
|
+
|
|
203
210
|
this._hRot = Quat.getRotationBetweenVectors(
|
|
204
211
|
new Vec3(targetPoint.x, 0.0, targetPoint.z).normal(),
|
|
205
212
|
new Vec3(this.grabbedPoint.x, 0.0, this.grabbedPoint.z).normal()
|
|
206
213
|
);
|
|
207
|
-
var rot = this._hRot.mul(this._vRot);
|
|
208
214
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
215
|
+
rot = this._hRot;
|
|
216
|
+
|
|
217
|
+
//var state = this.positionState[this.currState];
|
|
218
|
+
//var lim = cam.eye.normal().dot(Vec3.UP);
|
|
219
|
+
|
|
220
|
+
//if (lim > state.max || lim < state.min) {
|
|
221
|
+
// rot = Quat.yRotation(rot.getYaw());
|
|
222
|
+
cam.set(rot.mulVec3(cam.eye), Vec3.ZERO, rot.mulVec3(cam.getUp()));
|
|
223
|
+
cam.update();
|
|
224
|
+
//}
|
|
216
225
|
}
|
|
217
226
|
} else {
|
|
218
227
|
this.scaleRot = 0;
|
|
@@ -57,9 +57,9 @@ class MouseNavigation extends Control {
|
|
|
57
57
|
var steps = [];
|
|
58
58
|
|
|
59
59
|
var eye = cam.eye.clone(),
|
|
60
|
-
n = cam.
|
|
61
|
-
u = cam.
|
|
62
|
-
v = cam.
|
|
60
|
+
n = cam._b.clone(),
|
|
61
|
+
u = cam._r.clone(),
|
|
62
|
+
v = cam._u.clone();
|
|
63
63
|
|
|
64
64
|
var a = planet.getCartesianFromPixelTerrain(point, true);
|
|
65
65
|
|
|
@@ -265,7 +265,6 @@ class MouseNavigation extends Control {
|
|
|
265
265
|
this.renderer.handler.canvas.classList.add("ogGrabbingPoiner");
|
|
266
266
|
this.grabbedPoint = this.planet.getCartesianFromMouseTerrain();
|
|
267
267
|
if (this.grabbedPoint) {
|
|
268
|
-
this.renderer.isActiveBackBuffers = false;
|
|
269
268
|
this._eye0.copy(this.renderer.activeCamera.eye);
|
|
270
269
|
this.grabbedSpheroid.radius = this.grabbedPoint.length();
|
|
271
270
|
this.stopRotation();
|
|
@@ -281,7 +280,6 @@ class MouseNavigation extends Control {
|
|
|
281
280
|
}
|
|
282
281
|
|
|
283
282
|
onMouseLeftButtonUp(e) {
|
|
284
|
-
this.renderer.isActiveBackBuffers = true;
|
|
285
283
|
this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner");
|
|
286
284
|
if (e.x === e.prev_x && e.y === e.prev_y) {
|
|
287
285
|
this.scaleRot = 0.0;
|
|
@@ -309,9 +307,9 @@ class MouseNavigation extends Control {
|
|
|
309
307
|
);
|
|
310
308
|
var rot = this.qRot;
|
|
311
309
|
cam.eye = rot.mulVec3(cam.eye);
|
|
312
|
-
cam._v = rot.mulVec3(cam._v);
|
|
313
310
|
cam._u = rot.mulVec3(cam._u);
|
|
314
|
-
cam.
|
|
311
|
+
cam._r = rot.mulVec3(cam._r);
|
|
312
|
+
cam._b = rot.mulVec3(cam._b);
|
|
315
313
|
|
|
316
314
|
cam.checkTerrainCollision();
|
|
317
315
|
|
|
@@ -319,7 +317,7 @@ class MouseNavigation extends Control {
|
|
|
319
317
|
}
|
|
320
318
|
} else {
|
|
321
319
|
var p0 = this.grabbedPoint,
|
|
322
|
-
p1 = Vec3.add(p0, cam.
|
|
320
|
+
p1 = Vec3.add(p0, cam._r),
|
|
323
321
|
p2 = Vec3.add(p0, p0.normal());
|
|
324
322
|
|
|
325
323
|
var px = new Vec3();
|
|
@@ -395,9 +393,9 @@ class MouseNavigation extends Control {
|
|
|
395
393
|
}
|
|
396
394
|
|
|
397
395
|
cam.eye = sf.eye;
|
|
398
|
-
cam.
|
|
399
|
-
cam.
|
|
400
|
-
cam.
|
|
396
|
+
cam._u = sf.v;
|
|
397
|
+
cam._r = sf.u;
|
|
398
|
+
cam._b = sf.n;
|
|
401
399
|
|
|
402
400
|
cam.checkTerrainCollision();
|
|
403
401
|
|
|
@@ -428,9 +426,9 @@ class MouseNavigation extends Control {
|
|
|
428
426
|
this.scaleRot = 0.0;
|
|
429
427
|
}
|
|
430
428
|
cam.eye = rot.mulVec3(cam.eye);
|
|
431
|
-
cam._v = rot.mulVec3(cam._v);
|
|
432
429
|
cam._u = rot.mulVec3(cam._u);
|
|
433
|
-
cam.
|
|
430
|
+
cam._r = rot.mulVec3(cam._r);
|
|
431
|
+
cam._b = rot.mulVec3(cam._b);
|
|
434
432
|
|
|
435
433
|
cam.checkTerrainCollision();
|
|
436
434
|
|
|
@@ -195,9 +195,9 @@ class MouseWheelZoomControl extends Control {
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
cam.eye = sf.eye;
|
|
198
|
-
cam.
|
|
199
|
-
cam.
|
|
200
|
-
cam.
|
|
198
|
+
cam._u = sf.v;
|
|
199
|
+
cam._r = sf.u;
|
|
200
|
+
cam._b = sf.n;
|
|
201
201
|
|
|
202
202
|
cam.checkTerrainCollision();
|
|
203
203
|
|
|
@@ -228,9 +228,9 @@ class MouseWheelZoomControl extends Control {
|
|
|
228
228
|
this.scaleRot = 0.0;
|
|
229
229
|
}
|
|
230
230
|
cam.eye = rot.mulVec3(cam.eye);
|
|
231
|
-
cam._v = rot.mulVec3(cam._v);
|
|
232
231
|
cam._u = rot.mulVec3(cam._u);
|
|
233
|
-
cam.
|
|
232
|
+
cam._r = rot.mulVec3(cam._r);
|
|
233
|
+
cam._b = rot.mulVec3(cam._b);
|
|
234
234
|
|
|
235
235
|
cam.checkTerrainCollision();
|
|
236
236
|
|