@openglobus/og 0.12.1 → 0.13.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.
Files changed (230) hide show
  1. package/README.md +0 -2
  2. package/dist/@openglobus/og.css +1 -0
  3. package/dist/@openglobus/og.esm.js +21 -0
  4. package/dist/@openglobus/og.esm.js.map +1 -0
  5. package/dist/@openglobus/og.umd.js +21 -0
  6. package/dist/@openglobus/og.umd.js.map +1 -0
  7. package/package.json +8 -8
  8. package/src/og/Extent.js +3 -3
  9. package/src/og/Globe.js +277 -275
  10. package/src/og/ImageCanvas.js +3 -3
  11. package/src/og/LonLat.js +9 -9
  12. package/src/og/QueueArray.js +2 -2
  13. package/src/og/Rectangle.js +5 -5
  14. package/src/og/bv/Box.js +1 -1
  15. package/src/og/bv/Sphere.js +2 -2
  16. package/src/og/camera/Camera.js +1 -1
  17. package/src/og/camera/PlanetCamera.js +649 -646
  18. package/src/og/control/LayerSwitcher.js +1 -1
  19. package/src/og/control/MouseNavigation.js +22 -13
  20. package/src/og/control/MouseWheelZoomControl.js +2 -2
  21. package/src/og/control/ScaleControl.js +1 -1
  22. package/src/og/control/TouchNavigation.js +319 -319
  23. package/src/og/control/ZoomControl.js +132 -132
  24. package/src/og/control/visibleExtent/Segment.js +12 -12
  25. package/src/og/ellipsoid/Ellipsoid.js +577 -567
  26. package/src/og/entity/BillboardHandler.js +878 -1051
  27. package/src/og/entity/Entity.js +1 -1
  28. package/src/og/entity/EntityCollection.js +847 -857
  29. package/src/og/entity/GeoObjectHandler.js +37 -18
  30. package/src/og/entity/LabelHandler.js +888 -1040
  31. package/src/og/entity/LabelWorker.js +0 -6
  32. package/src/og/entity/PointCloud.js +495 -495
  33. package/src/og/entity/Polyline.js +2218 -2222
  34. package/src/og/entity/RayHandler.js +1 -1
  35. package/src/og/layer/CanvasTiles.js +6 -3
  36. package/src/og/layer/GeoImage.js +1 -1
  37. package/src/og/layer/KML.js +24 -17
  38. package/src/og/layer/Layer.js +806 -751
  39. package/src/og/layer/Vector.js +997 -1010
  40. package/src/og/layer/XYZ.js +359 -357
  41. package/src/og/math/Line2.js +4 -4
  42. package/src/og/math/Quat.js +2 -2
  43. package/src/og/math/Ray.js +2 -2
  44. package/src/og/math/Vec2.js +524 -524
  45. package/src/og/math/Vec3.js +900 -900
  46. package/src/og/math/Vec4.js +261 -261
  47. package/src/og/math.js +397 -398
  48. package/src/og/quadTree/EntityCollectionNode.js +389 -387
  49. package/src/og/renderer/Renderer.js +14 -20
  50. package/src/og/renderer/RendererEvents.js +1034 -1045
  51. package/src/og/scene/Planet.js +26 -23
  52. package/src/og/scene/RenderNode.js +347 -354
  53. package/src/og/segment/Segment.js +3 -1
  54. package/src/og/segment/SegmentLonLat.js +1 -4
  55. package/src/og/shaders/billboard.js +220 -204
  56. package/src/og/shaders/drawnode.js +603 -603
  57. package/src/og/shaders/geoObject.js +15 -6
  58. package/src/og/shaders/label.js +596 -456
  59. package/src/og/shaders/polyline.js +365 -361
  60. package/src/og/terrain/MapboxTerrain.js +1 -1
  61. package/src/og/utils/FontAtlas.js +209 -200
  62. package/src/og/utils/GeoImageCreator.js +4 -5
  63. package/src/og/utils/TextureAtlas.js +4 -4
  64. package/src/og/utils/VectorTileCreator.js +414 -414
  65. package/src/og/utils/shared.js +1 -1
  66. package/src/og/webgl/Handler.js +28 -60
  67. package/src/og/webgl/Multisample.js +260 -260
  68. package/src/og/webgl/Program.js +411 -396
  69. package/types/Clock.d.ts +94 -0
  70. package/types/Deferred.d.ts +6 -0
  71. package/types/Events.d.ts +77 -0
  72. package/types/Extent.d.ts +166 -0
  73. package/types/Globe.d.ts +85 -0
  74. package/types/ImageCanvas.d.ts +123 -0
  75. package/types/Lock.d.ts +12 -0
  76. package/types/LonLat.d.ts +108 -0
  77. package/types/Popup.d.ts +42 -0
  78. package/types/QueueArray.d.ts +19 -0
  79. package/types/Rectangle.d.ts +80 -0
  80. package/types/Stack.d.ts +19 -0
  81. package/types/ajax.d.ts +24 -0
  82. package/types/arial.d.ts +48 -0
  83. package/types/astro/astro.d.ts +38 -0
  84. package/types/astro/earth.d.ts +7 -0
  85. package/types/astro/jd.d.ts +254 -0
  86. package/types/bv/Box.d.ts +30 -0
  87. package/types/bv/Sphere.d.ts +38 -0
  88. package/types/bv/index.d.ts +3 -0
  89. package/types/camera/Camera.d.ts +312 -0
  90. package/types/camera/Frustum.d.ts +133 -0
  91. package/types/camera/PlanetCamera.d.ts +219 -0
  92. package/types/camera/index.d.ts +3 -0
  93. package/types/cons.d.ts +40 -0
  94. package/types/control/CompassButton.d.ts +17 -0
  95. package/types/control/Control.d.ts +104 -0
  96. package/types/control/DebugInfo.d.ts +15 -0
  97. package/types/control/EarthCoordinates.d.ts +47 -0
  98. package/types/control/EarthNavigation.d.ts +43 -0
  99. package/types/control/GeoImageDragControl.d.ts +6 -0
  100. package/types/control/KeyboardNavigation.d.ts +21 -0
  101. package/types/control/LayerSwitcher.d.ts +21 -0
  102. package/types/control/Lighting.d.ts +16 -0
  103. package/types/control/MouseNavigation.d.ts +48 -0
  104. package/types/control/MouseWheelZoomControl.d.ts +45 -0
  105. package/types/control/ScaleControl.d.ts +22 -0
  106. package/types/control/ShowFps.d.ts +11 -0
  107. package/types/control/SimpleNavigation.d.ts +25 -0
  108. package/types/control/Sun.d.ts +50 -0
  109. package/types/control/ToggleWireframe.d.ts +12 -0
  110. package/types/control/TouchNavigation.d.ts +48 -0
  111. package/types/control/ZoomControl.d.ts +27 -0
  112. package/types/control/index.d.ts +18 -0
  113. package/types/ellipsoid/Ellipsoid.d.ts +153 -0
  114. package/types/ellipsoid/index.d.ts +3 -0
  115. package/types/ellipsoid/wgs84.d.ts +6 -0
  116. package/types/entity/BaseBillboard.d.ts +215 -0
  117. package/types/entity/Billboard.d.ts +94 -0
  118. package/types/entity/BillboardHandler.d.ts +75 -0
  119. package/types/entity/Entity.d.ts +348 -0
  120. package/types/entity/EntityCollection.d.ts +309 -0
  121. package/types/entity/GeoObject.d.ts +111 -0
  122. package/types/entity/GeoObjectHandler.d.ts +81 -0
  123. package/types/entity/Geometry.d.ts +74 -0
  124. package/types/entity/GeometryHandler.d.ts +76 -0
  125. package/types/entity/Label.d.ts +189 -0
  126. package/types/entity/LabelHandler.d.ts +29 -0
  127. package/types/entity/LabelWorker.d.ts +11 -0
  128. package/types/entity/PointCloud.d.ts +174 -0
  129. package/types/entity/PointCloudHandler.d.ts +38 -0
  130. package/types/entity/Polyline.d.ts +306 -0
  131. package/types/entity/PolylineHandler.d.ts +18 -0
  132. package/types/entity/Ray.d.ts +124 -0
  133. package/types/entity/RayHandler.d.ts +67 -0
  134. package/types/entity/ShapeHandler.d.ts +22 -0
  135. package/types/entity/Strip.d.ts +119 -0
  136. package/types/entity/StripHandler.d.ts +38 -0
  137. package/types/entity/index.d.ts +8 -0
  138. package/types/index.core.d.ts +65 -0
  139. package/types/index.d.ts +45 -0
  140. package/types/index.webgl.d.ts +7 -0
  141. package/types/input/KeyboardHandler.d.ts +10 -0
  142. package/types/input/MouseHandler.d.ts +5 -0
  143. package/types/input/TouchHandler.d.ts +5 -0
  144. package/types/input/input.d.ts +34 -0
  145. package/types/layer/BaseGeoImage.d.ts +94 -0
  146. package/types/layer/CanvasTiles.d.ts +67 -0
  147. package/types/layer/GeoImage.d.ts +52 -0
  148. package/types/layer/GeoTexture2d.d.ts +8 -0
  149. package/types/layer/GeoVideo.d.ts +55 -0
  150. package/types/layer/KML.d.ts +68 -0
  151. package/types/layer/Layer.d.ts +315 -0
  152. package/types/layer/Material.d.ts +45 -0
  153. package/types/layer/Vector.d.ts +201 -0
  154. package/types/layer/WMS.d.ts +61 -0
  155. package/types/layer/XYZ.d.ts +119 -0
  156. package/types/layer/index.d.ts +10 -0
  157. package/types/light/LightSource.d.ts +178 -0
  158. package/types/math/Line2.d.ts +11 -0
  159. package/types/math/Line3.d.ts +10 -0
  160. package/types/math/Mat3.d.ts +65 -0
  161. package/types/math/Mat4.d.ts +176 -0
  162. package/types/math/Plane.d.ts +18 -0
  163. package/types/math/Quat.d.ts +379 -0
  164. package/types/math/Ray.d.ts +82 -0
  165. package/types/math/Vec2.d.ts +309 -0
  166. package/types/math/Vec3.d.ts +467 -0
  167. package/types/math/Vec4.d.ts +162 -0
  168. package/types/math/coder.d.ts +43 -0
  169. package/types/math/index.d.ts +11 -0
  170. package/types/math.d.ts +261 -0
  171. package/types/mercator.d.ts +92 -0
  172. package/types/proj/EPSG3857.d.ts +6 -0
  173. package/types/proj/EPSG4326.d.ts +6 -0
  174. package/types/proj/Proj.d.ts +42 -0
  175. package/types/quadTree/EntityCollectionNode.d.ts +34 -0
  176. package/types/quadTree/Node.d.ts +60 -0
  177. package/types/quadTree/quadTree.d.ts +40 -0
  178. package/types/renderer/Renderer.d.ts +290 -0
  179. package/types/renderer/RendererEvents.d.ts +237 -0
  180. package/types/res/images.d.ts +3 -0
  181. package/types/scene/Axes.d.ts +11 -0
  182. package/types/scene/BaseNode.d.ts +60 -0
  183. package/types/scene/Planet.d.ts +576 -0
  184. package/types/scene/RenderNode.d.ts +142 -0
  185. package/types/scene/SkyBox.d.ts +10 -0
  186. package/types/scene/index.d.ts +4 -0
  187. package/types/segment/Segment.d.ts +275 -0
  188. package/types/segment/SegmentLonLat.d.ts +17 -0
  189. package/types/segment/Slice.d.ts +10 -0
  190. package/types/segment/segmentHelper.d.ts +13 -0
  191. package/types/shaders/billboard.d.ts +3 -0
  192. package/types/shaders/depth.d.ts +2 -0
  193. package/types/shaders/drawnode.d.ts +7 -0
  194. package/types/shaders/geoObject.d.ts +3 -0
  195. package/types/shaders/label.d.ts +4 -0
  196. package/types/shaders/pointCloud.d.ts +2 -0
  197. package/types/shaders/polyline.d.ts +3 -0
  198. package/types/shaders/ray.d.ts +2 -0
  199. package/types/shaders/screenFrame.d.ts +2 -0
  200. package/types/shaders/shape.d.ts +4 -0
  201. package/types/shaders/skybox.d.ts +2 -0
  202. package/types/shaders/toneMapping.d.ts +2 -0
  203. package/types/shapes/BaseShape.d.ts +250 -0
  204. package/types/shapes/Sphere.d.ts +41 -0
  205. package/types/terrain/BilTerrain.d.ts +7 -0
  206. package/types/terrain/EmptyTerrain.d.ts +73 -0
  207. package/types/terrain/Geoid.d.ts +26 -0
  208. package/types/terrain/GlobusTerrain.d.ts +116 -0
  209. package/types/terrain/MapboxTerrain.d.ts +7 -0
  210. package/types/terrain/index.d.ts +5 -0
  211. package/types/utils/FontAtlas.d.ts +16 -0
  212. package/types/utils/GeoImageCreator.d.ts +30 -0
  213. package/types/utils/ImagesCacheManager.d.ts +10 -0
  214. package/types/utils/Loader.d.ts +25 -0
  215. package/types/utils/NormalMapCreator.d.ts +39 -0
  216. package/types/utils/PlainSegmentWorker.d.ts +10 -0
  217. package/types/utils/TerrainWorker.d.ts +9 -0
  218. package/types/utils/TextureAtlas.d.ts +111 -0
  219. package/types/utils/VectorTileCreator.d.ts +16 -0
  220. package/types/utils/colorTable.d.ts +143 -0
  221. package/types/utils/earcut.d.ts +6 -0
  222. package/types/utils/shared.d.ts +231 -0
  223. package/types/webgl/Framebuffer.d.ts +135 -0
  224. package/types/webgl/Handler.d.ts +392 -0
  225. package/types/webgl/Multisample.d.ts +89 -0
  226. package/types/webgl/Program.d.ts +163 -0
  227. package/types/webgl/ProgramController.d.ts +89 -0
  228. package/types/webgl/callbacks.d.ts +1 -0
  229. package/types/webgl/index.d.ts +6 -0
  230. package/types/webgl/types.d.ts +2 -0
