@openglobus/og 0.10.4 → 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/css/og.css +1 -1
- package/package.json +11 -9
- package/src/og/Extent.js +274 -273
- package/src/og/Globe.js +11 -3
- package/src/og/LonLat.js +152 -146
- package/src/og/Popup.js +2 -1
- package/src/og/camera/PlanetCamera.js +112 -38
- package/src/og/control/EarthNavigation.js +259 -0
- package/src/og/control/MouseNavigation.js +68 -40
- 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/CanvasTiles.js +32 -30
- package/src/og/layer/KML.js +159 -0
- 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/quadTree/Node.js +67 -13
- package/src/og/renderer/RendererEvents.js +21 -16
- package/src/og/scene/Planet.js +25 -10
- package/src/og/segment/Segment.js +3 -3
- package/src/og/segment/SegmentLonLat.js +7 -0
- package/src/og/terrain/GlobusTerrain.js +4 -0
- package/src/og/utils/FontAtlas.js +1 -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 -1001
- 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
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import * as math from "../math.js";
|
|
4
|
+
import { Control } from "./Control.js";
|
|
5
|
+
import { input } from "../input/input.js";
|
|
6
|
+
import { Key } from "../Lock.js";
|
|
7
|
+
import { LonLat } from "../LonLat.js";
|
|
8
|
+
import { Mat4 } from "../math/Mat4.js";
|
|
9
|
+
import { Quat } from "../math/Quat.js";
|
|
10
|
+
import { Ray } from "../math/Ray.js";
|
|
11
|
+
import { Sphere } from "../bv/Sphere.js";
|
|
12
|
+
import { Vec3 } from "../math/Vec3.js";
|
|
13
|
+
|
|
14
|
+
class EarthNavigation extends Control {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
super(options);
|
|
17
|
+
|
|
18
|
+
this.grabbedPoint = new Vec3();
|
|
19
|
+
this.inertia = 0.007;
|
|
20
|
+
this.grabbedSpheroid = new Sphere();
|
|
21
|
+
this.planet = null;
|
|
22
|
+
this._vRot = new Quat();
|
|
23
|
+
this._hRot = new Quat();
|
|
24
|
+
this._a = 0.0;
|
|
25
|
+
this.scaleRot = 0;
|
|
26
|
+
this.currState = 0;
|
|
27
|
+
|
|
28
|
+
this.positionState = [
|
|
29
|
+
{ h: 17119745.303455353, max: 0.99, min: -0.99 },
|
|
30
|
+
{ h: 6866011, max: 0.99, min: -0.99 },
|
|
31
|
+
{ h: 3000000, max: 0.99, min: -0.99 },
|
|
32
|
+
{ h: 1000000, max: 0.99, min: -0.99 },
|
|
33
|
+
{ h: 500000, max: 0.99, min: -0.99 }
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
var Touch = function () {
|
|
37
|
+
this.x = 0;
|
|
38
|
+
this.y = 0;
|
|
39
|
+
this.prev_x = 0;
|
|
40
|
+
this.prev_y = 0;
|
|
41
|
+
this.grabbedPoint = new Vec3();
|
|
42
|
+
this.grabbedSpheroid = new Sphere();
|
|
43
|
+
this.dX = function () {
|
|
44
|
+
return this.x - this.prev_x;
|
|
45
|
+
};
|
|
46
|
+
this.dY = function () {
|
|
47
|
+
return this.y - this.prev_y;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
this.touches = [new Touch(), new Touch()];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
switchZoomState(wheelDelta) {
|
|
55
|
+
this.stopRotation();
|
|
56
|
+
|
|
57
|
+
if (wheelDelta > 0) {
|
|
58
|
+
this.currState++;
|
|
59
|
+
} else {
|
|
60
|
+
this.currState--;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (this.currState <= 0) this.currState = 0;
|
|
64
|
+
|
|
65
|
+
if (this.currState >= this.positionState.length) {
|
|
66
|
+
this.currState = this.positionState.length - 1;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this.planet.stopFlying();
|
|
70
|
+
|
|
71
|
+
var ll = this.renderer.activeCamera._lonLat;
|
|
72
|
+
|
|
73
|
+
globus.planet.flyLonLat(new LonLat(ll.lon, ll.lat, this.positionState[this.currState].h));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
onMouseWheel(event) {
|
|
77
|
+
this.switchZoomState(event.wheelDelta);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
oninit() {
|
|
81
|
+
this.activate();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
onactivate() {
|
|
85
|
+
this.planet = this.renderer.renderNodes.Earth;
|
|
86
|
+
|
|
87
|
+
this.renderer.events.on("mousewheel", this.onMouseWheel, this);
|
|
88
|
+
this.renderer.events.on("lhold", this.onMouseLeftButtonDown, this);
|
|
89
|
+
this.renderer.events.on("ldown", this.onMouseLeftButtonClick, this);
|
|
90
|
+
this.renderer.events.on("lup", this.onMouseLeftButtonUp, this);
|
|
91
|
+
|
|
92
|
+
this.renderer.events.on("touchstart", this.onTouchStart, this);
|
|
93
|
+
this.renderer.events.on("touchend", this.onTouchEnd, this);
|
|
94
|
+
this.renderer.events.on("touchmove", this.onTouchMove, this);
|
|
95
|
+
|
|
96
|
+
this.renderer.events.on("draw", this.onDraw, this);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
onTouchStart(e) {
|
|
100
|
+
if (e.sys.touches.length == 1) {
|
|
101
|
+
var t = this.touches[0];
|
|
102
|
+
|
|
103
|
+
t.x = e.sys.touches.item(0).pageX - e.sys.offsetLeft;
|
|
104
|
+
t.y = e.sys.touches.item(0).pageY - e.sys.offsetTop;
|
|
105
|
+
t.prev_x = e.sys.touches.item(0).pageX - e.sys.offsetLeft;
|
|
106
|
+
t.prev_y = e.sys.touches.item(0).pageY - e.sys.offsetTop;
|
|
107
|
+
|
|
108
|
+
t.grabbedPoint = this.planet.getCartesianFromPixelTerrain(t, true);
|
|
109
|
+
|
|
110
|
+
if (t.grabbedPoint) {
|
|
111
|
+
t.grabbedSpheroid.radius = t.grabbedPoint.length();
|
|
112
|
+
this.stopRotation();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
onTouchEnd(e) {
|
|
118
|
+
if (e.sys.touches.length == 0) {
|
|
119
|
+
this.scaleRot = 1;
|
|
120
|
+
|
|
121
|
+
if (
|
|
122
|
+
Math.abs(this.touches[0].x - this.touches[0].prev_x) < 3 &&
|
|
123
|
+
Math.abs(this.touches[0].y - this.touches[0].prev_y) < 3
|
|
124
|
+
)
|
|
125
|
+
this.stopRotation();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
onTouchMove(e) {
|
|
130
|
+
if (e.sys.touches.length == 1) {
|
|
131
|
+
var cam = this.renderer.activeCamera;
|
|
132
|
+
|
|
133
|
+
var t = this.touches[0];
|
|
134
|
+
|
|
135
|
+
t.prev_x = t.x;
|
|
136
|
+
t.prev_y = t.y;
|
|
137
|
+
t.x = e.sys.touches.item(0).pageX - e.sys.offsetLeft;
|
|
138
|
+
t.y = e.sys.touches.item(0).pageY - e.sys.offsetTop;
|
|
139
|
+
|
|
140
|
+
if (!t.grabbedPoint) return;
|
|
141
|
+
|
|
142
|
+
var direction = cam.unproject(t.x, t.y);
|
|
143
|
+
var targetPoint = new Ray(cam.eye, direction).hitSphere(t.grabbedSpheroid);
|
|
144
|
+
|
|
145
|
+
if (targetPoint) {
|
|
146
|
+
this._a =
|
|
147
|
+
Math.acos(t.grabbedPoint.y / t.grabbedSpheroid.radius) -
|
|
148
|
+
Math.acos(targetPoint.y / t.grabbedSpheroid.radius);
|
|
149
|
+
this._vRot = Quat.axisAngleToQuat(cam._u, this._a);
|
|
150
|
+
this._hRot = Quat.getRotationBetweenVectors(
|
|
151
|
+
new Vec3(targetPoint.x, 0.0, targetPoint.z).normal(),
|
|
152
|
+
new Vec3(t.grabbedPoint.x, 0.0, t.grabbedPoint.z).normal()
|
|
153
|
+
);
|
|
154
|
+
var rot = this._hRot.mul(this._vRot);
|
|
155
|
+
|
|
156
|
+
var state = this.positionState[this.currState];
|
|
157
|
+
var lim = rot.mulVec3(cam.eye).normal().dot(Vec3.UP);
|
|
158
|
+
if (lim > state.max || lim < state.min) {
|
|
159
|
+
rot = Quat.yRotation(rot.getYaw());
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
cam.set(rot.mulVec3(cam.eye), Vec3.ZERO, Vec3.UP);
|
|
163
|
+
cam.update();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
onMouseLeftButtonClick() {
|
|
169
|
+
this.renderer.handler.gl.canvas.classList.add("ogGrabbingPoiner");
|
|
170
|
+
this.grabbedPoint = this.planet.getCartesianFromMouseTerrain(true);
|
|
171
|
+
if (this.grabbedPoint) {
|
|
172
|
+
this.grabbedSpheroid.radius = this.grabbedPoint.length();
|
|
173
|
+
this.stopRotation();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
stopRotation() {
|
|
178
|
+
this.scaleRot = 0.0;
|
|
179
|
+
this._a = 0.0;
|
|
180
|
+
this._vRot.clear();
|
|
181
|
+
this._hRot.clear();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
onMouseLeftButtonUp(e) {
|
|
185
|
+
this.scaleRot = 1;
|
|
186
|
+
this.renderer.handler.gl.canvas.classList.remove("ogGrabbingPoiner");
|
|
187
|
+
|
|
188
|
+
if (Math.abs(e.x - e.prev_x) < 3 && Math.abs(e.y - e.prev_y) < 3) this.stopRotation();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
onMouseLeftButtonDown(e) {
|
|
192
|
+
var cam = this.renderer.activeCamera;
|
|
193
|
+
|
|
194
|
+
if (!this.grabbedPoint || cam.isFlying()) return;
|
|
195
|
+
|
|
196
|
+
if (this.renderer.events.mouseState.moving) {
|
|
197
|
+
var targetPoint = new Ray(cam.eye, e.direction).hitSphere(this.grabbedSpheroid);
|
|
198
|
+
|
|
199
|
+
if (targetPoint) {
|
|
200
|
+
this._a =
|
|
201
|
+
Math.acos(this.grabbedPoint.y / this.grabbedSpheroid.radius) -
|
|
202
|
+
Math.acos(targetPoint.y / this.grabbedSpheroid.radius);
|
|
203
|
+
|
|
204
|
+
this._vRot = Quat.axisAngleToQuat(cam._u, this._a);
|
|
205
|
+
this._hRot = Quat.getRotationBetweenVectors(
|
|
206
|
+
new Vec3(targetPoint.x, 0.0, targetPoint.z).normal(),
|
|
207
|
+
new Vec3(this.grabbedPoint.x, 0.0, this.grabbedPoint.z).normal()
|
|
208
|
+
);
|
|
209
|
+
var rot = this._hRot.mul(this._vRot);
|
|
210
|
+
|
|
211
|
+
var state = this.positionState[this.currState];
|
|
212
|
+
var lim = rot.mulVec3(cam.eye).normal().dot(Vec3.UP);
|
|
213
|
+
if (lim > state.max || lim < state.min) {
|
|
214
|
+
rot = Quat.yRotation(rot.getYaw());
|
|
215
|
+
}
|
|
216
|
+
cam.set(rot.mulVec3(cam.eye), Vec3.ZERO, Vec3.UP);
|
|
217
|
+
cam.update();
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
this.scaleRot = 0;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
onDraw(e) {
|
|
225
|
+
var r = this.renderer;
|
|
226
|
+
var cam = r.activeCamera;
|
|
227
|
+
|
|
228
|
+
if (r.events.mouseState.leftButtonDown || !this.scaleRot || cam.isFlying()) return;
|
|
229
|
+
|
|
230
|
+
this.scaleRot -= this.inertia;
|
|
231
|
+
if (this.scaleRot <= 0) {
|
|
232
|
+
this.scaleRot = 0;
|
|
233
|
+
} else {
|
|
234
|
+
this._vRot = Quat.axisAngleToQuat(cam._u, this._a);
|
|
235
|
+
var rot = this._vRot.mul(this._hRot);
|
|
236
|
+
|
|
237
|
+
var lim = rot.mulVec3(cam.eye).normal().dot(Vec3.UP);
|
|
238
|
+
|
|
239
|
+
var state = this.positionState[this.currState];
|
|
240
|
+
|
|
241
|
+
if (lim > state.max || lim < state.min) {
|
|
242
|
+
rot = Quat.yRotation(rot.getYaw());
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
r.controlsBag.scaleRot = this.scaleRot;
|
|
246
|
+
rot = rot
|
|
247
|
+
.slerp(Quat.IDENTITY, 1 - this.scaleRot * this.scaleRot * this.scaleRot)
|
|
248
|
+
.normalize();
|
|
249
|
+
if (!(rot.x || rot.y || rot.z)) {
|
|
250
|
+
this.scaleRot = 0;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
cam.set(rot.mulVec3(cam.eye), Vec3.ZERO, Vec3.UP);
|
|
254
|
+
cam.update();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export { EarthNavigation };
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
* @module og/control/MouseNavigation
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import * as math from
|
|
8
|
-
import { Control } from
|
|
9
|
-
import { input } from
|
|
10
|
-
import { Key } from
|
|
11
|
-
import { LonLat } from
|
|
12
|
-
import { Mat4 } from
|
|
13
|
-
import { Quat } from
|
|
14
|
-
import { Ray } from
|
|
15
|
-
import { Sphere } from
|
|
16
|
-
import { Vec3 } from
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
import * as math from "../math.js";
|
|
8
|
+
import { Control } from "./Control.js";
|
|
9
|
+
import { input } from "../input/input.js";
|
|
10
|
+
import { Key } from "../Lock.js";
|
|
11
|
+
import { LonLat } from "../LonLat.js";
|
|
12
|
+
import { Mat4 } from "../math/Mat4.js";
|
|
13
|
+
import { Quat } from "../math/Quat.js";
|
|
14
|
+
import { Ray } from "../math/Ray.js";
|
|
15
|
+
import { Sphere } from "../bv/Sphere.js";
|
|
16
|
+
import { Vec3 } from "../math/Vec3.js";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Mouse planet camera dragging control.
|
|
@@ -46,11 +46,12 @@ class MouseNavigation extends Control {
|
|
|
46
46
|
|
|
47
47
|
this._lmbDoubleClickActive = true;
|
|
48
48
|
|
|
49
|
+
this.minSlope = options.minSlope || 0.1;
|
|
50
|
+
|
|
49
51
|
this._keyLock = new Key();
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
static getMovePointsFromPixelTerrain(cam, planet, stepsCount, delta, point, forward, dir) {
|
|
53
|
-
|
|
54
55
|
var steps = [];
|
|
55
56
|
|
|
56
57
|
var eye = cam.eye.clone(),
|
|
@@ -65,12 +66,11 @@ class MouseNavigation extends Control {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
if (a) {
|
|
68
|
-
|
|
69
69
|
if (!dir) {
|
|
70
70
|
dir = Vec3.sub(a, cam.eye).normalize();
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
var d = a ? delta * cam.eye.distance(a) / stepsCount : 1000;
|
|
73
|
+
var d = a ? (delta * cam.eye.distance(a)) / stepsCount : 1000;
|
|
74
74
|
|
|
75
75
|
if (forward) {
|
|
76
76
|
d = -d;
|
|
@@ -163,7 +163,7 @@ class MouseNavigation extends Control {
|
|
|
163
163
|
this.renderer.events.off("ldblclick", this.onMouseLeftButtonDoubleClick);
|
|
164
164
|
this.renderer.events.off("mouseleave", this.onMouseLeave);
|
|
165
165
|
this.renderer.events.off("mouseenter", this.onMouseEnter);
|
|
166
|
-
}
|
|
166
|
+
}
|
|
167
167
|
|
|
168
168
|
activateDoubleClickZoom() {
|
|
169
169
|
if (!this._lmbDoubleClickActive) {
|
|
@@ -180,8 +180,16 @@ class MouseNavigation extends Control {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
onMouseEnter(e) {
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
const renderEvents = this.renderer.events;
|
|
184
|
+
if (renderEvents.isKeyPressed(input.KEY_ALT)) {
|
|
185
|
+
renderEvents.releaseKeys();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
renderEvents.updateButtonsStates(e.buttons);
|
|
189
|
+
if (renderEvents.mouseState.leftButtonDown) {
|
|
190
|
+
this.renderer.handler.canvas.classList.add("ogGrabbingPoiner");
|
|
191
|
+
} else {
|
|
192
|
+
this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner");
|
|
185
193
|
}
|
|
186
194
|
}
|
|
187
195
|
|
|
@@ -189,10 +197,10 @@ class MouseNavigation extends Control {
|
|
|
189
197
|
if (this.renderer.events.mouseState.leftButtonDown) {
|
|
190
198
|
this.scaleRot = 0;
|
|
191
199
|
}
|
|
200
|
+
this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner");
|
|
192
201
|
}
|
|
193
202
|
|
|
194
203
|
onMouseWheel(event) {
|
|
195
|
-
|
|
196
204
|
if (this.stepIndex) {
|
|
197
205
|
return;
|
|
198
206
|
}
|
|
@@ -208,8 +216,15 @@ class MouseNavigation extends Control {
|
|
|
208
216
|
this.planet._normalMapCreator.lock(this._keyLock);
|
|
209
217
|
|
|
210
218
|
var ms = this.renderer.events.mouseState;
|
|
211
|
-
this.stepsForward = MouseNavigation.getMovePointsFromPixelTerrain(
|
|
212
|
-
this.
|
|
219
|
+
this.stepsForward = MouseNavigation.getMovePointsFromPixelTerrain(
|
|
220
|
+
this.renderer.activeCamera,
|
|
221
|
+
this.planet,
|
|
222
|
+
this.stepsCount,
|
|
223
|
+
this.distDiff,
|
|
224
|
+
ms,
|
|
225
|
+
event.wheelDelta > 0,
|
|
226
|
+
ms.direction
|
|
227
|
+
);
|
|
213
228
|
if (this.stepsForward) {
|
|
214
229
|
this.stepIndex = this.stepsCount;
|
|
215
230
|
}
|
|
@@ -229,9 +244,13 @@ class MouseNavigation extends Control {
|
|
|
229
244
|
if (p) {
|
|
230
245
|
var g = this.planet.ellipsoid.cartesianToLonLat(p);
|
|
231
246
|
if (this.renderer.events.isKeyPressed(input.KEY_ALT)) {
|
|
232
|
-
this.planet.flyLonLat(
|
|
247
|
+
this.planet.flyLonLat(
|
|
248
|
+
new LonLat(g.lon, g.lat, this.renderer.activeCamera.eye.distance(p) * 2.0)
|
|
249
|
+
);
|
|
233
250
|
} else {
|
|
234
|
-
this.planet.flyLonLat(
|
|
251
|
+
this.planet.flyLonLat(
|
|
252
|
+
new LonLat(g.lon, g.lat, this.renderer.activeCamera.eye.distance(p) * 0.57)
|
|
253
|
+
);
|
|
235
254
|
}
|
|
236
255
|
}
|
|
237
256
|
}
|
|
@@ -264,7 +283,6 @@ class MouseNavigation extends Control {
|
|
|
264
283
|
|
|
265
284
|
onMouseLeftButtonDown(e) {
|
|
266
285
|
if (this._active) {
|
|
267
|
-
|
|
268
286
|
if (!this.grabbedPoint) {
|
|
269
287
|
return;
|
|
270
288
|
}
|
|
@@ -272,14 +290,16 @@ class MouseNavigation extends Control {
|
|
|
272
290
|
this.planet.stopFlying();
|
|
273
291
|
|
|
274
292
|
if (this.renderer.events.mouseState.moving) {
|
|
275
|
-
|
|
276
293
|
var cam = this.renderer.activeCamera;
|
|
277
294
|
|
|
278
295
|
if (cam.slope > 0.2) {
|
|
279
296
|
var targetPoint = new Ray(cam.eye, e.direction).hitSphere(this.grabbedSpheroid);
|
|
280
297
|
if (targetPoint) {
|
|
281
298
|
this.scaleRot = 1.0;
|
|
282
|
-
this.qRot = Quat.getRotationBetweenVectors(
|
|
299
|
+
this.qRot = Quat.getRotationBetweenVectors(
|
|
300
|
+
targetPoint.normal(),
|
|
301
|
+
this.grabbedPoint.normal()
|
|
302
|
+
);
|
|
283
303
|
var rot = this.qRot;
|
|
284
304
|
cam.eye = rot.mulVec3(cam.eye);
|
|
285
305
|
cam._v = rot.mulVec3(cam._v);
|
|
@@ -291,7 +311,6 @@ class MouseNavigation extends Control {
|
|
|
291
311
|
cam.update();
|
|
292
312
|
}
|
|
293
313
|
} else {
|
|
294
|
-
|
|
295
314
|
var p0 = this.grabbedPoint,
|
|
296
315
|
p1 = Vec3.add(p0, cam._u),
|
|
297
316
|
p2 = Vec3.add(p0, p0.normal());
|
|
@@ -312,23 +331,28 @@ class MouseNavigation extends Control {
|
|
|
312
331
|
onMouseRightButtonClick(e) {
|
|
313
332
|
this.stopRotation();
|
|
314
333
|
this.planet.stopFlying();
|
|
315
|
-
this.pointOnEarth = this.planet.getCartesianFromPixelTerrain(
|
|
334
|
+
this.pointOnEarth = this.planet.getCartesianFromPixelTerrain(
|
|
335
|
+
{
|
|
336
|
+
x: e.x,
|
|
337
|
+
y: e.y
|
|
338
|
+
},
|
|
339
|
+
true
|
|
340
|
+
);
|
|
316
341
|
if (this.pointOnEarth) {
|
|
317
342
|
this.earthUp = this.pointOnEarth.normal();
|
|
318
343
|
}
|
|
319
|
-
}
|
|
344
|
+
}
|
|
320
345
|
|
|
321
346
|
onMouseRightButtonDown(e) {
|
|
322
347
|
var cam = this.renderer.activeCamera;
|
|
323
348
|
|
|
324
349
|
if (this.pointOnEarth && this.renderer.events.mouseState.moving) {
|
|
325
|
-
|
|
326
350
|
this.renderer.controlsBag.scaleRot = 1.0;
|
|
327
|
-
var l = 0.5 / cam.eye.distance(this.pointOnEarth) * cam._lonLat.height * math.RADIANS;
|
|
351
|
+
var l = (0.5 / cam.eye.distance(this.pointOnEarth)) * cam._lonLat.height * math.RADIANS;
|
|
328
352
|
if (l > 0.007) l = 0.007;
|
|
329
353
|
cam.rotateHorizontal(l * (e.x - e.prev_x), false, this.pointOnEarth, this.earthUp);
|
|
330
354
|
|
|
331
|
-
cam.rotateVertical(l * (e.y - e.prev_y), this.pointOnEarth,
|
|
355
|
+
cam.rotateVertical(l * (e.y - e.prev_y), this.pointOnEarth, this.minSlope);
|
|
332
356
|
|
|
333
357
|
cam.checkTerrainCollision();
|
|
334
358
|
|
|
@@ -341,9 +365,7 @@ class MouseNavigation extends Control {
|
|
|
341
365
|
}
|
|
342
366
|
|
|
343
367
|
onMouseMove(e) {
|
|
344
|
-
|
|
345
368
|
if (this._active && this.renderer.events.isKeyPressed(input.KEY_ALT)) {
|
|
346
|
-
|
|
347
369
|
if (!this._shiftBusy) {
|
|
348
370
|
this._shiftBusy = true;
|
|
349
371
|
this.onMouseRightButtonClick(e);
|
|
@@ -354,9 +376,7 @@ class MouseNavigation extends Control {
|
|
|
354
376
|
}
|
|
355
377
|
|
|
356
378
|
onDraw(e) {
|
|
357
|
-
|
|
358
379
|
if (this._active) {
|
|
359
|
-
|
|
360
380
|
var r = this.renderer;
|
|
361
381
|
var cam = r.activeCamera;
|
|
362
382
|
var prevEye = cam.eye.clone();
|
|
@@ -364,6 +384,13 @@ class MouseNavigation extends Control {
|
|
|
364
384
|
if (this.stepIndex) {
|
|
365
385
|
r.controlsBag.scaleRot = 1.0;
|
|
366
386
|
var sf = this.stepsForward[this.stepsCount - this.stepIndex--];
|
|
387
|
+
|
|
388
|
+
let maxAlt = cam.maxAltitude + this.planet.ellipsoid._a;
|
|
389
|
+
|
|
390
|
+
if (sf.eye.length() > maxAlt) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
367
394
|
cam.eye = sf.eye;
|
|
368
395
|
cam._v = sf.v;
|
|
369
396
|
cam._u = sf.u;
|
|
@@ -390,9 +417,10 @@ class MouseNavigation extends Control {
|
|
|
390
417
|
if (this.scaleRot <= 0.0) {
|
|
391
418
|
this.scaleRot = 0.0;
|
|
392
419
|
} else {
|
|
393
|
-
|
|
394
420
|
r.controlsBag.scaleRot = this.scaleRot;
|
|
395
|
-
var rot = this.qRot
|
|
421
|
+
var rot = this.qRot
|
|
422
|
+
.slerp(Quat.IDENTITY, 1.0 - this.scaleRot * this.scaleRot * this.scaleRot)
|
|
423
|
+
.normalize();
|
|
396
424
|
if (!(rot.x || rot.y || rot.z)) {
|
|
397
425
|
this.scaleRot = 0.0;
|
|
398
426
|
}
|
|
@@ -417,6 +445,6 @@ class MouseNavigation extends Control {
|
|
|
417
445
|
}
|
|
418
446
|
}
|
|
419
447
|
}
|
|
420
|
-
}
|
|
448
|
+
}
|
|
421
449
|
|
|
422
|
-
export { MouseNavigation };
|
|
450
|
+
export { MouseNavigation };
|
|
@@ -21,7 +21,7 @@ import { ShapeHandler } from './ShapeHandler.js';
|
|
|
21
21
|
* @param {Object} [options] - Entity options:
|
|
22
22
|
* @param {Array.<og.Entity>} [options.entities] - Entities array.
|
|
23
23
|
* @param {boolean} [options.visibility=true] - Entity visibility.
|
|
24
|
-
* @param {Array.<number
|
|
24
|
+
* @param {Array.<number>} [options.scaleByDistance] - Entity scale by distance parameters. (exactly 3 entries)
|
|
25
25
|
* First index - near distance to the entity, after entity becomes full scale.
|
|
26
26
|
* Second index - far distance to the entity, when entity becomes zero scale.
|
|
27
27
|
* Third index - far distance to the entity, when entity becomes invisible.
|