diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-04-17 12:27:51 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-04-17 12:27:51 -0400 |
| commit | f6424c4756de2045648de0980de14a32b0126df7 (patch) | |
| tree | 844b690dbe722dad6d8eb2869015abacb563a11b | |
| parent | 309574dec1852238ae899d719f5486f21949a064 (diff) | |
scale map
| -rw-r--r-- | assets/javascripts/rectangles/_env.js | 6 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/map/_map.js | 3 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/map/ui.js | 13 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/models/rect.js | 10 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/models/vec2.js | 5 |
5 files changed, 27 insertions, 10 deletions
diff --git a/assets/javascripts/rectangles/_env.js b/assets/javascripts/rectangles/_env.js index 9df73c2..4964bfa 100644 --- a/assets/javascripts/rectangles/_env.js +++ b/assets/javascripts/rectangles/_env.js @@ -2,9 +2,9 @@ var environment = new function(){} environment.init = function(){ window.scene && scene.camera.move({ - "x": 0, - "y": 1000, - "z": 0, + "x": 500, + "y": 1500, + "z": 200, "rotationX": PI/2, "rotationY": PI }) diff --git a/assets/javascripts/rectangles/map/_map.js b/assets/javascripts/rectangles/map/_map.js index 833df7a..b0d0b60 100644 --- a/assets/javascripts/rectangles/map/_map.js +++ b/assets/javascripts/rectangles/map/_map.js @@ -8,6 +8,8 @@ var map = new function(){ base.bounds = new vec2(500,500) base.center = new vec2(0,0) + base.zoom = 1/2 + var canvas = document.createElement("canvas") var ctx = window.ctx = canvas.getContext("2d") var w = window.w = canvas.width = 500 @@ -19,6 +21,7 @@ var map = new function(){ map.draw.clear_canvas() map.draw.ruler() + ctx.scale( base.zoom, base.zoom ) ctx.translate( map.center.a + map.bounds.a/2, map.center.b + map.bounds.b/2 ) ctx.scale( -1, 1 ) diff --git a/assets/javascripts/rectangles/map/ui.js b/assets/javascripts/rectangles/map/ui.js index cc9a560..9faebea 100644 --- a/assets/javascripts/rectangles/map/ui.js +++ b/assets/javascripts/rectangles/map/ui.js @@ -24,8 +24,8 @@ map.ui = new function(){ // function down (e, cursor){ - cursor.x.add( map.center.a + map.bounds.a/2 ) - cursor.y.add( -map.center.b - map.bounds.b/2 ) + 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 ) var intersects = clipper.rooms.filter(function(r){ return r.focused = r.rect.contains(cursor.x.a, cursor.y.a) @@ -44,14 +44,13 @@ map.ui = new function(){ } function move (e, cursor) { - cursor.x.add( map.center.a + map.bounds.a/2 ) - cursor.y.add( -map.center.b - map.bounds.b/2 ) - z=true + 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) { - cursor.x.b += map.center.a + map.bounds.a/2 - cursor.y.b += -map.center.b - map.bounds.b/2 + 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 if (base.dragging) { base.dragging.rect.translation.a = cursor.x.magnitude() diff --git a/assets/javascripts/rectangles/models/rect.js b/assets/javascripts/rectangles/models/rect.js index 548e16a..5623dc8 100644 --- a/assets/javascripts/rectangles/models/rect.js +++ b/assets/javascripts/rectangles/models/rect.js @@ -26,6 +26,16 @@ window.rect = (function(){ rect.prototype.area = function(){ return this.x.length() * this.y.length() } + + rect.prototype.mul = function(n){ + this.x.mul(n) + this.y.mul(n) + } + rect.prototype.div = function(n){ + this.x.div(n) + this.y.div(n) + } + rect.prototype.translate = function(translation){ var translation = translation || this.translation this.x.abs().add(translation.a) diff --git a/assets/javascripts/rectangles/models/vec2.js b/assets/javascripts/rectangles/models/vec2.js index 4e2ad36..3105fec 100644 --- a/assets/javascripts/rectangles/models/vec2.js +++ b/assets/javascripts/rectangles/models/vec2.js @@ -28,23 +28,28 @@ vec2.prototype.eq = function(v){ vec2.prototype.add = function(n){ this.a += n this.b += n + return this } vec2.prototype.sub = function(n){ this.a -= n this.b -= n + return this } vec2.prototype.mul = function(n){ this.a *= n this.b *= n + return this } vec2.prototype.div = function(n){ this.a /= n this.b /= n + return this } vec2.normalize = function(){ var dim = max(this.a, this.b) this.a = this.a/dim this.b = this.b/dim + return this } vec2.prototype.contains = function(n){ return this.a <= n && n <= this.b |
