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