summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/map
diff options
context:
space:
mode:
Diffstat (limited to 'assets/javascripts/rectangles/map')
-rw-r--r--assets/javascripts/rectangles/map/_map.js3
-rw-r--r--assets/javascripts/rectangles/map/ui.js22
2 files changed, 12 insertions, 13 deletions
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) {