diff options
| author | Julie Lala <jules@okfoc.us> | 2014-08-22 13:27:06 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-08-22 13:27:06 -0400 |
| commit | 41349226e763751311d3b0135086505a77f5472a (patch) | |
| tree | edec2928b8a7140a8fa9b1a33bb81f839bd3aafb | |
| parent | 4ec4b0e42c06b63962658ae8b886ee9466d09a21 (diff) | |
drag and clamp
5 files changed, 33 insertions, 11 deletions
diff --git a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js index 119391d..1e2e83a 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js +++ b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js @@ -54,6 +54,12 @@ var Scenery = new function(){ delete base.list[id] scene_media && scene_media.destroy() } + + base.removeAll = function(){ + base.forEach(function(scene_media){ + base.remove(scene_media.id) + }) + } base.uid = new UidGenerator(base.list) diff --git a/public/assets/javascripts/rectangles/engine/scenery/move.js b/public/assets/javascripts/rectangles/engine/scenery/move.js index 47e155b..991d1d4 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/move.js +++ b/public/assets/javascripts/rectangles/engine/scenery/move.js @@ -1,7 +1,7 @@ Scenery.move = function(base){ - var x, y, z, bounds + var x, y, z, position, dimension, bounds var dragging = false var oldState @@ -48,7 +48,11 @@ Scenery.move = function(base){ x = base.mx.x y = base.mx.y z = base.mx.z + bounds = base.bounds + dimension = base.dimensions + position = base.wall.mxToPosition( base.mx, dimension ) + oldState = base.serialize() document.body.classList.add("dragging") } @@ -56,18 +60,28 @@ Scenery.move = function(base){ function drag (e, cursor){ if (! dragging) return - base.mx.y = bounds.y.clamp( y - cursor.y.magnitude()*cursor_amp ) + var flipX = base.wall.side & (FRONT | RIGHT) + + var delta = cursor.delta() + delta.mul( cursor_amp ) // this should be proportional to your distance from the wall + if (flipX) { delta.a *= -1 } + delta.b *= -1 + + var new_bounds = base.wall.surface.translate( bounds, dimension, position, delta ) + if (new_bounds) bounds = new_bounds + if (flipX) { delta.a *= -1 } + + base.mx.y = position.b + delta.b + dimension.b / 2 switch (base.wall.side) { case FRONT: case BACK: - base.mx.x = bounds.x.clamp( x + cos(wall_rotation[base.wall.side]) * cursor.x.magnitude()*cursor_amp ) + base.mx.x = position.a + delta.a * cos(wall_rotation[base.wall.side]) + dimension.a / 2 break case LEFT: case RIGHT: - base.mx.z = bounds.x.clamp( z + sin(wall_rotation[base.wall.side]) * cursor.x.magnitude()*cursor_amp ) + base.mx.z = position.a + delta.a * sin(wall_rotation[base.wall.side]) + dimension.a / 2 break } - if (editor.permissions.resize) { Scenery.resize.move_dots() } diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/image.js b/public/assets/javascripts/rectangles/engine/scenery/types/image.js index 3bee827..cab6a94 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/image.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/image.js @@ -12,13 +12,13 @@ Scenery.types.image = Scenery.types.base.extend(function(base){ this.bind() if (opt.data) { - console.log(opt.wall) + // console.log(opt.wall) // console.log(opt.data.position) if (opt.wall) { var position = opt.wall.mxToPosition(opt.data.position) - console.log(position.a) + // console.log(position.a) opt.index = opt.wall.surface.index_for_x( position.a, 0 ) - console.log(opt.index) + // console.log(opt.index) } this.set_wall(opt) this.deserialize(opt.data) diff --git a/public/assets/javascripts/rectangles/models/surface.js b/public/assets/javascripts/rectangles/models/surface.js index 9c45eaf..5b411c0 100644 --- a/public/assets/javascripts/rectangles/models/surface.js +++ b/public/assets/javascripts/rectangles/models/surface.js @@ -97,8 +97,6 @@ } var top_edge = position.b + dimension.b + delta.b - bounds.y.b -// console.log(position.b, 0, delta.b, bounds.y.a, bottom_edge) -// console.log(position.b, dimension.b, delta.b, bounds.y.b, top_edge) if (top_edge > 0) { delta.b -= top_edge } diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js index f6742ad..8723c3c 100644 --- a/public/assets/javascripts/rectangles/models/wall.js +++ b/public/assets/javascripts/rectangles/models/wall.js @@ -122,7 +122,7 @@ rotationY: wall_rotation[ this.side ], } } - Wall.prototype.mxToPosition = function(mx) { + Wall.prototype.mxToPosition = function(mx, dimension) { var position = new vec2(0,0) switch (this.side) { case FRONT: @@ -136,6 +136,10 @@ position.b = mx.y break } + if (dimension) { + position.a -= dimension.a / 2 + position.b -= dimension.b / 2 + } // if (mx.width) { position.a -= mx.width / 2 } // if (mx.height) { position.b -= mx.height / 2 } return position |
