summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles
diff options
context:
space:
mode:
Diffstat (limited to 'assets/javascripts/rectangles')
-rw-r--r--assets/javascripts/rectangles/engine/builder.js11
-rw-r--r--assets/javascripts/rectangles/models/rect.js2
-rw-r--r--assets/javascripts/rectangles/models/room.js25
-rw-r--r--assets/javascripts/rectangles/models/wall.js13
-rw-r--r--assets/javascripts/rectangles/util/sort.js19
5 files changed, 59 insertions, 11 deletions
diff --git a/assets/javascripts/rectangles/engine/builder.js b/assets/javascripts/rectangles/engine/builder.js
index 3452ecc..d5caeee 100644
--- a/assets/javascripts/rectangles/engine/builder.js
+++ b/assets/javascripts/rectangles/engine/builder.js
@@ -1,3 +1,4 @@
+
var builder = new function(){
var base = this
@@ -69,6 +70,7 @@ var builder = new function(){
el.x = region.x.a + width/2
el.y = height/2
el.z = region.y.a
+ el.side = FRONT
room.walls.push(el)
list.push(el)
}
@@ -80,6 +82,7 @@ var builder = new function(){
el.x = region.x.b - width/2
el.y = height/2
el.z = region.y.b
+ el.side = BACK
room.walls.push(el)
list.push(el)
}
@@ -91,6 +94,7 @@ var builder = new function(){
el.x = region.x.a
el.y = height/2
el.z = region.y.a + depth/2
+ el.side = LEFT
room.walls.push(el)
list.push(el)
}
@@ -102,6 +106,7 @@ var builder = new function(){
el.x = region.x.b
el.y = height/2
el.z = region.y.b - depth/2
+ el.side = RIGHT
room.walls.push(el)
list.push(el)
}
@@ -232,6 +237,7 @@ var builder = new function(){
el.y = 0
el.z = region.y.a + depth/2
el.rotationX = PI/2
+ el.side = FLOOR
return el
}
function make_ceiling(room, region){
@@ -246,15 +252,18 @@ var builder = new function(){
el.y = height
el.z = region.y.a + depth/2
el.rotationX = -PI/2
+ el.side = CEILING
return el
}
- function make_wall(klass){
+ function make_wall(room, klass){
var el = new MX.Object3D(".face" + (klass || ""))
el.width = el.height = el.scaleX = el.scaleY = el.scaleZ = 1
el.z = el.y = el.x = 0
+ el.side = 0
el.type = "Face"
el.el.style.opacity = 1.0
+ el.side = 0
return el
}
diff --git a/assets/javascripts/rectangles/models/rect.js b/assets/javascripts/rectangles/models/rect.js
index 2d48e13..a5ae9bf 100644
--- a/assets/javascripts/rectangles/models/rect.js
+++ b/assets/javascripts/rectangles/models/rect.js
@@ -1,5 +1,3 @@
-var FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8,
- FRONT_BACK = FRONT | BACK, LEFT_RIGHT = LEFT | RIGHT
function sidesToString(sides){
var s = ""
diff --git a/assets/javascripts/rectangles/models/room.js b/assets/javascripts/rectangles/models/room.js
index c26efa9..34eed6a 100644
--- a/assets/javascripts/rectangles/models/room.js
+++ b/assets/javascripts/rectangles/models/room.js
@@ -1,3 +1,6 @@
+var FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8, FLOOR = 0x10, CEILING = 0x20
+ FRONT_BACK = FRONT | BACK, LEFT_RIGHT = LEFT | RIGHT, FLOOR_CEILING = FLOOR | CEILING
+
window.Room = (function(){
var Room = function(opt){
@@ -48,9 +51,27 @@ window.Room = (function(){
})
}
- Room.prototype.add_wall = function(){
- }
+ Room.prototype.group_walls = function(){
+ var base = this
+ var array_groups = {}, rect_groups = []
+
+ sort_wall_els_by_x_then_z(base.walls)
+
+ base.walls.forEach(function(wall){
+ var w = array_groups[ wall.side ]
+ if (w) {
+ w.forEach(function(ww){
+
+ })
+ }
+ else {
+ array_groups[ wall.side ] = [[wall]]
+ }
+ })
+ return groups
+ }
+
Room.prototype.clipTo = function(r){
// for each of this rect's regions split the region if necessary
var regions = this.regions
diff --git a/assets/javascripts/rectangles/models/wall.js b/assets/javascripts/rectangles/models/wall.js
index e25d2dd..b9705a2 100644
--- a/assets/javascripts/rectangles/models/wall.js
+++ b/assets/javascripts/rectangles/models/wall.js
@@ -1,20 +1,21 @@
-window.wall = (function(){
+window.Wall = (function(){
- var wall = function(opt){
+ var Wall = function(opt){
this.id = opt.id
this.room = opt.room
this.rect = opt.rect
this.mx = []
+ this.els = []
}
- wall.prototype.toString = function(){
+ Wall.prototype.toString = function(){
return this.rect.toString()
}
- wall.prototype.reset = function(){
+ Wall.prototype.reset = function(){
}
- wall.prototype.bind = function(){
+ Wall.prototype.bind = function(){
this.$walls.bind({
mouseover: function(){
},
@@ -26,6 +27,6 @@ window.wall = (function(){
})
}
- return wall
+ return Wall
})()
diff --git a/assets/javascripts/rectangles/util/sort.js b/assets/javascripts/rectangles/util/sort.js
index e53a09c..008e20a 100644
--- a/assets/javascripts/rectangles/util/sort.js
+++ b/assets/javascripts/rectangles/util/sort.js
@@ -57,3 +57,22 @@ function sort_rects_by_area(list){
.sort(compare_rect_area)
.map(function(r){ return r[1] })
}
+
+
+function sort_wall_els_by_x_then_z(list){
+ return list.sort(function(a,b){
+ return sort_wall_els_by_x(a,b) || sort_wall_els_by_z(a,b)
+ })
+}
+
+function sort_wall_els_by_z(list){
+ return list.sort(function(a,b){
+ return a.z < b.z ? -1 : a.z == b.z ? 0 : 1
+ })
+}
+function sort_wall_els_by_x(a){
+ return list.sort(function(a,b){
+ return a.x < b.x ? -1 : a.x == b.x ? 0 : 1
+ })
+}
+