Skip to content

Commit

Permalink
Merge pull request #92 from AnalyticalGraphicsInc/viewer-mouse
Browse files Browse the repository at this point in the history
New Mouse Handling
  • Loading branch information
pjcozzi committed Jul 5, 2012
2 parents 33b2e51 + 36ded68 commit e501d15
Show file tree
Hide file tree
Showing 23 changed files with 654 additions and 476 deletions.
14 changes: 12 additions & 2 deletions Apps/CesiumViewer/CesiumViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define([
'Core/FullScreen',
'Core/Ellipsoid',
'Core/Transforms',
'Core/Cartesian3',
'Core/requestAnimationFrame',
'Scene/SceneTransitioner',
'Scene/BingMapsStyle',
Expand All @@ -42,6 +43,7 @@ define([
FullScreen,
Ellipsoid,
Transforms,
Cartesian3,
requestAnimationFrame,
SceneTransitioner,
BingMapsStyle,
Expand All @@ -59,6 +61,7 @@ define([
multiplier : 1
});
var animationController = new AnimationController(clock);
var spindleController;
var timeline;
var transitioner;
var dynamicObjectCollection = new DynamicObjectCollection();
Expand Down Expand Up @@ -159,10 +162,17 @@ define([
lastCameraCenteredObjectID = cameraCenteredObjectID;
var camera = widget.scene.getCamera();
camera.position = camera.position.normalize().multiplyWithScalar(5000.0);

var controllers = camera.getControllers();
controllers.removeAll();
spindleController = controllers.addSpindle();
spindleController.constrainedAxis = Cartesian3.UNIT_Z;
}

var transform = Transforms.eastNorthUpToFixedFrame(cameraCenteredObjectIDPosition, widget.ellipsoid);
widget.spindleCameraController.setReferenceFrame(transform, Ellipsoid.UNIT_SPHERE);
if (typeof spindleController !== 'undefined' && !spindleController.isDestroyed()) {
var transform = Transforms.eastNorthUpToFixedFrame(cameraCenteredObjectIDPosition, widget.ellipsoid);
spindleController.setReferenceFrame(transform, Ellipsoid.UNIT_SPHERE);
}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ Beta Releases
var position = scene.pickEllipsoid(windowPosition, ellipsoid);

* `Camera.getPickRay` now returns the new `Ray` type instead of an object with position and direction properties.
* `CameraSpindleController.mouseConstrainedZAxis` has been removed. Instead, use `CameraSpindleController.constrainedAxis`. Code that previously looked like:

spindleController.mouseConstrainedZAxis = true;

should now look like:

spindleController.constrainedAxis = Cartesian3.UNIT_Z;

* The free look feature has been removed from `CameraColumbusViewController` in favor of rotating about the point clicked on the map with the middle mouse button.
* The `Camera2DController` constructor and `CameraControllerCollection.add2D` now require a projection instead of an ellipsoid.

* Added `addImage` to `TextureAtlas` so images can be added to a texture atlas after it is constructed.
* Added `Scene.pickEllipsoid`, which picks either the ellipsoid or the map depending on the current `SceneMode`.
Expand All @@ -39,6 +49,10 @@ Beta Releases
* Added a new Timeline control to the widgets directory.
* Added a new DojoWidgets directory, to contain dojo-specific widgets.
* Added new Timeline and Cesium dojo widgets.
* Added `CameraCentralBodyController` as the new default controller to handle mouse input.
* The left mouse button rotates around the central body.
* The right mouse button and mouse wheel zoom in and out.
* The middle mouse button rotates around the point clicked on the central body.

### b6a - 06/20/2012

Expand Down
3 changes: 1 addition & 2 deletions Examples/Sandbox/CodeSnippets/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
var transform = Cesium.Transforms.eastNorthUpToFixedFrame(center);

var spindle = scene.getCamera().getControllers().get(0);
spindle.mouseConstrainedZAxis = true;
spindle.constrainedAxis = Cesium.Cartesian3.UNIT_Z;
spindle.setReferenceFrame(transform, Cesium.Ellipsoid.UNIT_SPHERE);

// draw x axis in red
Expand Down Expand Up @@ -75,7 +75,6 @@
this.clear = function() {
var spindle = scene.getCamera().getControllers().get(0);
spindle.setReferenceFrame(Cesium.Matrix4.IDENTITY);
spindle.mouseConstrainedZAxis = false;
};
};

Expand Down
2 changes: 1 addition & 1 deletion Examples/Sandbox/Sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var Sandbox = Sandbox || {};
primitives.setCentralBody(cb);

scene.getCamera().getControllers().addSpindle();
scene.getCamera().getControllers().get(0).mouseConstrainedZAxis = true;
scene.getCamera().getControllers().get(0).constrainedAxis = Cesium.Cartesian3.UNIT_Z;

scene.getCamera().getControllers().addFreeLook();

Expand Down
4 changes: 1 addition & 3 deletions Examples/Skeleton/Skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ require({
primitives.setCentralBody(cb);

scene.getCamera().frustum.near = 1.0;

scene.getCamera().getControllers().addSpindle();
scene.getCamera().getControllers().addFreeLook();
scene.getCamera().getControllers().addCentralBody();

var transitioner = new Cesium.SceneTransitioner(scene, ellipsoid);

Expand Down
150 changes: 2 additions & 148 deletions Source/Core/EventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,8 @@ define([
}

this._leftMouseButtonDown = false;
this._leftPressTime = undefined;
this._leftReleaseTime = undefined;
this._middleMouseButtonDown = false;
this._middlePressTime = undefined;
this._middleReleaseTime = undefined;
this._rightMouseButtonDown = false;
this._rightPressTime = undefined;
this._rightReleaseTime = undefined;
this._seenAnyTouchEvents = false;
this._lastMouseX = 0;
this._lastMouseY = 0;
Expand Down Expand Up @@ -82,138 +76,6 @@ define([
};
};

/**
* Returns <code>true</code> if the left mouse button is pressed and <code>false</code> otherwise.
*
* @memberof EventHandler
*
* @return {Boolean} <code>true</code> if the left mouse button is pressed and <code>false</code> otherwise.
*
* @see EventHandler#isMiddleMouseButtonDown
* @see EventHandler#isRightMouseButtonDown
*/
EventHandler.prototype.isLeftMouseButtonDown = function() {
return this._leftMouseButtonDown;
};

/**
* Returns the last time that the left mouse button was pressed.
*
* @memberof EventHandler
*
* @return {JulianDate} The time the left mouse button was pressed.
*
* @see EventHandler#getLeftReleaseTime
* @see EventHandler#getRightPressTime
* @see EventHandler#getMiddlePressTime
*/
EventHandler.prototype.getLeftPressTime = function() {
return this._leftPressTime;
};

/**
* Returns the last time that the left mouse button was released.
*
* @memberof EventHandler
*
* @return {JulianDate} The time the left mouse button was released.
*
* @see EventHandler#getLeftPressTime
* @see EventHandler#getRightReleaseTime
* @see EventHandler#getMiddleReleaseTime
*/
EventHandler.prototype.getLeftReleaseTime = function() {
return this._leftReleaseTime;
};

/**
* Returns <code>true</code> if the middle mouse button is pressed and <code>false</code> otherwise.
*
* @memberof EventHandler
*
* @return {Boolean} <code>true</code> if the middle mouse button is pressed and <code>false</code> otherwise.
*
* @see EventHandler#isMiddleMouseButtonDown
* @see EventHandler#isLeftMouseButtonDown
*/
EventHandler.prototype.isMiddleMouseButtonDown = function() {
return this._middleMouseButtonDown;
};

/**
* Returns the last time that the middle mouse button was pressed.
*
* @memberof EventHandler
*
* @return {JulianDate} The time the middle mouse button was pressed.
*
* @see EventHandler#getMiddleReleaseTime
* @see EventHandler#getRightPressTime
* @see EventHandler#getLeftPressTime
*/
EventHandler.prototype.getMiddlePressTime = function() {
return this._middlePressTime;
};

/**
* Returns the last time that the middle mouse button was released.
*
* @memberof EventHandler
*
* @return {JulianDate} The time the middle mouse button was released.
*
* @see EventHandler#getMiddlePressTime
* @see EventHandler#getRightReleaseTime
* @see EventHandler#getLeftReleaseTime
*/
EventHandler.prototype.getMiddleReleaseTime = function() {
return this._middleReleaseTime;
};

/**
* Returns <code>true</code> if the right mouse button is pressed and <code>false</code> otherwise.
*
* @memberof EventHandler
*
* @return {Boolean} <code>true</code> if the right mouse button is pressed and <code>false</code> otherwise.
*
* @see EventHandler#isMiddleMouseButtonDown
* @see EventHandler#isLeftMouseButtonDown
*/
EventHandler.prototype.isRightMouseButtonDown = function() {
return this._rightMouseButtonDown;
};

/**
* Returns the last time that the right mouse button was pressed.
*
* @memberof EventHandler
*
* @return {JulianDate} The time the right mouse button was pressed.
*
* @see EventHandler#getRightReleaseTime
* @see EventHandler#getLeftPressTime
* @see EventHandler#getMiddlePressTime
*/
EventHandler.prototype.getRightPressTime = function() {
return this._rightPressTime;
};

/**
* Returns the last time that the right mouse button was released.
*
* @memberof EventHandler
*
* @return {JulianDate} The time the right mouse button was released.
*
* @see EventHandler#getRightPressTime
* @see EventHandler#getLeftReleaseTime
* @see EventHandler#getMiddleReleaseTime
*/
EventHandler.prototype.getRightReleaseTime = function() {
return this._rightReleaseTime;
};

/**
* Set a function to be executed on a mouse event.
*
Expand Down Expand Up @@ -281,7 +143,7 @@ define([
return mouseEvents[type.name];
}

return null;
return undefined;
};

/**
Expand Down Expand Up @@ -324,7 +186,7 @@ define([
return EventModifier.ALT;
}

return null;
return undefined;
};

EventHandler.prototype._handleMouseDown = function(event) {
Expand All @@ -345,15 +207,12 @@ define([
// constants somewhere?
if (event.button === 0) {
this._leftMouseButtonDown = true;
this._leftPressTime = new JulianDate();
action = this.getMouseAction(MouseEventType.LEFT_DOWN, modifier);
} else if (event.button === 1) {
this._middleMouseButtonDown = true;
this._middlePressTime = new JulianDate();
action = this.getMouseAction(MouseEventType.MIDDLE_DOWN, modifier);
} else if (event.button === 2) {
this._rightMouseButtonDown = true;
this._rightPressTime = new JulianDate();
action = this.getMouseAction(MouseEventType.RIGHT_DOWN, modifier);
}

Expand All @@ -378,17 +237,14 @@ define([
// constants somewhere?
if (event.button === 0) {
this._leftMouseButtonDown = false;
this._leftReleaseTime = new JulianDate();
action = this.getMouseAction(MouseEventType.LEFT_UP, modifier);
clickAction = this.getMouseAction(MouseEventType.LEFT_CLICK, modifier);
} else if (event.button === 1) {
this._middleMouseButtonDown = false;
this._middleReleaseTime = new JulianDate();
action = this.getMouseAction(MouseEventType.MIDDLE_UP, modifier);
clickAction = this.getMouseAction(MouseEventType.MIDDLE_CLICK, modifier);
} else if (event.button === 2) {
this._rightMouseButtonDown = false;
this._rightReleaseTime = new JulianDate();
action = this.getMouseAction(MouseEventType.RIGHT_UP, modifier);
clickAction = this.getMouseAction(MouseEventType.RIGHT_CLICK, modifier);
}
Expand Down Expand Up @@ -456,7 +312,6 @@ define([
var action;

this._leftMouseButtonDown = true;
this._leftPressTime = new JulianDate();
action = this.getMouseAction(MouseEventType.LEFT_DOWN, modifier);

if (action) {
Expand All @@ -478,7 +333,6 @@ define([

if (this._leftMouseButtonDown) {
this._leftMouseButtonDown = false;
this._leftReleaseTime = new JulianDate();
action = this.getMouseAction(MouseEventType.LEFT_UP, modifier);
clickAction = this.getMouseAction(MouseEventType.LEFT_CLICK, modifier);
}
Expand Down
8 changes: 2 additions & 6 deletions Source/DojoWidgets/CesiumWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ define([
camera.frustum.near = 0.0002 * maxRadii;
camera.frustum.far = 50.0 * maxRadii;

this.spindleCameraController = camera.getControllers().addSpindle(ellipsoid);
this.spindleCameraController.mouseConstrainedZAxis = true;
this.freelookCameraController = camera.getControllers().addFreeLook(ellipsoid);
this.centralBodyCameraController = camera.getControllers().addCentralBody();

var handler = new EventHandler(canvas);
handler.setMouseAction(lang.hitch(this, '_handleLeftClick'), MouseEventType.LEFT_CLICK);
Expand Down Expand Up @@ -247,9 +245,7 @@ define([

var controllers = camera.getControllers();
controllers.removeAll();
this.spindleCameraController = controllers.addSpindle(this.ellipsoid);
this.spindleCameraController.constrainedZAxis = true;
this.freelookCameraController = controllers.addFreeLook(this.ellipsoid);
this.centralBodyCameraController = controllers.addCentralBody();
},

areCloudsAvailable : function() {
Expand Down
13 changes: 12 additions & 1 deletion Source/Scene/AnimationCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ define([
* @memberof AnimationCollection
*/
AnimationCollection.prototype.remove = function(animation) {
if (animation) {
if (typeof animation !== 'undefined') {
var count = Tween.getAll().length;
Tween.remove(animation._tween);

Expand All @@ -216,6 +216,17 @@ define([
Tween.removeAll();
};

/**
* DOC_TBA
* @memberof Animationcollection
*/
AnimationCollection.prototype.contains = function(animation) {
if (typeof animation !== 'undefined') {
return Tween.getAll().indexOf(animation) !== -1;
}
return false;
};

/**
* DOC_TBA
* @memberof AnimationCollection
Expand Down
Loading

0 comments on commit e501d15

Please sign in to comment.