Skip to content

Commit 2ea276a

Browse files
committed
Remove WorldWindow dependency from Camera. Move transformations between Camera and LookAt to WorldWindow.
1 parent 834910e commit 2ea276a

23 files changed

+276
-329
lines changed

apps/Explorer/Explorer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ define(['../../src/WorldWind',
6767
var lookAt = new WorldWind.LookAt();
6868
lookAt.position.latitude = 30;
6969
lookAt.position.longitude = -(180 / 12) * ((new Date()).getTimezoneOffset() / 60);
70-
this.wwd.camera.setFromLookAt(lookAt);
70+
this.wwd.cameraFromLookAt(lookAt);
7171

7272
this.goToBox = new GoToBox(this.wwd);
7373
this.layersPanel = new LayersPanel(this.wwd);

apps/NEO/NEO.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ define(['../../src/WorldWind',
6464
var lookAt = new WorldWind.LookAt();
6565
lookAt.position.latitude = 30;
6666
lookAt.position.longitude = -(180 / 12) * ((new Date()).getTimezoneOffset() / 60);
67-
this.wwd.camera.setFromLookAt(lookAt);
67+
this.wwd.cameraFromLookAt(lookAt);
6868

6969
this.timeSeriesPlayer = new TimeSeriesPlayer(this.wwd);
7070
this.projectionMenu = new ProjectionMenu(this.wwd);

apps/SentinelWMTS/SentinelWMTS.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ define(['../../src/WorldWind',
8484
lookAt.position.latitude = 48.86;
8585
lookAt.position.longitude = 2.37;
8686
lookAt.range = 5e4;
87-
this.wwd.camera.setFromLookAt(lookAt);
87+
this.wwd.cameraFromLookAt(lookAt);
8888

8989
// Create controllers for the user interface elements.
9090
new GoToBox(wwd);

apps/SubSurface/SubSurface.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ define(['../../src/WorldWind',
6767
var lookAt = new WorldWind.LookAt();
6868
lookAt.position.latitude = 30;
6969
lookAt.position.longitude = -(180 / 12) * ((new Date()).getTimezoneOffset() / 60);
70-
this.wwd.camera.setFromLookAt(lookAt);
70+
this.wwd.cameraFromLookAt(lookAt);
7171

7272
this.goToBox = new GoToBox(this.wwd);
7373
this.layersPanel = new LayersPanel(this.wwd);

apps/USGSSlabs/USGSSlabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ define(['../../src/WorldWind',
7878
var lookAt = new WorldWind.LookAt();
7979
lookAt.position.latitude = 30;
8080
lookAt.position.longitude = -(180 / 12) * ((new Date()).getTimezoneOffset() / 60);
81-
this.wwd.camera.setFromLookAt(lookAt);
81+
this.wwd.cameraFromLookAt(lookAt);
8282

8383
// Establish the shapes and the controllers to handle picking.
8484
this.setupPicking();

apps/USGSWells/USGSWells.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ define(['../../src/WorldWind',
9191
lookAt.range = 1400;
9292
lookAt.heading = 90;
9393
lookAt.tilt = 60;
94-
this.wwd.camera.setFromLookAt(lookAt);
94+
this.wwd.cameraFromLookAt(lookAt);
9595

9696
// Establish the shapes and the controllers to handle picking.
9797
this.setupPicking();

examples/Canyon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ requirejs(['./WorldWindShim'],
2222
var wwd = new WorldWind.WorldWindow("canvasOne");
2323
var camera = wwd.camera;
2424
var lookAt = new WorldWind.LookAt();
25-
camera.getAsLookAt(lookAt);
25+
wwd.cameraAsLookAt(lookAt);
2626
var layers = [
2727
{layer: new WorldWind.BMNGLayer(), enabled: true},
2828
{layer: new WorldWind.BingAerialWithLabelsLayer(null), enabled: true},

examples/Views.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ requirejs(['./WorldWindShim',
2424
var wwd = new WorldWind.WorldWindow("canvasOne");
2525
var camera = wwd.camera;
2626
var lookAt = new WorldWind.LookAt();
27-
camera.getAsLookAt(lookAt);
27+
wwd.cameraAsLookAt(lookAt);
2828
var layers = [
2929
{layer: new WorldWind.BMNGLayer(), enabled: true},
3030
{layer: new WorldWind.BingAerialWithLabelsLayer(null), enabled: true},
@@ -127,7 +127,7 @@ requirejs(['./WorldWindShim',
127127
rangeSlider.slider("disable");
128128
altitudeSlider.slider("enable");
129129
} else {
130-
camera.getAsLookAt(lookAt);
130+
wwd.cameraAsLookAt(lookAt);
131131
pos = lookAt.position;
132132
view = lookAt;
133133
rangeSlider.slider("enable");
@@ -138,7 +138,7 @@ requirejs(['./WorldWindShim',
138138
pos = camera.position;
139139
view = camera;
140140
} else {
141-
camera.getAsLookAt(lookAt);
141+
wwd.cameraAsLookAt(lookAt);
142142
pos = lookAt.position;
143143
view = lookAt;
144144
}
@@ -150,7 +150,7 @@ requirejs(['./WorldWindShim',
150150
view.roll = rollSlider.slider("value");
151151
if (selectedViewType === "LookAt") {
152152
lookAt.range = rangeSlider.slider("value");
153-
camera.setFromLookAt(lookAt);
153+
wwd.cameraFromLookAt(lookAt);
154154
}
155155
}
156156
updateControls(pos, view);
@@ -159,7 +159,7 @@ requirejs(['./WorldWindShim',
159159

160160
window.setInterval(function () {
161161
var pos, view;
162-
camera.getAsLookAt(lookAt);
162+
wwd.cameraAsLookAt(lookAt);
163163
if (currentViewType === "Camera") {
164164
pos = camera.position;
165165
view = camera;

performance/DeepPickingPerformance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ requirejs(['../src/WorldWind',
6969
var lookAt = new WorldWind.LookAt();
7070
lookAt.position = new WorldWind.Position(44.2, -94.12, 0);
7171
lookAt.range = 625000;
72-
wwd.camera.setFromLookAt(lookAt);
72+
wwd.cameraFromLookAt(lookAt);
7373

7474
// Satellite image footprints
7575
var footprints = [];

src/BasicWorldWindowController.js

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ define([
131131
this.beginPoint = new Vec2(0, 0);
132132
this.lastPoint = new Vec2(0, 0);
133133
this.lastRotation = 0;
134+
this.lastWheelEvent = 0;
135+
this.activeGestures = 0;
134136

135137
/**
136138
* Internal use only.
@@ -251,9 +253,9 @@ define([
251253
lookAt.position.latitude += forwardDegrees * cosHeading - sideDegrees * sinHeading;
252254
lookAt.position.longitude += forwardDegrees * sinHeading + sideDegrees * cosHeading;
253255
this.lastPoint.set(tx, ty);
254-
this.applyLookAtLimits(lookAt);
255-
this.wwd.camera.setFromLookAt(lookAt);
256-
this.wwd.redraw();
256+
this.applyChanges();
257+
} else if (state === WorldWind.ENDED || state === WorldWind.CANCELLED) {
258+
this.gestureDidEnd();
257259
}
258260
};
259261

@@ -295,7 +297,7 @@ define([
295297

296298
// Transform the original view's modelview matrix to account for the gesture's change.
297299
var modelview = Matrix.fromIdentity();
298-
lookAt.computeViewingTransform(globe, modelview);
300+
this.wwd.lookAtToViewingTransform(lookAt, modelview);
299301
modelview.multiplyByTranslation(point2[0] - point1[0], point2[1] - point1[1], point2[2] - point1[2]);
300302

301303
// Compute the globe point at the screen center from the perspective of the transformed view.
@@ -313,9 +315,9 @@ define([
313315
lookAt.heading = params.heading;
314316
lookAt.tilt = params.tilt;
315317
lookAt.roll = params.roll;
316-
this.applyLookAtLimits(lookAt);
317-
this.wwd.camera.setFromLookAt(lookAt);
318-
this.wwd.redraw();
318+
this.applyChanges();
319+
} else if (state === WorldWind.ENDED || state === WorldWind.CANCELLED) {
320+
this.gestureDidEnd();
319321
}
320322
};
321323

@@ -337,9 +339,9 @@ define([
337339
// Apply the change in heading and tilt to this view's corresponding properties.
338340
lookAt.heading = this.beginLookAt.heading + headingDegrees;
339341
lookAt.tilt = this.beginLookAt.tilt + tiltDegrees;
340-
this.applyLookAtLimits(lookAt);
341-
this.wwd.camera.setFromLookAt(lookAt);
342-
this.wwd.redraw();
342+
this.applyChanges();
343+
} else if (state === WorldWind.ENDED || state === WorldWind.CANCELLED) {
344+
this.gestureDidEnd();
343345
}
344346
};
345347

@@ -356,10 +358,10 @@ define([
356358
// began.
357359
var lookAt = this.lookAt;
358360
lookAt.range = this.beginLookAt.range / scale;
359-
this.applyLookAtLimits(lookAt);
360-
this.wwd.camera.setFromLookAt(lookAt);
361-
this.wwd.redraw();
361+
this.applyChanges();
362362
}
363+
} else if (state === WorldWind.ENDED || state === WorldWind.CANCELLED) {
364+
this.gestureDidEnd();
363365
}
364366
};
365367

@@ -378,9 +380,9 @@ define([
378380
var lookAt = this.lookAt;
379381
lookAt.heading -= rotation - this.lastRotation;
380382
this.lastRotation = rotation;
381-
this.applyLookAtLimits(lookAt);
382-
this.wwd.camera.setFromLookAt(lookAt);
383-
this.wwd.redraw();
383+
this.applyChanges();
384+
} else if (state === WorldWind.ENDED || state === WorldWind.CANCELLED) {
385+
this.gestureDidEnd();
384386
}
385387
};
386388

@@ -397,16 +399,21 @@ define([
397399
var tiltDegrees = -90 * ty / this.wwd.canvas.clientHeight;
398400
// Apply the change in heading and tilt to this view's corresponding properties.
399401
var lookAt = this.lookAt;
400-
lookAt.tilt = this.beginTilt + tiltDegrees;
401-
this.applyLookAtLimits(lookAt);
402-
this.wwd.camera.setFromLookAt(lookAt);
403-
this.wwd.redraw();
402+
lookAt.tilt = this.beginLookAt.tilt + tiltDegrees;
403+
this.applyChanges();
404+
} else if (state === WorldWind.ENDED || state === WorldWind.CANCELLED) {
405+
this.gestureDidEnd();
404406
}
405407
};
406408

407409
// Intentionally not documented.
408410
BasicWorldWindowController.prototype.handleWheelEvent = function (event) {
409-
var lookAt = this.wwd.camera.getAsLookAt(this.lookAt);
411+
var lookAt = this.lookAt;
412+
var timeStamp = event.timeStamp;
413+
if (timeStamp - this.lastWheelEvent > 500) {
414+
this.wwd.cameraAsLookAt(lookAt);
415+
this.lastWheelEvent = timeStamp;
416+
}
410417
// Normalize the wheel delta based on the wheel delta mode. This produces a roughly consistent delta across
411418
// browsers and input devices.
412419
var normalizedDelta;
@@ -425,17 +432,17 @@ define([
425432

426433
// Apply the scale to this view's properties.
427434
lookAt.range *= scale;
428-
this.applyLookAtLimits(lookAt);
429-
this.wwd.camera.setFromLookAt(lookAt);
430-
this.wwd.redraw();
435+
this.applyChanges();
431436
};
432437

433438
/**
434439
* Internal use only.
435-
* Limits the properties of a look at view to prevent unwanted navigation behaviour.
440+
* Limits the properties of a look at view to prevent unwanted navigation behaviour and update camera view.
436441
* @ignore
437442
*/
438-
BasicWorldWindowController.prototype.applyLookAtLimits = function (lookAt) {
443+
BasicWorldWindowController.prototype.applyChanges = function () {
444+
var lookAt = this.lookAt;
445+
439446
// Clamp latitude to between -90 and +90, and normalize longitude to between -180 and +180.
440447
lookAt.position.latitude = WWMath.clamp(lookAt.position.latitude, -90, 90);
441448
lookAt.position.longitude = Angle.normalizedDegreesLongitude(lookAt.position.longitude);
@@ -463,16 +470,10 @@ define([
463470
// Force tilt to 0 when in 2D mode to keep the viewer looking straight down.
464471
lookAt.tilt = 0;
465472
}
466-
};
467473

468-
/**
469-
* Documented in super-class.
470-
* @ignore
471-
*/
472-
BasicWorldWindowController.prototype.applyLimits = function () {
473-
var lookAt = this.wwd.camera.getAsLookAt(this.lookAt);
474-
this.applyLookAtLimits(lookAt);
475-
this.wwd.camera.setFromLookAt(lookAt);
474+
// Update camera view.
475+
this.wwd.cameraFromLookAt(lookAt);
476+
this.wwd.redraw();
476477
};
477478

478479
/**
@@ -481,8 +482,17 @@ define([
481482
* @ignore
482483
*/
483484
BasicWorldWindowController.prototype.gestureDidBegin = function () {
484-
this.wwd.camera.getAsLookAt(this.beginLookAt);
485-
this.lookAt.copy(this.beginLookAt);
485+
if (this.activeGestures++ === 0) {
486+
this.wwd.cameraAsLookAt(this.beginLookAt);
487+
this.lookAt.copy(this.beginLookAt);
488+
}
489+
};
490+
491+
BasicWorldWindowController.prototype.gestureDidEnd = function () {
492+
// this should always be the case, but we check anyway
493+
if (this.activeGestures > 0) {
494+
this.activeGestures--;
495+
}
486496
};
487497

488498
return BasicWorldWindowController;

0 commit comments

Comments
 (0)