diff options
| author | Julie Lala <jules@okfoc.us> | 2014-04-22 00:32:10 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-04-22 00:32:10 -0400 |
| commit | c618f157845c6baa492c935dc84012d392993f8f (patch) | |
| tree | 3e01acf1f541ea0bd8f9306eea4c4170d53a1756 | |
| parent | 5ac8395a55e8c05e6a73ae26fb7f4d2a4608558d (diff) | |
| parent | 5e795dbab647d9d8c4285233e1efc6262d49f720 (diff) | |
Merge branch 'master' of github.com:okfocus/vvalls
| -rw-r--r-- | assets/javascripts/rectangles/_env.js | 6 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/map/_map.js | 6 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/map/draw.js | 38 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/map/ui.js | 8 |
4 files changed, 46 insertions, 12 deletions
diff --git a/assets/javascripts/rectangles/_env.js b/assets/javascripts/rectangles/_env.js index f0f84e4..4023cdc 100644 --- a/assets/javascripts/rectangles/_env.js +++ b/assets/javascripts/rectangles/_env.js @@ -9,8 +9,10 @@ environment.init = function(){ "rotationY": PI }) - map.center.a = scene.camera.x - map.center.b = scene.camera.z +// map.center.a = scene.camera.x +// map.center.b = scene.camera.z + map.center.a = 0 + map.center.b = 0 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 bd8995c..b7e9536 100644 --- a/assets/javascripts/rectangles/map/_map.js +++ b/assets/javascripts/rectangles/map/_map.js @@ -7,6 +7,12 @@ var map = new function(){ var base = this base.bounds = new vec2(500,500) base.center = new vec2(0,0) + + base.sides = function(){ + var sides = base.bounds.clone().div(2).div(base.zoom) + return new rect( base.center.a - sides.a, base.center.b - sides.b, + base.center.a + sides.a, base.center.b + sides.b ) + } base.zoom = 1/4 diff --git a/assets/javascripts/rectangles/map/draw.js b/assets/javascripts/rectangles/map/draw.js index e15b083..518c160 100644 --- a/assets/javascripts/rectangles/map/draw.js +++ b/assets/javascripts/rectangles/map/draw.js @@ -8,23 +8,20 @@ map.draw = new function(){ map.draw.clear_canvas() map.draw.ruler() -// ctx.scale( map.zoom, map.zoom ) -// ctx.translate( map.center.a + map.bounds.a/2, map.center.b + map.bounds.b/2 ) -// ctx.scale( -1, 1 ) - - ctx.translate( map.center.a, map.center.b ) - ctx.translate( +map.bounds.a/2, +map.bounds.b/2 ) + ctx.translate( map.bounds.a * 1/2, map.bounds.b * 1/2) ctx.scale( map.zoom, map.zoom ) + ctx.translate( map.center.a, map.center.b) ctx.scale( -1, 1 ) map.draw.regions(clipper.regions) map.draw.mouse(map.ui.mouse.cursor) + map.draw.coords() scene && map.draw.camera(scene.camera) ctx.restore() } - base.clear_canvas = function (){ + base.clear_canvas = function(){ ctx.fillStyle = "rgba(255,255,255,0.99)" ctx.clearRect(0,0,w,h) ctx.fillRect(0,0,w,h) @@ -91,6 +88,20 @@ map.draw = new function(){ ctx.restore() } + base.coords = function(){ + ctx.fillStyle = "#888"; + dot_at(0,0) + ctx.fillStyle = "#bbb"; + dot_at(100,0) + dot_at(0,100) + ctx.fillStyle = "#ddd"; + dot_at(200,0) + dot_at(0,200) + ctx.fillStyle = "#eee"; + dot_at(300,0) + dot_at(0,300) + } + // function line (x,y,a,b,translation){ @@ -123,4 +134,17 @@ map.draw = new function(){ function stroke_rect (r){ line(r.x.a, r.y.a, r.x.b, r.y.b, r.translation) } + + function dot_at (x,z){ + ctx.save() + ctx.translate(x,z) + + var radius = 3 / map.zoom + + ctx.beginPath(); + ctx.arc(0, 0, radius, 0, 2*Math.PI, false); + ctx.fill(); + + ctx.restore() + } }
\ No newline at end of file diff --git a/assets/javascripts/rectangles/map/ui.js b/assets/javascripts/rectangles/map/ui.js index f08cae0..f4fc0ef 100644 --- a/assets/javascripts/rectangles/map/ui.js +++ b/assets/javascripts/rectangles/map/ui.js @@ -25,7 +25,7 @@ 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 ) -console.log(cursor+"") + 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 @@ -55,8 +55,10 @@ console.log(cursor+"") } function move (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).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 ) } function drag (e, cursor) { |
