summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/engine/builder.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/javascripts/rectangles/engine/builder.js')
-rw-r--r--assets/javascripts/rectangles/engine/builder.js163
1 files changed, 82 insertions, 81 deletions
diff --git a/assets/javascripts/rectangles/engine/builder.js b/assets/javascripts/rectangles/engine/builder.js
index 4ccc649..3452ecc 100644
--- a/assets/javascripts/rectangles/engine/builder.js
+++ b/assets/javascripts/rectangles/engine/builder.js
@@ -21,25 +21,27 @@ var builder = new function(){
function build (){
clipper.rooms = sort_rooms_by_id(clipper.rooms)
- clipper.regions.forEach(function(r){
- build_walls(r).forEach(function(el){
+ clipper.regions.forEach(function(room){
+ build_walls(room).forEach(function(el){
els.push(el)
scene.add(el)
})
})
clipper.rooms = sort_rooms_by_height(clipper.rooms)
- clipper.rooms.forEach(function(r){
- build_floors(r).forEach(function(el){
+ clipper.rooms.forEach(function(room){
+ build_floors(room).forEach(function(el){
els.push(el)
scene.add(el)
})
})
+
+ clipper.rooms = sort_rooms_by_id(clipper.rooms)
}
function bind (){
- clipper.rooms.forEach(function(r){
- r.bind()
+ clipper.rooms.forEach(function(room){
+ room.bind()
})
}
@@ -50,200 +52,199 @@ var builder = new function(){
els = []
}
- function build_walls (r){
- var rm = clipper.rooms[ r.id ]
+ function build_walls (region){
+ var room = clipper.rooms[ region.id ]
var list = [], el = null
- var width = r.x.length()
- var depth = r.y.length()
- var height = clipper.rooms[r.id].height
+ var width = region.x.length()
+ var depth = region.y.length()
+ var height = room.height
- if (r.sides & FRONT) {
+ if (region.sides & FRONT) {
el = make_wall('.front')
el.width = width
el.height = height
el.rotationY = PI
- el.x = r.x.a + width/2
+ el.x = region.x.a + width/2
el.y = height/2
- el.z = r.y.a
- rm.$walls.push(el.el)
+ el.z = region.y.a
+ room.walls.push(el)
list.push(el)
}
- if (r.sides & BACK) {
+ if (region.sides & BACK) {
var el = make_wall('.back')
el.width = width
el.height = height
el.rotationY = 0
- el.x = r.x.b - width/2
+ el.x = region.x.b - width/2
el.y = height/2
- el.z = r.y.b
- rm.$walls.push(el.el)
+ el.z = region.y.b
+ room.walls.push(el)
list.push(el)
}
- if (r.sides & LEFT) {
+ if (region.sides & LEFT) {
el = make_wall('.left')
el.rotationY = HALF_PI
el.height = height
el.width = depth
- el.x = r.x.a
+ el.x = region.x.a
el.y = height/2
- el.z = r.y.a + depth/2
- rm.$walls.push(el.el)
+ el.z = region.y.a + depth/2
+ room.walls.push(el)
list.push(el)
}
- if (r.sides & RIGHT) {
+ if (region.sides & RIGHT) {
el = make_wall('.right')
el.rotationY = -HALF_PI
el.height = height
el.width = depth
- el.x = r.x.b
+ el.x = region.x.b
el.y = height/2
- el.z = r.y.b - depth/2
- rm.$walls.push(el.el)
+ el.z = region.y.b - depth/2
+ room.walls.push(el)
list.push(el)
}
return list
}
- function build_floors(rm){
+ function build_floors(room){
var list = [], el = null
- var already_constructed = rm.intersects.filter(function(rr){ return rr.constructed })
- sort_rooms_by_height(already_constructed)
+ var constructed = room.intersects.filter(function(room){ return room.constructed })
+ sort_rooms_by_height(constructed)
- if (already_constructed.length > 0) {
+ if (constructed.length > 0) {
// render the regions that don't intersect with anything we've already rendered
// if the height is different, calculate the overlapping sides and render half-walls
- rm.regions.forEach(function(r){
+ room.regions.forEach(function(region){
var intersected = false
- for (var i = 0; i < already_constructed.length; i++) {
- if (already_constructed[i].rect.contains(r)) {
+ for (var i = 0; i < constructed.length; i++) {
+ if (constructed[i].rect.contains(region)) {
intersected = true
// r.sides = 0xf
// half_sides
}
- else if (already_constructed[i].rect.intersects(r)) {
+ else if (constructed[i].rect.intersects(region)) {
intersected = true
- if (rm.height < already_constructed[i].height) {
- list = list.concat( make_ceiling_walls( rm, already_constructed[i], r ) )
+ if (room.height < constructed[i].height) {
+ list = list.concat( make_ceiling_walls( room, constructed[i], region ) )
}
}
}
if (! intersected) {
- el = make_floor(rm, r)
+ el = make_floor(room, region)
list.push( el )
- rm.$floor.push(el.el)
+ room.floor.push(el)
- el = make_ceiling(rm, r)
+ el = make_ceiling(room, region)
list.push( el )
- rm.$ceiling.push(el.el)
+ room.ceiling.push(el)
}
})
}
else {
// render floor and ceiling for the entire rectangle
- el = make_floor(rm, rm.rect)
+ el = make_floor(room, room.rect)
list.push( el )
- rm.$floor.push(el.el)
+ room.floor.push(el)
- el = make_ceiling(rm, rm.rect)
+ el = make_ceiling(room, room.rect)
list.push( el )
- rm.$ceiling.push(el.el)
+ room.ceiling.push(el)
}
- rm.constructed = true
+ room.constructed = true
return list
}
- function make_ceiling_walls( lo, hi, r ){
+ function make_ceiling_walls( lo, hi, region ){
var list = []
- var width = r.x.length()
- var depth = r.y.length()
+ var width = region.x.length()
+ var depth = region.y.length()
var height = hi.height - lo.height
- if (! (r.half_sides & LEFT) && r.x.a == hi.rect.x.a) {
+ if (! (region.half_sides & LEFT) && region.x.a == hi.rect.x.a) {
el = make_wall('.left')
el.rotationY = HALF_PI
el.height = height
el.width = depth
- el.x = r.x.a
+ el.x = region.x.a
el.y = lo.height + height/2
- el.z = r.y.a + depth/2
+ el.z = region.y.a + depth/2
list.push(el)
- hi.$walls.push(el.el)
- r.half_sides |= LEFT
+ hi.walls.push(el)
+ region.half_sides |= LEFT
}
- if (! (r.half_sides & RIGHT) && r.x.b == hi.rect.x.b) {
+ if (! (region.half_sides & RIGHT) && region.x.b == hi.rect.x.b) {
el = make_wall('.right')
el.rotationY = -HALF_PI
el.height = height
el.width = depth
- el.x = r.x.b
+ el.x = region.x.b
el.y = lo.height + height/2
- el.z = r.y.b - depth/2
+ el.z = region.y.b - depth/2
list.push(el)
- hi.$walls.push(el.el)
- r.half_sides |= RIGHT
+ hi.walls.push(el)
+ region.half_sides |= RIGHT
}
- if (! (r.half_sides & FRONT) && r.y.a == hi.rect.y.a) {
+ if (! (region.half_sides & FRONT) && region.y.a == hi.rect.y.a) {
el = make_wall('.front')
el.width = width
el.height = height
el.rotationY = PI
- el.x = r.x.a + width/2
+ el.x = region.x.a + width/2
el.y = lo.height + height/2
- el.z = r.y.a
+ el.z = region.y.a
list.push(el)
- hi.$walls.push(el.el)
- r.half_sides |= FRONT
+ hi.walls.push(el)
+ region.half_sides |= FRONT
}
- if (! (r.half_sides & BACK) && r.y.b == hi.rect.y.b) {
+ if (! (region.half_sides & BACK) && region.y.b == hi.rect.y.b) {
el = make_wall('.back')
el.width = width
el.height = height
el.rotationY = 0
- el.x = r.x.b - width/2
+ el.x = region.x.b - width/2
el.y = lo.height + height/2
- el.z = r.y.b
+ el.z = region.y.b
list.push(el)
- hi.$walls.push(el.el)
- r.half_sides |= BACK
+ hi.walls.push(el)
+ region.half_sides |= BACK
}
return list
}
- function make_floor(rm, r){
- var width = r.x.length()
- var depth = r.y.length()
+ function make_floor(room, region){
+ var width = region.x.length()
+ var depth = region.y.length()
var el = make_wall('.floor')
el.height = depth
el.width = width
- el.x = r.x.a + width/2
+ el.x = region.x.a + width/2
el.y = 0
- el.z = r.y.a + depth/2
+ el.z = region.y.a + depth/2
el.rotationX = PI/2
-
return el
}
- function make_ceiling(rm, r){
- var width = r.x.length()
- var depth = r.y.length()
- var height = rm.height
+ function make_ceiling(room, region){
+ var width = region.x.length()
+ var depth = region.y.length()
+ var height = room.height
var el = make_wall('.ceiling')
el.height = depth
el.width = width
- el.x = r.x.a + width/2
+ el.x = region.x.a + width/2
el.y = height
- el.z = r.y.a + depth/2
+ el.z = region.y.a + depth/2
el.rotationX = -PI/2
return el
}