summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles')
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/_scenery.js2
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/move.js2
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/resize.js27
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/types/_object.js26
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/types/image.js9
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/types/video.js9
-rw-r--r--public/assets/javascripts/rectangles/models/vec2.js17
-rw-r--r--public/assets/javascripts/rectangles/models/wall.js38
-rw-r--r--public/assets/javascripts/rectangles/util/coords.js33
-rw-r--r--public/assets/javascripts/rectangles/util/minotaur.js2
10 files changed, 140 insertions, 25 deletions
diff --git a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
index d34e299..69e9ba7 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/_scenery.js
@@ -48,7 +48,7 @@ var Scenery = new function(){
base.find = function(id){
return base.list[id] || null
}
-
+
base.remove = function(id){
var scene_media = base.list[id]
delete base.list[id]
diff --git a/public/assets/javascripts/rectangles/engine/scenery/move.js b/public/assets/javascripts/rectangles/engine/scenery/move.js
index 55d6ef1..7d148cf 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/move.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/move.js
@@ -101,7 +101,7 @@ Scenery.move = function(base){
// TODO: watch individual scenery object here
Minotaur.watch( app.router.editorView.settings )
-
+
oldState = null
}
diff --git a/public/assets/javascripts/rectangles/engine/scenery/resize.js b/public/assets/javascripts/rectangles/engine/scenery/resize.js
index 2ba84a1..893237c 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/resize.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/resize.js
@@ -57,35 +57,32 @@ Scenery.resize = new function(){
// move all the dots to the object's current position
base.move_dots = function(){
- x = obj.mx.x + sin(rotationY) * dot_distance_from_picture
- y = obj.mx.y
- z = obj.mx.z - cos(rotationY) * dot_distance_from_picture
+ var x = obj.mx.x + sin(rotationY) * dot_distance_from_picture
+ var y = obj.mx.y
+ var z = obj.mx.z - cos(rotationY) * dot_distance_from_picture
dots.forEach(function(dot){
- base.move_dot(dot)
+ base.move_dot(dot, { x: x, y: y, z: z })
})
}
// move a dot .. to the initial position of the image
- base.move_dot = function(dot){
- dot.x = x
- dot.y = y
- dot.z = z
-
+ base.move_dot = function(dot, pos){
if (dot.side & TOP) {
- dot.y += obj.mx.height * obj.mx.scale / 2
+ pos.y += obj.dimensions.b / 2
}
if (dot.side & BOTTOM) {
- dot.y -= obj.mx.height * obj.mx.scale / 2
+ pos.y -= obj.dimensions.b / 2
}
if (dot.side & LEFT) {
- dot.x -= cos(rotationY) * (obj.mx.width * obj.mx.scale) / 2
- dot.z -= sin(rotationY) * (obj.mx.width * obj.mx.scale) / 2
+ pos.x -= cos(rotationY) * (obj.dimensions.a) / 2
+ pos.z -= sin(rotationY) * (obj.dimensions.a) / 2
}
if (dot.side & RIGHT) {
- dot.x += cos(rotationY) * (obj.mx.width * obj.mx.scale) / 2
- dot.z += sin(rotationY) * (obj.mx.width * obj.mx.scale) / 2
+ pos.x += cos(rotationY) * (obj.dimensions.a) / 2
+ pos.z += sin(rotationY) * (obj.dimensions.a) / 2
}
+ dot.move(pos)
}
// pick a new object to focus on and show the dots
diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js
index 5eed53e..4e5e2c5 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js
@@ -33,11 +33,33 @@ Scenery.types.base = Fiber.extend(function(base){
var center = this.bounds.center()
center.a -= this.dimensions.a / 2
center.b -= this.dimensions.b / 2
- var mx_position = this.wall.positionToMx( center, this.dimensions )
- this.mx.move(mx_position)
this.position.assign(center)
},
+ translateTo: function (position){
+ var flipX = this.wall.side & (FRONT | RIGHT)
+ var delta = position.clone().subVec(this.position)
+ delta.a -= this.dimensions.a/2
+ delta.b -= this.dimensions.b/2
+
+ if (flipX) { delta.a *= -1 }
+
+ var new_bounds = this.wall.surface.translate( this.bounds, this.dimensions, this.position, delta )
+
+ this.position.b += delta.b
+
+ switch (this.wall.side) {
+ case FRONT:
+ case BACK:
+ this.position.a += delta.a * cos(wall_rotation[this.wall.side])
+ break
+ case LEFT:
+ case RIGHT:
+ this.position.a += delta.a * sin(wall_rotation[this.wall.side])
+ break
+ }
+ },
+
bind: function(){
this.move.bind()
$(this.mx.el).bind({
diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/image.js b/public/assets/javascripts/rectangles/engine/scenery/types/image.js
index d2fa3ab..aa43341 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/types/image.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/types/image.js
@@ -22,7 +22,14 @@ Scenery.types.image = Scenery.types.base.extend(function(base){
}
else {
this.set_wall(opt)
- this.bounds && this.recenter()
+ if (this.bounds) {
+ this.recenter()
+ if (opt.position) {
+ this.translateTo(opt.position)
+ }
+ var mx_position = this.wall.positionToMx( this.position, this.dimensions )
+ this.mx.move(mx_position)
+ }
}
},
diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/video.js b/public/assets/javascripts/rectangles/engine/scenery/types/video.js
index 76f32ac..2ef6ec3 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/types/video.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/types/video.js
@@ -21,7 +21,14 @@ Scenery.types.video = Scenery.types.base.extend(function(base){
}
else {
this.set_wall(opt)
- this.bounds && this.recenter()
+ if (this.bounds) {
+ this.recenter()
+ if (opt.position) {
+ this.translateTo(opt.position)
+ }
+ var mx_position = this.wall.positionToMx( this.position, this.dimensions )
+ this.mx.move(mx_position)
+ }
}
},
diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js
index 0040435..49613c3 100644
--- a/public/assets/javascripts/rectangles/models/vec2.js
+++ b/public/assets/javascripts/rectangles/models/vec2.js
@@ -37,6 +37,9 @@
vec2.prototype.midpoint = function(){
return lerp(0.5, this.a, this.b)
}
+ vec2.prototype.lerp = function(n){
+ return lerp(n, this.a, this.b)
+ }
vec2.prototype.eq = function(v){
return this.a == v.a && this.b == v.b
}
@@ -60,9 +63,23 @@
this.b /= n
return this
}
+ vec2.prototype.addVec = function(v){
+ this.a += v.a
+ this.b += v.b
+ return this
+ }
+ vec2.prototype.subVec = function(v){
+ this.a -= v.a
+ this.b -= v.b
+ return this
+ }
vec2.prototype.zero = function(){
this.a = this.b = 0
}
+ vec2.prototype.round = function(){
+ this.a = Math.round(this.a)
+ this.b = Math.round(this.b)
+ }
vec2.prototype.setPosition = function(n){
var len = this.length()
this.a = n
diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js
index 1b37aa0..fdc8d8c 100644
--- a/public/assets/javascripts/rectangles/models/wall.js
+++ b/public/assets/javascripts/rectangles/models/wall.js
@@ -50,13 +50,36 @@
index: index,
})
},
+/*
mousemove: function(e){
+ var offset = offsetFromPoint(e, mx.el)
+ if (offset) {
+ var pos = base.mxOffsetToPosition( offset, index )
+
+ var mx_pos = base.positionToMx(pos, new vec2(5,5))
+ var mx_dot = new MX.Object3D
+ mx_dot.move(mx_pos)
+ mx_dot.width = 5
+ mx_dot.height = 5
+ mx_dot.rotationY = wall_rotation[base.side]
+ mx_dot.el.style.backgroundColor = "red"
+ scene.add(mx_dot)
+ }
},
+*/
mousedown: function(e){
- if (Scenery.nextMedia) {
+ if (Scenery.nextText) {
+ }
+ else if (Scenery.nextMedia) {
+ var offset = offsetFromPoint(e, mx.el)
+ if (! offset) { return }
+
+ var pos = base.mxOffsetToPosition( offset, index )
+
var scenery = Scenery.addNextToWall({
wall: base,
- index: index
+ index: index,
+ position: pos,
})
// scenery was not placed
@@ -176,7 +199,16 @@
}
return position
}
-
+ Wall.prototype.mxOffsetToPosition = function( offset, index ) {
+ var face = this.surface.faces[index]
+ var shouldFlip = this.side & (RIGHT | FRONT)
+ var position = new vec2(0,0)
+ position.a = face.x.lerp(shouldFlip ? 1-offset.left : offset.left)
+ position.b = face.y.lerp(1-offset.top)
+ position.round()
+ return position
+ }
+
Wall.prototype.color = function(color){
this.$walls.css("background-color", color)
}
diff --git a/public/assets/javascripts/rectangles/util/coords.js b/public/assets/javascripts/rectangles/util/coords.js
new file mode 100644
index 0000000..74b7fda
--- /dev/null
+++ b/public/assets/javascripts/rectangles/util/coords.js
@@ -0,0 +1,33 @@
+function offsetFromPoint(event, element) {
+ function a(width) {
+ var l = 0, r = 200;
+ while (r - l > 0.0001) {
+ var mid = (r + l) / 2;
+ var a = document.createElement('div');
+ a.style.cssText = 'position: absolute;left:0;top:0;background: red;z-index: 1000;';
+ a.style[width ? 'width' : 'height'] = mid.toFixed(3) + '%';
+ a.style[width ? 'height' : 'width'] = '100%';
+ element.appendChild(a);
+ var x = document.elementFromPoint(event.clientX, event.clientY);
+ element.removeChild(a);
+ if (x === a) {
+ r = mid;
+ } else {
+ if (r === 200) {
+ return null;
+ }
+ l = mid;
+ }
+ }
+ return mid;
+ }
+ var l = a(1),
+ t = a(0);
+ return l && t ? {
+ left: l / 100,
+ top: t / 100,
+ toString: function () {
+ return 'left: ' + l + '%, top: ' + t + '%';
+ }
+ } : null;
+}
diff --git a/public/assets/javascripts/rectangles/util/minotaur.js b/public/assets/javascripts/rectangles/util/minotaur.js
index 4d9a795..d165ccc 100644
--- a/public/assets/javascripts/rectangles/util/minotaur.js
+++ b/public/assets/javascripts/rectangles/util/minotaur.js
@@ -4,7 +4,7 @@
var base = this
base.$el = $("#minotaur")
base.timeout = null
- base.delay = 5000
+ base.delay = 2500
base.objects = {}
base.init = function () {