summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/engine
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles/engine')
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/_scenery.js2
-rw-r--r--public/assets/javascripts/rectangles/engine/scenery/move.js1
-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
6 files changed, 53 insertions, 21 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 981eb68..7d148cf 100644
--- a/public/assets/javascripts/rectangles/engine/scenery/move.js
+++ b/public/assets/javascripts/rectangles/engine/scenery/move.js
@@ -88,7 +88,6 @@ Scenery.move = function(base){
}
function up (e, cursor){
- console.log(dragging, oldState)
if (! dragging || ! oldState) return
dragging = false
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)
+ }
}
},