@openglobus/og 0.13.2 → 0.13.5
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/dist/@openglobus/og.esm.js +2 -2
- package/dist/@openglobus/og.esm.js.map +1 -1
- package/dist/@openglobus/og.umd.js +2 -2
- package/dist/@openglobus/og.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/og/control/TouchNavigation.js +340 -319
- package/src/og/entity/Billboard.js +165 -165
- package/src/og/entity/BillboardHandler.js +1 -1
- package/src/og/entity/GeoObject.js +4 -0
- package/src/og/entity/GeoObjectHandler.js +22 -33
- package/src/og/entity/Geometry.js +319 -319
- package/src/og/entity/Label.js +348 -346
- package/src/og/entity/LabelHandler.js +44 -37
- package/src/og/renderer/RendererEvents.js +1051 -1051
- package/src/og/shaders/billboard.js +8 -0
- package/src/og/shaders/label.js +59 -16
- package/src/og/utils/FontAtlas.js +25 -15
- package/src/og/utils/TextureAtlas.js +291 -280
- package/types/entity/GeoObject.d.ts +1 -0
- package/types/entity/Label.d.ts +1 -0
- package/types/entity/LabelHandler.d.ts +1 -1
- package/types/utils/TextureAtlas.d.ts +2 -0
|
@@ -1,319 +1,340 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module og/control/TouchNavigation
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
import * as math from "../math.js";
|
|
8
|
-
import { Control } from "./Control.js";
|
|
9
|
-
import { Key } from "../Lock.js";
|
|
10
|
-
import { LonLat } from "../LonLat.js";
|
|
11
|
-
import { Quat } from "../math/Quat.js";
|
|
12
|
-
import { Ray } from "../math/Ray.js";
|
|
13
|
-
import { Sphere } from "../bv/Sphere.js";
|
|
14
|
-
import { Vec3 } from "../math/Vec3.js";
|
|
15
|
-
|
|
16
|
-
class Touch {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.x = 0;
|
|
19
|
-
this.y = 0;
|
|
20
|
-
this.prev_x = 0;
|
|
21
|
-
this.prev_y = 0;
|
|
22
|
-
this.grabbedPoint = new Vec3();
|
|
23
|
-
this.grabbedSpheroid = new Sphere();
|
|
24
|
-
this.dX = function () {
|
|
25
|
-
return this.x - this.prev_x;
|
|
26
|
-
};
|
|
27
|
-
this.dY = function () {
|
|
28
|
-
return this.y - this.prev_y;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Touch pad planet camera dragging control.
|
|
35
|
-
* @class
|
|
36
|
-
* @extends {Control}
|
|
37
|
-
* @param {Object} [options] - Control options.
|
|
38
|
-
*/
|
|
39
|
-
class TouchNavigation extends Control {
|
|
40
|
-
constructor(options) {
|
|
41
|
-
super(options);
|
|
42
|
-
|
|
43
|
-
this._name = "touchNavigation";
|
|
44
|
-
|
|
45
|
-
this.grabbedPoint = new Vec3();
|
|
46
|
-
this.inertia = 0.007;
|
|
47
|
-
this.grabbedSpheroid = new Sphere();
|
|
48
|
-
this.planet = null;
|
|
49
|
-
this.qRot = new Quat();
|
|
50
|
-
this.scaleRot = 0;
|
|
51
|
-
this.rot = 1;
|
|
52
|
-
this._eye0 = new Vec3();
|
|
53
|
-
|
|
54
|
-
this.stepsCount = 5;
|
|
55
|
-
this.stepsForward = null;
|
|
56
|
-
this.stepIndex = 0;
|
|
57
|
-
|
|
58
|
-
this.pointOnEarth = null;
|
|
59
|
-
this.earthUp = null;
|
|
60
|
-
|
|
61
|
-
this.touches = [new Touch(), new Touch()];
|
|
62
|
-
|
|
63
|
-
this._keyLock = new Key();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
oninit() {
|
|
67
|
-
this.renderer.events.on("touchstart", this.onTouchStart, this);
|
|
68
|
-
this.renderer.events.on("touchend", this.onTouchEnd, this);
|
|
69
|
-
this.renderer.events.on("doubletouch", this.onDoubleTouch, this);
|
|
70
|
-
this.renderer.events.on("touchcancel", this.onTouchCancel, this);
|
|
71
|
-
this.renderer.events.on("touchmove", this.onTouchMove, this);
|
|
72
|
-
this.renderer.events.on("draw", this.onDraw, this);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
onTouchStart(e) {
|
|
76
|
-
this._touching = true;
|
|
77
|
-
|
|
78
|
-
if (e.sys.touches.length === 2) {
|
|
79
|
-
var t0 = this.touches[0],
|
|
80
|
-
t1 = this.touches[1];
|
|
81
|
-
|
|
82
|
-
t0.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
|
83
|
-
t0.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
|
84
|
-
t0.prev_x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
|
85
|
-
t0.prev_y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
|
86
|
-
t0.grabbedPoint = this.planet.getCartesianFromPixelTerrain(t0, true);
|
|
87
|
-
|
|
88
|
-
t1.x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
|
|
89
|
-
t1.y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
|
|
90
|
-
t1.prev_x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
|
|
91
|
-
t1.prev_y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
|
|
92
|
-
t1.grabbedPoint = this.planet.getCartesianFromPixelTerrain(t1, true);
|
|
93
|
-
|
|
94
|
-
// this.planet._viewChanged = true;
|
|
95
|
-
this.pointOnEarth = this.planet.getCartesianFromPixelTerrain(
|
|
96
|
-
this.renderer.handler.getCenter(),
|
|
97
|
-
true
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
if (this.pointOnEarth) {
|
|
101
|
-
this.earthUp = this.pointOnEarth.normal();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (t0.grabbedPoint && t1.grabbedPoint) {
|
|
105
|
-
t0.grabbedSpheroid.radius = t0.grabbedPoint.length();
|
|
106
|
-
t1.grabbedSpheroid.radius = t1.grabbedPoint.length();
|
|
107
|
-
this.stopRotation();
|
|
108
|
-
}
|
|
109
|
-
} else if (e.sys.touches.length === 1) {
|
|
110
|
-
this._startTouchOne(e);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
_startTouchOne(e) {
|
|
115
|
-
var t = this.touches[0];
|
|
116
|
-
|
|
117
|
-
t.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
|
118
|
-
t.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
|
119
|
-
t.prev_x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
|
120
|
-
t.prev_y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
|
121
|
-
|
|
122
|
-
t.grabbedPoint = this.planet.getCartesianFromPixelTerrain(t, true);
|
|
123
|
-
this._eye0.copy(this.renderer.activeCamera.eye);
|
|
124
|
-
|
|
125
|
-
if (t.grabbedPoint) {
|
|
126
|
-
t.grabbedSpheroid.radius = t.grabbedPoint.length();
|
|
127
|
-
this.stopRotation();
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
stopRotation() {
|
|
132
|
-
this.qRot.clear();
|
|
133
|
-
this.planet.layerLock.free(this._keyLock);
|
|
134
|
-
this.planet.terrainLock.free(this._keyLock);
|
|
135
|
-
this.planet._normalMapCreator.free(this._keyLock);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
onDoubleTouch(e) {
|
|
139
|
-
if (this.stepIndex) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
this.planet.stopFlying();
|
|
144
|
-
this.stopRotation();
|
|
145
|
-
var p = this.planet.getCartesianFromPixelTerrain(this.touches[0], true);
|
|
146
|
-
if (p) {
|
|
147
|
-
var g = this.planet.ellipsoid.cartesianToLonLat(p);
|
|
148
|
-
this.planet.flyLonLat(
|
|
149
|
-
new LonLat(g.lon, g.lat, this.renderer.activeCamera.eye.distance(p) * 0.57)
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
onTouchEnd(e) {
|
|
155
|
-
if (e.sys.touches.length === 0) {
|
|
156
|
-
this._touching = false;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (e.sys.touches.length === 1) {
|
|
160
|
-
this._startTouchOne(e);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (
|
|
164
|
-
Math.abs(this.touches[0].x - this.touches[0].prev_x) < 3 &&
|
|
165
|
-
Math.abs(this.touches[0].y - this.touches[0].prev_y) < 3
|
|
166
|
-
) {
|
|
167
|
-
this.scaleRot = 0;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
onTouchCancel(e) {}
|
|
172
|
-
|
|
173
|
-
onTouchMove(e) {
|
|
174
|
-
var cam = this.renderer.activeCamera;
|
|
175
|
-
|
|
176
|
-
if (e.sys.touches.length === 2) {
|
|
177
|
-
this.renderer.controlsBag.scaleRot = 1;
|
|
178
|
-
|
|
179
|
-
var t0 = this.touches[0],
|
|
180
|
-
t1 = this.touches[1];
|
|
181
|
-
|
|
182
|
-
if (!t0.grabbedPoint || !t1.grabbedPoint) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
this.planet.stopFlying();
|
|
187
|
-
|
|
188
|
-
t0.prev_x = t0.x;
|
|
189
|
-
t0.prev_y = t0.y;
|
|
190
|
-
t0.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
|
191
|
-
t0.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
|
192
|
-
|
|
193
|
-
t1.prev_x = t1.x;
|
|
194
|
-
t1.prev_y = t1.y;
|
|
195
|
-
t1.x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
|
|
196
|
-
t1.y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
cam.
|
|
300
|
-
cam.
|
|
301
|
-
cam.
|
|
302
|
-
cam.
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
this.
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module og/control/TouchNavigation
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
import * as math from "../math.js";
|
|
8
|
+
import { Control } from "./Control.js";
|
|
9
|
+
import { Key } from "../Lock.js";
|
|
10
|
+
import { LonLat } from "../LonLat.js";
|
|
11
|
+
import { Quat } from "../math/Quat.js";
|
|
12
|
+
import { Ray } from "../math/Ray.js";
|
|
13
|
+
import { Sphere } from "../bv/Sphere.js";
|
|
14
|
+
import { Vec3 } from "../math/Vec3.js";
|
|
15
|
+
|
|
16
|
+
class Touch {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.x = 0;
|
|
19
|
+
this.y = 0;
|
|
20
|
+
this.prev_x = 0;
|
|
21
|
+
this.prev_y = 0;
|
|
22
|
+
this.grabbedPoint = new Vec3();
|
|
23
|
+
this.grabbedSpheroid = new Sphere();
|
|
24
|
+
this.dX = function () {
|
|
25
|
+
return this.x - this.prev_x;
|
|
26
|
+
};
|
|
27
|
+
this.dY = function () {
|
|
28
|
+
return this.y - this.prev_y;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Touch pad planet camera dragging control.
|
|
35
|
+
* @class
|
|
36
|
+
* @extends {Control}
|
|
37
|
+
* @param {Object} [options] - Control options.
|
|
38
|
+
*/
|
|
39
|
+
class TouchNavigation extends Control {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
super(options);
|
|
42
|
+
|
|
43
|
+
this._name = "touchNavigation";
|
|
44
|
+
|
|
45
|
+
this.grabbedPoint = new Vec3();
|
|
46
|
+
this.inertia = 0.007;
|
|
47
|
+
this.grabbedSpheroid = new Sphere();
|
|
48
|
+
this.planet = null;
|
|
49
|
+
this.qRot = new Quat();
|
|
50
|
+
this.scaleRot = 0;
|
|
51
|
+
this.rot = 1;
|
|
52
|
+
this._eye0 = new Vec3();
|
|
53
|
+
|
|
54
|
+
this.stepsCount = 5;
|
|
55
|
+
this.stepsForward = null;
|
|
56
|
+
this.stepIndex = 0;
|
|
57
|
+
|
|
58
|
+
this.pointOnEarth = null;
|
|
59
|
+
this.earthUp = null;
|
|
60
|
+
|
|
61
|
+
this.touches = [new Touch(), new Touch()];
|
|
62
|
+
|
|
63
|
+
this._keyLock = new Key();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
oninit() {
|
|
67
|
+
this.renderer.events.on("touchstart", this.onTouchStart, this);
|
|
68
|
+
this.renderer.events.on("touchend", this.onTouchEnd, this);
|
|
69
|
+
this.renderer.events.on("doubletouch", this.onDoubleTouch, this);
|
|
70
|
+
this.renderer.events.on("touchcancel", this.onTouchCancel, this);
|
|
71
|
+
this.renderer.events.on("touchmove", this.onTouchMove, this);
|
|
72
|
+
this.renderer.events.on("draw", this.onDraw, this);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
onTouchStart(e) {
|
|
76
|
+
this._touching = true;
|
|
77
|
+
|
|
78
|
+
if (e.sys.touches.length === 2) {
|
|
79
|
+
var t0 = this.touches[0],
|
|
80
|
+
t1 = this.touches[1];
|
|
81
|
+
|
|
82
|
+
t0.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
|
83
|
+
t0.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
|
84
|
+
t0.prev_x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
|
85
|
+
t0.prev_y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
|
86
|
+
t0.grabbedPoint = this.planet.getCartesianFromPixelTerrain(t0, true);
|
|
87
|
+
|
|
88
|
+
t1.x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
|
|
89
|
+
t1.y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
|
|
90
|
+
t1.prev_x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
|
|
91
|
+
t1.prev_y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
|
|
92
|
+
t1.grabbedPoint = this.planet.getCartesianFromPixelTerrain(t1, true);
|
|
93
|
+
|
|
94
|
+
// this.planet._viewChanged = true;
|
|
95
|
+
this.pointOnEarth = this.planet.getCartesianFromPixelTerrain(
|
|
96
|
+
this.renderer.handler.getCenter(),
|
|
97
|
+
true
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (this.pointOnEarth) {
|
|
101
|
+
this.earthUp = this.pointOnEarth.normal();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (t0.grabbedPoint && t1.grabbedPoint) {
|
|
105
|
+
t0.grabbedSpheroid.radius = t0.grabbedPoint.length();
|
|
106
|
+
t1.grabbedSpheroid.radius = t1.grabbedPoint.length();
|
|
107
|
+
this.stopRotation();
|
|
108
|
+
}
|
|
109
|
+
} else if (e.sys.touches.length === 1) {
|
|
110
|
+
this._startTouchOne(e);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
_startTouchOne(e) {
|
|
115
|
+
var t = this.touches[0];
|
|
116
|
+
|
|
117
|
+
t.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
|
118
|
+
t.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
|
119
|
+
t.prev_x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
|
120
|
+
t.prev_y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
|
121
|
+
|
|
122
|
+
t.grabbedPoint = this.planet.getCartesianFromPixelTerrain(t, true);
|
|
123
|
+
this._eye0.copy(this.renderer.activeCamera.eye);
|
|
124
|
+
|
|
125
|
+
if (t.grabbedPoint) {
|
|
126
|
+
t.grabbedSpheroid.radius = t.grabbedPoint.length();
|
|
127
|
+
this.stopRotation();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
stopRotation() {
|
|
132
|
+
this.qRot.clear();
|
|
133
|
+
this.planet.layerLock.free(this._keyLock);
|
|
134
|
+
this.planet.terrainLock.free(this._keyLock);
|
|
135
|
+
this.planet._normalMapCreator.free(this._keyLock);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
onDoubleTouch(e) {
|
|
139
|
+
if (this.stepIndex) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this.planet.stopFlying();
|
|
144
|
+
this.stopRotation();
|
|
145
|
+
var p = this.planet.getCartesianFromPixelTerrain(this.touches[0], true);
|
|
146
|
+
if (p) {
|
|
147
|
+
var g = this.planet.ellipsoid.cartesianToLonLat(p);
|
|
148
|
+
this.planet.flyLonLat(
|
|
149
|
+
new LonLat(g.lon, g.lat, this.renderer.activeCamera.eye.distance(p) * 0.57)
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
onTouchEnd(e) {
|
|
155
|
+
if (e.sys.touches.length === 0) {
|
|
156
|
+
this._touching = false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (e.sys.touches.length === 1) {
|
|
160
|
+
this._startTouchOne(e);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (
|
|
164
|
+
Math.abs(this.touches[0].x - this.touches[0].prev_x) < 3 &&
|
|
165
|
+
Math.abs(this.touches[0].y - this.touches[0].prev_y) < 3
|
|
166
|
+
) {
|
|
167
|
+
this.scaleRot = 0;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
onTouchCancel(e) {}
|
|
172
|
+
|
|
173
|
+
onTouchMove(e) {
|
|
174
|
+
var cam = this.renderer.activeCamera;
|
|
175
|
+
|
|
176
|
+
if (e.sys.touches.length === 2) {
|
|
177
|
+
this.renderer.controlsBag.scaleRot = 1;
|
|
178
|
+
|
|
179
|
+
var t0 = this.touches[0],
|
|
180
|
+
t1 = this.touches[1];
|
|
181
|
+
|
|
182
|
+
if (!t0.grabbedPoint || !t1.grabbedPoint) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
this.planet.stopFlying();
|
|
187
|
+
|
|
188
|
+
t0.prev_x = t0.x;
|
|
189
|
+
t0.prev_y = t0.y;
|
|
190
|
+
t0.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
|
191
|
+
t0.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
|
192
|
+
|
|
193
|
+
t1.prev_x = t1.x;
|
|
194
|
+
t1.prev_y = t1.y;
|
|
195
|
+
t1.x = e.sys.touches.item(1).clientX - e.sys.offsetLeft;
|
|
196
|
+
t1.y = e.sys.touches.item(1).clientY - e.sys.offsetTop;
|
|
197
|
+
|
|
198
|
+
// distance = Math.sqrt((t0.prev_x-t1.prev_x)**2+(t0.prev_y-t1.prev_y)**2) - Math.sqrt((t0.x-t1.x)**2 + (t0.y-t1.y)**2))
|
|
199
|
+
// distance < 0 --> zoomIn; distance > 0 --> zoomOut
|
|
200
|
+
var t0t1Distance = Math.abs(t0.prev_x - t1.prev_x) + Math.abs(t0.prev_y - t1.prev_y) - (Math.abs(t0.x - t1.x) + Math.abs(t0.y - t1.y))
|
|
201
|
+
var _move = 0
|
|
202
|
+
var _targetPoint = this.renderer.getCenter()
|
|
203
|
+
var d =
|
|
204
|
+
cam.eye.distance(
|
|
205
|
+
this.planet.getCartesianFromPixelTerrain(_targetPoint, true)
|
|
206
|
+
) * 0.075;
|
|
207
|
+
if (t0t1Distance < 0) {
|
|
208
|
+
_move = 1
|
|
209
|
+
}
|
|
210
|
+
if (t0t1Distance > 0) {
|
|
211
|
+
_move = -1
|
|
212
|
+
}
|
|
213
|
+
if (_move !== 0) {
|
|
214
|
+
cam.eye.addA(cam.getForward().scale(_move * d));
|
|
215
|
+
cam.checkTerrainCollision();
|
|
216
|
+
cam.update();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (
|
|
220
|
+
(t0.dY() > 0 && t1.dY() > 0) ||
|
|
221
|
+
(t0.dY() < 0 && t1.dY() < 0) ||
|
|
222
|
+
(t0.dX() > 0 && t1.dX() > 0) ||
|
|
223
|
+
(t0.dX() < 0 && t1.dX() < 0)
|
|
224
|
+
) {
|
|
225
|
+
var l =
|
|
226
|
+
(0.5 / cam.eye.distance(this.pointOnEarth)) * cam._lonLat.height * math.RADIANS;
|
|
227
|
+
if (l > 0.007) l = 0.007;
|
|
228
|
+
cam.rotateHorizontal(l * t0.dX(), false, this.pointOnEarth, this.earthUp);
|
|
229
|
+
cam.rotateVertical(l * t0.dY(), this.pointOnEarth, true);
|
|
230
|
+
cam.checkTerrainCollision();
|
|
231
|
+
cam.update();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
this.scaleRot = 0;
|
|
235
|
+
} else if (e.sys.touches.length === 1) {
|
|
236
|
+
var t = this.touches[0];
|
|
237
|
+
|
|
238
|
+
t.prev_x = t.x;
|
|
239
|
+
t.prev_y = t.y;
|
|
240
|
+
t.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
|
|
241
|
+
t.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
|
|
242
|
+
|
|
243
|
+
if (!t.grabbedPoint) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
this.planet.stopFlying();
|
|
248
|
+
|
|
249
|
+
var direction = cam.unproject(t.x, t.y);
|
|
250
|
+
var targetPoint = new Ray(cam.eye, direction).hitSphere(t.grabbedSpheroid);
|
|
251
|
+
|
|
252
|
+
if (targetPoint) {
|
|
253
|
+
if (cam.slope > 0.2) {
|
|
254
|
+
this.qRot = Quat.getRotationBetweenVectors(
|
|
255
|
+
targetPoint.normal(),
|
|
256
|
+
t.grabbedPoint.normal()
|
|
257
|
+
);
|
|
258
|
+
var rot = this.qRot;
|
|
259
|
+
cam.eye = rot.mulVec3(cam.eye);
|
|
260
|
+
cam._r = rot.mulVec3(cam._r);
|
|
261
|
+
cam._u = rot.mulVec3(cam._u);
|
|
262
|
+
cam._b = rot.mulVec3(cam._b);
|
|
263
|
+
cam.checkTerrainCollision();
|
|
264
|
+
cam.update();
|
|
265
|
+
this.scaleRot = 1;
|
|
266
|
+
} else {
|
|
267
|
+
var p0 = t.grabbedPoint,
|
|
268
|
+
p1 = Vec3.add(p0, cam._u),
|
|
269
|
+
p2 = Vec3.add(p0, p0.normal());
|
|
270
|
+
var dir = cam.unproject(t.x, t.y);
|
|
271
|
+
var px = new Vec3();
|
|
272
|
+
if (new Ray(cam.eye, dir).hitPlane(p0, p1, p2, px) === Ray.INSIDE) {
|
|
273
|
+
cam.eye = this._eye0.addA(px.subA(p0).negate());
|
|
274
|
+
cam.checkTerrainCollision();
|
|
275
|
+
cam.update();
|
|
276
|
+
this.scaleRot = 0;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
onDraw(e) {
|
|
284
|
+
this.renderer.controlsBag.scaleRot = this.scaleRot;
|
|
285
|
+
|
|
286
|
+
if (this._touching) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
var r = this.renderer;
|
|
291
|
+
var cam = r.activeCamera;
|
|
292
|
+
var prevEye = cam.eye.clone();
|
|
293
|
+
|
|
294
|
+
if (this.stepIndex) {
|
|
295
|
+
r.controlsBag.scaleRot = 1;
|
|
296
|
+
var sf = this.stepsForward[this.stepsCount - this.stepIndex--];
|
|
297
|
+
cam.eye = sf.eye;
|
|
298
|
+
cam._r = sf.v;
|
|
299
|
+
cam._u = sf.u;
|
|
300
|
+
cam._b = sf.n;
|
|
301
|
+
cam.checkTerrainCollision();
|
|
302
|
+
cam.update();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (r.events.mouseState.leftButtonDown || !this.scaleRot) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
this.scaleRot -= this.inertia;
|
|
310
|
+
if (this.scaleRot <= 0) {
|
|
311
|
+
this.scaleRot = 0;
|
|
312
|
+
} else {
|
|
313
|
+
r.controlsBag.scaleRot = this.scaleRot;
|
|
314
|
+
var rot = this.qRot
|
|
315
|
+
.slerp(Quat.IDENTITY, 1 - this.scaleRot * this.scaleRot * this.scaleRot)
|
|
316
|
+
.normalize();
|
|
317
|
+
if (!(rot.x || rot.y || rot.z)) {
|
|
318
|
+
this.scaleRot = 0;
|
|
319
|
+
}
|
|
320
|
+
cam.eye = rot.mulVec3(cam.eye);
|
|
321
|
+
cam._r = rot.mulVec3(cam._r);
|
|
322
|
+
cam._u = rot.mulVec3(cam._u);
|
|
323
|
+
cam._b = rot.mulVec3(cam._b);
|
|
324
|
+
cam.checkTerrainCollision();
|
|
325
|
+
cam.update();
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (cam.eye.distance(prevEye) / cam._terrainAltitude > 0.01) {
|
|
329
|
+
this.planet.layerLock.lock(this._keyLock);
|
|
330
|
+
this.planet.terrainLock.lock(this._keyLock);
|
|
331
|
+
this.planet._normalMapCreator.lock(this._keyLock);
|
|
332
|
+
} else {
|
|
333
|
+
this.planet.layerLock.free(this._keyLock);
|
|
334
|
+
this.planet.terrainLock.free(this._keyLock);
|
|
335
|
+
this.planet._normalMapCreator.free(this._keyLock);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export { TouchNavigation };
|