@@ -1,319 +1,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
- if (
199
- (t0.dY() > 0 && t1.dY() > 0) ||
200
- (t0.dY() < 0 && t1.dY() < 0) ||
201
- (t0.dX() > 0 && t1.dX() > 0) ||
202
- (t0.dX() < 0 && t1.dX() < 0)
203
- ) {
204
- var l =
205
- (0.5 / cam.eye.distance(this.pointOnEarth)) * cam._lonLat.height * math.RADIANS;
206
- if (l > 0.007) l = 0.007;
207
- cam.rotateHorizontal(l * t0.dX(), false, this.pointOnEarth, this.earthUp);
208
- cam.rotateVertical(l * t0.dY(), this.pointOnEarth, true);
209
- cam.checkTerrainCollision();
210
- cam.update();
211
- }
212
-
213
- this.scaleRot = 0;
214
- } else if (e.sys.touches.length === 1) {
215
- var t = this.touches[0];
216
-
217
- t.prev_x = t.x;
218
- t.prev_y = t.y;
219
- t.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
220
- t.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
221
-
222
- if (!t.grabbedPoint) {
223
- return;
224
- }
225
-
226
- this.planet.stopFlying();
227
-
228
- var direction = cam.unproject(t.x, t.y);
229
- var targetPoint = new Ray(cam.eye, direction).hitSphere(t.grabbedSpheroid);
230
-
231
- if (targetPoint) {
232
- if (cam.slope > 0.2) {
233
- this.qRot = Quat.getRotationBetweenVectors(
234
- targetPoint.normal(),
235
- t.grabbedPoint.normal()
236
- );
237
- var rot = this.qRot;
238
- cam.eye = rot.mulVec3(cam.eye);
239
- cam._v = rot.mulVec3(cam._v);
240
- cam._u = rot.mulVec3(cam._u);
241
- cam._n = rot.mulVec3(cam._n);
242
- cam.checkTerrainCollision();
243
- cam.update();
244
- this.scaleRot = 1;
245
- } else {
246
- var p0 = t.grabbedPoint,
247
- p1 = Vec3.add(p0, cam._u),
248
- p2 = Vec3.add(p0, p0.normal());
249
- var dir = cam.unproject(t.x, t.y);
250
- var px = new Vec3();
251
- if (new Ray(cam.eye, dir).hitPlane(p0, p1, p2, px) === Ray.INSIDE) {
252
- cam.eye = this._eye0.addA(px.subA(p0).negate());
253
- cam.checkTerrainCollision();
254
- cam.update();
255
- this.scaleRot = 0;
256
- }
257
- }
258
- }
259
- }
260
- }
261
-
262
- onDraw(e) {
263
- this.renderer.controlsBag.scaleRot = this.scaleRot;
264
-
265
- if (this._touching) {
266
- return;
267
- }
268
-
269
- var r = this.renderer;
270
- var cam = r.activeCamera;
271
- var prevEye = cam.eye.clone();
272
-
273
- if (this.stepIndex) {
274
- r.controlsBag.scaleRot = 1;
275
- var sf = this.stepsForward[this.stepsCount - this.stepIndex--];
276
- cam.eye = sf.eye;
277
- cam._v = sf.v;
278
- cam._u = sf.u;
279
- cam._n = sf.n;
280
- cam.checkTerrainCollision();
281
- cam.update();
282
- }
283
-
284
- if (r.events.mouseState.leftButtonDown || !this.scaleRot) {
285
- return;
286
- }
287
-
288
- this.scaleRot -= this.inertia;
289
- if (this.scaleRot <= 0) {
290
- this.scaleRot = 0;
291
- } else {
292
- r.controlsBag.scaleRot = this.scaleRot;
293
- var rot = this.qRot
294
- .slerp(Quat.IDENTITY, 1 - this.scaleRot * this.scaleRot * this.scaleRot)
295
- .normalize();
296
- if (!(rot.x || rot.y || rot.z)) {
297
- this.scaleRot = 0;
298
- }
299
- cam.eye = rot.mulVec3(cam.eye);
300
- cam._v = rot.mulVec3(cam._v);
301
- cam._u = rot.mulVec3(cam._u);
302
- cam._n = rot.mulVec3(cam._n);
303
- cam.checkTerrainCollision();
304
- cam.update();
305
- }
306
-
307
- if (cam.eye.distance(prevEye) / cam._terrainAltitude > 0.01) {
308
- this.planet.layerLock.lock(this._keyLock);
309
- this.planet.terrainLock.lock(this._keyLock);
310
- this.planet._normalMapCreator.lock(this._keyLock);
311
- } else {
312
- this.planet.layerLock.free(this._keyLock);
313
- this.planet.terrainLock.free(this._keyLock);
314
- this.planet._normalMapCreator.free(this._keyLock);
315
- }
316
- }
317
- }
318
-
319
- export { TouchNavigation };
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
+ if (
199
+ (t0.dY() > 0 && t1.dY() > 0) ||
200
+ (t0.dY() < 0 && t1.dY() < 0) ||
201
+ (t0.dX() > 0 && t1.dX() > 0) ||
202
+ (t0.dX() < 0 && t1.dX() < 0)
203
+ ) {
204
+ var l =
205
+ (0.5 / cam.eye.distance(this.pointOnEarth)) * cam._lonLat.height * math.RADIANS;
206
+ if (l > 0.007) l = 0.007;
207
+ cam.rotateHorizontal(l * t0.dX(), false, this.pointOnEarth, this.earthUp);
208
+ cam.rotateVertical(l * t0.dY(), this.pointOnEarth, true);
209
+ cam.checkTerrainCollision();
210
+ cam.update();
211
+ }
212
+
213
+ this.scaleRot = 0;
214
+ } else if (e.sys.touches.length === 1) {
215
+ var t = this.touches[0];
216
+
217
+ t.prev_x = t.x;
218
+ t.prev_y = t.y;
219
+ t.x = e.sys.touches.item(0).clientX - e.sys.offsetLeft;
220
+ t.y = e.sys.touches.item(0).clientY - e.sys.offsetTop;
221
+
222
+ if (!t.grabbedPoint) {
223
+ return;
224
+ }
225
+
226
+ this.planet.stopFlying();
227
+
228
+ var direction = cam.unproject(t.x, t.y);
229
+ var targetPoint = new Ray(cam.eye, direction).hitSphere(t.grabbedSpheroid);
230
+
231
+ if (targetPoint) {
232
+ if (cam.slope > 0.2) {
233
+ this.qRot = Quat.getRotationBetweenVectors(
234
+ targetPoint.normal(),
235
+ t.grabbedPoint.normal()
236
+ );
237
+ var rot = this.qRot;
238
+ cam.eye = rot.mulVec3(cam.eye);
239
+ cam._r = rot.mulVec3(cam._r);
240
+ cam._u = rot.mulVec3(cam._u);
241
+ cam._b = rot.mulVec3(cam._b);
242
+ cam.checkTerrainCollision();
243
+ cam.update();
244
+ this.scaleRot = 1;
245
+ } else {
246
+ var p0 = t.grabbedPoint,
247
+ p1 = Vec3.add(p0, cam._u),
248
+ p2 = Vec3.add(p0, p0.normal());
249
+ var dir = cam.unproject(t.x, t.y);
250
+ var px = new Vec3();
251
+ if (new Ray(cam.eye, dir).hitPlane(p0, p1, p2, px) === Ray.INSIDE) {
252
+ cam.eye = this._eye0.addA(px.subA(p0).negate());
253
+ cam.checkTerrainCollision();
254
+ cam.update();
255
+ this.scaleRot = 0;
256
+ }
257
+ }
258
+ }
259
+ }
260
+ }
261
+
262
+ onDraw(e) {
263
+ this.renderer.controlsBag.scaleRot = this.scaleRot;
264
+
265
+ if (this._touching) {
266
+ return;
267
+ }
268
+
269
+ var r = this.renderer;
270
+ var cam = r.activeCamera;
271
+ var prevEye = cam.eye.clone();
272
+
273
+ if (this.stepIndex) {
274
+ r.controlsBag.scaleRot = 1;
275
+ var sf = this.stepsForward[this.stepsCount - this.stepIndex--];
276
+ cam.eye = sf.eye;
277
+ cam._r = sf.v;
278
+ cam._u = sf.u;
279
+ cam._b = sf.n;
280
+ cam.checkTerrainCollision();
281
+ cam.update();
282
+ }
283
+
284
+ if (r.events.mouseState.leftButtonDown || !this.scaleRot) {
285
+ return;
286
+ }
287
+
288
+ this.scaleRot -= this.inertia;
289
+ if (this.scaleRot <= 0) {
290
+ this.scaleRot = 0;
291
+ } else {
292
+ r.controlsBag.scaleRot = this.scaleRot;
293
+ var rot = this.qRot
294
+ .slerp(Quat.IDENTITY, 1 - this.scaleRot * this.scaleRot * this.scaleRot)
295
+ .normalize();
296
+ if (!(rot.x || rot.y || rot.z)) {
297
+ this.scaleRot = 0;
298
+ }
299
+ cam.eye = rot.mulVec3(cam.eye);
300
+ cam._r = rot.mulVec3(cam._r);
301
+ cam._u = rot.mulVec3(cam._u);
302
+ cam._b = rot.mulVec3(cam._b);
303
+ cam.checkTerrainCollision();
304
+ cam.update();
305
+ }
306
+
307
+ if (cam.eye.distance(prevEye) / cam._terrainAltitude > 0.01) {
308
+ this.planet.layerLock.lock(this._keyLock);
309
+ this.planet.terrainLock.lock(this._keyLock);
310
+ this.planet._normalMapCreator.lock(this._keyLock);
311
+ } else {
312
+ this.planet.layerLock.free(this._keyLock);
313
+ this.planet.terrainLock.free(this._keyLock);
314
+ this.planet._normalMapCreator.free(this._keyLock);
315
+ }
316
+ }
317
+ }
318
+
319
+ export { TouchNavigation };