diff options
| -rw-r--r-- | assets/javascripts/rectangles/_env.js | 4 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/map/_map.js | 3 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/map/ui.js | 22 |
3 files changed, 14 insertions, 15 deletions
diff --git a/assets/javascripts/rectangles/_env.js b/assets/javascripts/rectangles/_env.js index 4023cdc..1063d80 100644 --- a/assets/javascripts/rectangles/_env.js +++ b/assets/javascripts/rectangles/_env.js @@ -11,8 +11,8 @@ environment.init = function(){ // map.center.a = scene.camera.x // map.center.b = scene.camera.z - map.center.a = 0 - map.center.b = 0 + map.center.a = 100 + map.center.b = 100 clipper.rooms.push( new room ({ rect: new rect(-100,-100, 100,100), diff --git a/assets/javascripts/rectangles/map/_map.js b/assets/javascripts/rectangles/map/_map.js index b7e9536..20db8fc 100644 --- a/assets/javascripts/rectangles/map/_map.js +++ b/assets/javascripts/rectangles/map/_map.js @@ -5,6 +5,7 @@ window.ctx = window.w = window.h = null; var map = new function(){ var base = this + base.dimensions = new vec2(500,500) base.bounds = new vec2(500,500) base.center = new vec2(0,0) @@ -14,7 +15,7 @@ var map = new function(){ base.center.a + sides.a, base.center.b + sides.b ) } - base.zoom = 1/4 + base.zoom = 1/8 var canvas = document.createElement("canvas") var ctx = window.ctx = canvas.getContext("2d") diff --git a/assets/javascripts/rectangles/map/ui.js b/assets/javascripts/rectangles/map/ui.js index f4fc0ef..129ec90 100644 --- a/assets/javascripts/rectangles/map/ui.js +++ b/assets/javascripts/rectangles/map/ui.js @@ -23,12 +23,12 @@ map.ui = new function(){ // function down (e, cursor){ - cursor.x.div(map.zoom).add( map.center.a + map.bounds.a/2 ) - cursor.y.div(map.zoom).add( -map.center.b - map.bounds.b/2 ) + cursor.x.div(w).add(0.5).mul(map.bounds.a / map.zoom).add(map.center.a) + cursor.y.div(h).sub(0.5).mul(map.bounds.b / map.zoom).sub(map.center.b) if (e.ctrlKey || e.which === 3) { - map.center.a = cursor.x.a + map.bounds.a * map.zoom - map.center.b = -cursor.y.a + map.bounds.b * map.zoom + map.center.a = cursor.x.a + map.center.b = -cursor.y.a console.log(map.center+"") cursor.x.b = cursor.x.a cursor.y.b = cursor.y.a @@ -55,15 +55,13 @@ map.ui = new function(){ } function move (e, cursor) { - cursor.x.div(w).sub(0.5) - cursor.y.div(h).sub(0.5) -// cursor.x.div(map.zoom).add( map.center.a + map.bounds.a/2 ) -// cursor.y.div(map.zoom).add( -map.center.b - map.bounds.b/2 ) + cursor.x.div(w).add(0.5).mul(map.bounds.a / map.zoom).add(map.center.a) + cursor.y.div(h).sub(0.5).mul(map.bounds.b / map.zoom).sub(map.center.b) } function drag (e, cursor) { - cursor.x.b = (cursor.x.b / map.zoom) + map.center.a + map.bounds.a/2 - cursor.y.b = (cursor.y.b / map.zoom) - map.center.b - map.bounds.b/2 + cursor.x.b = ((cursor.x.b/w)+0.5) * map.bounds.a / map.zoom + map.center.a + cursor.y.b = ((cursor.y.b/h)-0.5) * map.bounds.b / map.zoom - map.center.b if (base.dragging) { base.dragging.rect.translation.a = cursor.x.magnitude() @@ -73,8 +71,8 @@ map.ui = new function(){ function up (e, cursor, new_cursor) { - new_cursor.x.div(map.zoom).add( map.center.a + map.bounds.a/2 ) - new_cursor.y.div(map.zoom).add( -map.center.b - map.bounds.b/2 ) + new_cursor.x.div(w).add(0.5).mul(map.bounds.a / map.zoom).add(map.center.a) + new_cursor.y.div(h).sub(0.5).mul(map.bounds.b / map.zoom).sub(map.center.b) if (base.creating) { if (cursor.height() != 0 && cursor.width() != 0) { |
