Skip to content

Commit

Permalink
Fix Tilt gesture issue represented in commit (c406f69)
Browse files Browse the repository at this point in the history
  • Loading branch information
ComBatVision committed Sep 15, 2022
1 parent c47deb1 commit 88f80fe
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
78 changes: 43 additions & 35 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.cameraFromLookAt(lookAt);
this.wwd.redraw();
this.applyChanges();
} else if (state === WorldWind.ENDED || state === WorldWind.CANCELLED) {
this.gestureDidEnd();
}
};

Expand Down Expand Up @@ -313,9 +315,9 @@ define([
lookAt.heading = params.heading;
lookAt.tilt = params.tilt;
lookAt.roll = params.roll;
this.applyLookAtLimits(lookAt);
this.wwd.cameraFromLookAt(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.cameraFromLookAt(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.cameraFromLookAt(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.cameraFromLookAt(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.cameraFromLookAt(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.cameraAsLookAt(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,15 @@ define([

// Apply the scale to this view's properties.
lookAt.range *= scale;
this.applyLookAtLimits(lookAt);
this.wwd.cameraFromLookAt(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 () {
// 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 +468,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.cameraAsLookAt(this.lookAt);
this.applyLookAtLimits(lookAt);
// Update camera view.
this.wwd.cameraFromLookAt(lookAt);
this.wwd.redraw();
};

/**
Expand All @@ -481,8 +480,17 @@ define([
* @ignore
*/
BasicWorldWindowController.prototype.gestureDidBegin = function () {
this.wwd.cameraAsLookAt(this.beginLookAt);
this.lookAt.copy(this.beginLookAt);
if (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 (activeGestures > 0) {
activeGestures--;
}
};

return BasicWorldWindowController;
Expand Down
8 changes: 0 additions & 8 deletions src/WorldWindowController.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,6 @@ define([
}
};

/**
* Called by WorldWindow to allow the controller to enforce navigation limits. Implementation is not required by
* sub-classes.
*/
WorldWindowController.prototype.applyLimits = function () {

};

return WorldWindowController;
}
);

0 comments on commit 88f80fe

Please sign in to comment.