Skip to content

Commit

Permalink
Remove WorldWindow dependency from Camera. Move transformations betwe…
Browse files Browse the repository at this point in the history
…en Camera and LookAt to WorldWindow.
  • Loading branch information
ComBatVision committed Sep 19, 2022
1 parent 834910e commit cda680d
Show file tree
Hide file tree
Showing 23 changed files with 276 additions and 329 deletions.
2 changes: 1 addition & 1 deletion apps/Explorer/Explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ define(['../../src/WorldWind',
var lookAt = new WorldWind.LookAt();
lookAt.position.latitude = 30;
lookAt.position.longitude = -(180 / 12) * ((new Date()).getTimezoneOffset() / 60);
this.wwd.camera.setFromLookAt(lookAt);
this.wwd.cameraFromLookAt(lookAt);

this.goToBox = new GoToBox(this.wwd);
this.layersPanel = new LayersPanel(this.wwd);
Expand Down
2 changes: 1 addition & 1 deletion apps/NEO/NEO.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ define(['../../src/WorldWind',
var lookAt = new WorldWind.LookAt();
lookAt.position.latitude = 30;
lookAt.position.longitude = -(180 / 12) * ((new Date()).getTimezoneOffset() / 60);
this.wwd.camera.setFromLookAt(lookAt);
this.wwd.cameraFromLookAt(lookAt);

this.timeSeriesPlayer = new TimeSeriesPlayer(this.wwd);
this.projectionMenu = new ProjectionMenu(this.wwd);
Expand Down
2 changes: 1 addition & 1 deletion apps/SentinelWMTS/SentinelWMTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ define(['../../src/WorldWind',
lookAt.position.latitude = 48.86;
lookAt.position.longitude = 2.37;
lookAt.range = 5e4;
this.wwd.camera.setFromLookAt(lookAt);
this.wwd.cameraFromLookAt(lookAt);

// Create controllers for the user interface elements.
new GoToBox(wwd);
Expand Down
2 changes: 1 addition & 1 deletion apps/SubSurface/SubSurface.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ define(['../../src/WorldWind',
var lookAt = new WorldWind.LookAt();
lookAt.position.latitude = 30;
lookAt.position.longitude = -(180 / 12) * ((new Date()).getTimezoneOffset() / 60);
this.wwd.camera.setFromLookAt(lookAt);
this.wwd.cameraFromLookAt(lookAt);

this.goToBox = new GoToBox(this.wwd);
this.layersPanel = new LayersPanel(this.wwd);
Expand Down
2 changes: 1 addition & 1 deletion apps/USGSSlabs/USGSSlabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ define(['../../src/WorldWind',
var lookAt = new WorldWind.LookAt();
lookAt.position.latitude = 30;
lookAt.position.longitude = -(180 / 12) * ((new Date()).getTimezoneOffset() / 60);
this.wwd.camera.setFromLookAt(lookAt);
this.wwd.cameraFromLookAt(lookAt);

// Establish the shapes and the controllers to handle picking.
this.setupPicking();
Expand Down
2 changes: 1 addition & 1 deletion apps/USGSWells/USGSWells.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ define(['../../src/WorldWind',
lookAt.range = 1400;
lookAt.heading = 90;
lookAt.tilt = 60;
this.wwd.camera.setFromLookAt(lookAt);
this.wwd.cameraFromLookAt(lookAt);

// Establish the shapes and the controllers to handle picking.
this.setupPicking();
Expand Down
2 changes: 1 addition & 1 deletion examples/Canyon.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ requirejs(['./WorldWindShim'],
var wwd = new WorldWind.WorldWindow("canvasOne");
var camera = wwd.camera;
var lookAt = new WorldWind.LookAt();
camera.getAsLookAt(lookAt);
wwd.cameraAsLookAt(lookAt);
var layers = [
{layer: new WorldWind.BMNGLayer(), enabled: true},
{layer: new WorldWind.BingAerialWithLabelsLayer(null), enabled: true},
Expand Down
10 changes: 5 additions & 5 deletions examples/Views.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ requirejs(['./WorldWindShim',
var wwd = new WorldWind.WorldWindow("canvasOne");
var camera = wwd.camera;
var lookAt = new WorldWind.LookAt();
camera.getAsLookAt(lookAt);
wwd.cameraAsLookAt(lookAt);
var layers = [
{layer: new WorldWind.BMNGLayer(), enabled: true},
{layer: new WorldWind.BingAerialWithLabelsLayer(null), enabled: true},
Expand Down Expand Up @@ -127,7 +127,7 @@ requirejs(['./WorldWindShim',
rangeSlider.slider("disable");
altitudeSlider.slider("enable");
} else {
camera.getAsLookAt(lookAt);
wwd.cameraAsLookAt(lookAt);
pos = lookAt.position;
view = lookAt;
rangeSlider.slider("enable");
Expand All @@ -138,7 +138,7 @@ requirejs(['./WorldWindShim',
pos = camera.position;
view = camera;
} else {
camera.getAsLookAt(lookAt);
wwd.cameraAsLookAt(lookAt);
pos = lookAt.position;
view = lookAt;
}
Expand All @@ -150,7 +150,7 @@ requirejs(['./WorldWindShim',
view.roll = rollSlider.slider("value");
if (selectedViewType === "LookAt") {
lookAt.range = rangeSlider.slider("value");
camera.setFromLookAt(lookAt);
wwd.cameraFromLookAt(lookAt);
}
}
updateControls(pos, view);
Expand All @@ -159,7 +159,7 @@ requirejs(['./WorldWindShim',

window.setInterval(function () {
var pos, view;
camera.getAsLookAt(lookAt);
wwd.cameraAsLookAt(lookAt);
if (currentViewType === "Camera") {
pos = camera.position;
view = camera;
Expand Down
2 changes: 1 addition & 1 deletion performance/DeepPickingPerformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ requirejs(['../src/WorldWind',
var lookAt = new WorldWind.LookAt();
lookAt.position = new WorldWind.Position(44.2, -94.12, 0);
lookAt.range = 625000;
wwd.camera.setFromLookAt(lookAt);
wwd.cameraFromLookAt(lookAt);

// Satellite image footprints
var footprints = [];
Expand Down
84 changes: 47 additions & 37 deletions src/BasicWorldWindowController.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ define([
this.beginPoint = new Vec2(0, 0);
this.lastPoint = new Vec2(0, 0);
this.lastRotation = 0;
this.lastWheelEvent = 0;
this.activeGestures = 0;

/**
* Internal use only.
Expand Down Expand Up @@ -251,9 +253,9 @@ define([
lookAt.position.latitude += forwardDegrees * cosHeading - sideDegrees * sinHeading;
lookAt.position.longitude += forwardDegrees * sinHeading + sideDegrees * cosHeading;
this.lastPoint.set(tx, ty);
this.applyLookAtLimits(lookAt);
this.wwd.camera.setFromLookAt(lookAt);
this.wwd.redraw();
this.applyChanges();
} else if (state === WorldWind.ENDED || state === WorldWind.CANCELLED) {
this.gestureDidEnd();
}
};

Expand Down Expand Up @@ -295,7 +297,7 @@ define([

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

// Compute the globe point at the screen center from the perspective of the transformed view.
Expand All @@ -313,9 +315,9 @@ define([
lookAt.heading = params.heading;
lookAt.tilt = params.tilt;
lookAt.roll = params.roll;
this.applyLookAtLimits(lookAt);
this.wwd.camera.setFromLookAt(lookAt);
this.wwd.redraw();
this.applyChanges();
} else if (state === WorldWind.ENDED || state === WorldWind.CANCELLED) {
this.gestureDidEnd();
}
};

Expand All @@ -337,9 +339,9 @@ define([
// Apply the change in heading and tilt to this view's corresponding properties.
lookAt.heading = this.beginLookAt.heading + headingDegrees;
lookAt.tilt = this.beginLookAt.tilt + tiltDegrees;
this.applyLookAtLimits(lookAt);
this.wwd.camera.setFromLookAt(lookAt);
this.wwd.redraw();
this.applyChanges();
} else if (state === WorldWind.ENDED || state === WorldWind.CANCELLED) {
this.gestureDidEnd();
}
};

Expand All @@ -356,10 +358,10 @@ define([
// began.
var lookAt = this.lookAt;
lookAt.range = this.beginLookAt.range / scale;
this.applyLookAtLimits(lookAt);
this.wwd.camera.setFromLookAt(lookAt);
this.wwd.redraw();
this.applyChanges();
}
} else if (state === WorldWind.ENDED || state === WorldWind.CANCELLED) {
this.gestureDidEnd();
}
};

Expand All @@ -378,9 +380,9 @@ define([
var lookAt = this.lookAt;
lookAt.heading -= rotation - this.lastRotation;
this.lastRotation = rotation;
this.applyLookAtLimits(lookAt);
this.wwd.camera.setFromLookAt(lookAt);
this.wwd.redraw();
this.applyChanges();
} else if (state === WorldWind.ENDED || state === WorldWind.CANCELLED) {
this.gestureDidEnd();
}
};

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

// Intentionally not documented.
BasicWorldWindowController.prototype.handleWheelEvent = function (event) {
var lookAt = this.wwd.camera.getAsLookAt(this.lookAt);
var lookAt = this.lookAt;
var timeStamp = event.timeStamp;
if (timeStamp - this.lastWheelEvent > 500) {
this.wwd.cameraAsLookAt(lookAt);
this.lastWheelEvent = timeStamp;
}
// Normalize the wheel delta based on the wheel delta mode. This produces a roughly consistent delta across
// browsers and input devices.
var normalizedDelta;
Expand All @@ -425,17 +432,17 @@ define([

// Apply the scale to this view's properties.
lookAt.range *= scale;
this.applyLookAtLimits(lookAt);
this.wwd.camera.setFromLookAt(lookAt);
this.wwd.redraw();
this.applyChanges();
};

/**
* Internal use only.
* Limits the properties of a look at view to prevent unwanted navigation behaviour.
* Limits the properties of a look at view to prevent unwanted navigation behaviour and update camera view.
* @ignore
*/
BasicWorldWindowController.prototype.applyLookAtLimits = function (lookAt) {
BasicWorldWindowController.prototype.applyChanges = function () {
var lookAt = this.lookAt;

// Clamp latitude to between -90 and +90, and normalize longitude to between -180 and +180.
lookAt.position.latitude = WWMath.clamp(lookAt.position.latitude, -90, 90);
lookAt.position.longitude = Angle.normalizedDegreesLongitude(lookAt.position.longitude);
Expand Down Expand Up @@ -463,16 +470,10 @@ define([
// Force tilt to 0 when in 2D mode to keep the viewer looking straight down.
lookAt.tilt = 0;
}
};

/**
* Documented in super-class.
* @ignore
*/
BasicWorldWindowController.prototype.applyLimits = function () {
var lookAt = this.wwd.camera.getAsLookAt(this.lookAt);
this.applyLookAtLimits(lookAt);
this.wwd.camera.setFromLookAt(lookAt);
// Update camera view.
this.wwd.cameraFromLookAt(lookAt);
this.wwd.redraw();
};

/**
Expand All @@ -481,8 +482,17 @@ define([
* @ignore
*/
BasicWorldWindowController.prototype.gestureDidBegin = function () {
this.wwd.camera.getAsLookAt(this.beginLookAt);
this.lookAt.copy(this.beginLookAt);
if (this.activeGestures++ === 0) {
this.wwd.cameraAsLookAt(this.beginLookAt);
this.lookAt.copy(this.beginLookAt);
}
};

BasicWorldWindowController.prototype.gestureDidEnd = function () {
// this should always be the case, but we check anyway
if (this.activeGestures > 0) {
this.activeGestures--;
}
};

return BasicWorldWindowController;
Expand Down
Loading

0 comments on commit cda680d

Please sign in to comment.