Skip to content
Browse files

Use the picked hit point as a frame of reference when dragging object…

…s to move them.

By using this point, we actually track the exact point under the
mouse, which is nicer, and also fix the problem that for large
objects, the object center could be in an odd location, far from the
click point, resulting in very unintuitive movement. Fixes #249.
  • Loading branch information...
1 parent 39d729b commit 2fed65d6237bdb19f5dc3ff20b09a23b1208349f @ewencp ewencp committed May 31, 2011
View
2 liboh/plugins/js/scripts/std/graphics/default.em
@@ -260,7 +260,7 @@ function() {
if (this._selected)
this._dragger = dragger;
if (this._dragger)
- this._dragger.selected(this._selected, evt);
+ this._dragger.selected(this._selected, this._simulator.pickedPosition(), evt);
};
/** @function */
View
2 liboh/plugins/js/scripts/std/graphics/drag/handler.em
@@ -47,7 +47,7 @@ std.graphics.DragHandler = system.Class.extend(
},
/** @memberOf std.graphics.DragHandler */
- selected: function(obj) {
+ selected: function(obj, hitpoint, evt) {
},
/** @memberOf std.graphics.DragHandler */
View
17 liboh/plugins/js/scripts/std/graphics/drag/move.em
@@ -33,7 +33,7 @@
system.require('std/movement/movableremote.em');
system.require('std/graphics/drag/handler.em');
-/** @namespace
+/** @namespace
MoveDragHandler responds to drag events by moving a selected object.
*/
std.graphics.MoveDragHandler = std.graphics.DragHandler.extend(
@@ -44,9 +44,15 @@ std.graphics.MoveDragHandler = std.graphics.DragHandler.extend(
},
/** @memberOf std.graphics.MoveDragHandler */
- selected: function(obj) {
- this._dragging = obj ?
- new std.movement.MovableRemote(obj) : null;
+ selected: function(obj, hitpoint, evt) {
+ if (obj) {
+ this._dragging = new std.movement.MovableRemote(obj);
+ this._dragPoint = hitpoint;
+ }
+ else {
+ this._dragging = null;
+ this._dragPoint = null;
+ }
},
/** @memberOf std.graphics.MoveDragHandler */
@@ -64,12 +70,13 @@ std.graphics.MoveDragHandler = std.graphics.DragHandler.extend(
if (!lastClickAxis) return;
- var moveVector = this._dragging.getPosition().sub( this._graphics.presence.getPosition() );
+ var moveVector = this._dragPoint.sub( this._graphics.presence.getPosition() );
var moveDistance = moveVector.dot(centerAxis);
var start = lastClickAxis.scale(moveDistance);
var end = clickAxis.scale(moveDistance);
var toMove = end.sub(start);
this._dragging.dragPosition = this._dragging.dragPosition.add(toMove);
+ this._dragPoint = this._dragPoint.add(toMove);
this._dragging.setPosition(this._dragging.dragPosition);
},
View
2 liboh/plugins/js/scripts/std/graphics/drag/rotate.em
@@ -82,7 +82,7 @@ std.graphics.RotateDragHandler = std.graphics.DragHandler.extend(
},
/** @memberOf std.graphics.RotateDragHandler */
- selected: function(obj, evt) {
+ selected: function(obj, hitpoint, evt) {
this._dragging = obj ?
new std.movement.MovableRemote(obj) : null;
this._startingDir = this._spherePos(evt);

0 comments on commit 2fed65d

Please sign in to comment.
Something went wrong with that request. Please try again.