def make_geometry(self, width): self.ends = [ vec2(self.end_points[0].x, self.end_points[0].y), vec2(self.end_points[1].x, self.end_points[1].y) ] self.make_walls_and_doors(width) return
def build_geometry(self, points): """ Builds the geometry for a room consisting of centre point, ad a number of corridor end points where each branch of a corridoor ends """ length = 0 radius = 0.0 self.centre_point = vec2( points[self.centre].x, points[self.centre].y ) for b in self.branches: end_point = vec2( points[b].x, points[b].y ) self.points = self.points + [ end_point ] length = geom.line_exp_len_2d(self.centre_point, end_point) radius = radius + length self.radius = radius / ( len(self.branches) * 2.0 ) #print "Radius %s " % self.radius return
def build_room_geometry(self): """ Given that the rooms have been identified, flesh out their geometry """ for r in self.rooms: r.build_geometry(self.end_points) doors = [] for point in r.points: line = ( r.centre_point, point ) ## now, interoplate a bit along the line in order to get the vertex of a polygon door_point = vec2((line[1].x - line[0].x) * 0.25 + line[0].x, (line[1].y - line[0].y) * 0.25 + line[0].y) r.doors += [ door_point ] # door_line = ( door_point, geom.line_exp_perp_2d(line[0], line[1], door_point) ) # door_line_delta = door_line[1] - door_line[0] # door_line_delta = door_line_delta * 1.0 / door_line_delta.length() # door_line = ( door_point + ( door_line_delta * 0.02 ) , door_point - ( door_line_delta * 0.02 ) ) # r.doors = r.doors + [ door_line ] # print "Points: ", r.points for ci in r.connections: connection = self.connections[ci] # print "Room centere %s " % r.centre_point # print "Connection %d (%d,%d) " % (ci, self.connections[ci][0], self.connections[ci][1] ) # print "Connection %s %s " % (self.end_points[self.connections[ci][0]], self.end_points[self.connections[ci][1]] ) corridor = self.corridors[ci] # print "Corridor ends 0 %s 1 % s " % (corridor.end_points[0], corridor.end_points[1]) end = connection.closest(r.centre_point, self.end_points) # print "end is %d " % end assert(corridor.end_points[end] == vec3(r.centre_point.x, r.centre_point[1], 0.0)) corridor.shorten_corridor(0.25, end, self.corridor_width) r.build_floorplan(self.corridors, self.end_points) return
def build_room_geometry(self): """ Given that the rooms have been identified, flesh out their geometry """ for r in self.rooms: r.build_geometry(self.end_points) doors = [] for point in r.points: line = (r.centre_point, point) ## now, interoplate a bit along the line in order to get the vertex of a polygon door_point = vec2((line[1].x - line[0].x) * 0.25 + line[0].x, (line[1].y - line[0].y) * 0.25 + line[0].y) r.doors += [door_point] # door_line = ( door_point, geom.line_exp_perp_2d(line[0], line[1], door_point) ) # door_line_delta = door_line[1] - door_line[0] # door_line_delta = door_line_delta * 1.0 / door_line_delta.length() # door_line = ( door_point + ( door_line_delta * 0.02 ) , door_point - ( door_line_delta * 0.02 ) ) # r.doors = r.doors + [ door_line ] # print "Points: ", r.points for ci in r.connections: connection = self.connections[ci] # print "Room centere %s " % r.centre_point # print "Connection %d (%d,%d) " % (ci, self.connections[ci][0], self.connections[ci][1] ) # print "Connection %s %s " % (self.end_points[self.connections[ci][0]], self.end_points[self.connections[ci][1]] ) corridor = self.corridors[ci] # print "Corridor ends 0 %s 1 % s " % (corridor.end_points[0], corridor.end_points[1]) end = connection.closest(r.centre_point, self.end_points) # print "end is %d " % end assert (corridor.end_points[end] == vec3( r.centre_point.x, r.centre_point[1], 0.0)) corridor.shorten_corridor(0.25, end, self.corridor_width) r.build_floorplan(self.corridors, self.end_points) return
def build_floorplan(self, corridors, room_centre_points): """ Construct a floorplan for the room. Consists of a series of points describing a polygon around the room in polar form """ for ci in self.connections: corridor = corridors[ci] end = corridor.connection.closest(self.centre_point, room_centre_points) # which end of the corridor is closest to this room? for point in corridor.door_geometry(end): self.floorplan += [ self.convert_to_polar(point) ] # sort them in radial orde self.floorplan.sort(compare_points) new_floorplan = [] new_floorplan.append(self.floorplan[0]) for i in range(0, len(self.floorplan) - 1): new_floorplan.append(vec2(self.floorplan[i].r, self.floorplan[i].theta + (self.floorplan[i+1].theta - self.floorplan[i].theta) / 2)) new_floorplan.append(self.floorplan[i+1]) self.floorplan = new_floorplan