Exemple #1
0
 def translate(self, displacement):
   self.poly3d.vertices = matrix.translate_points(self.poly3d.vertices, displacement)
Exemple #2
0
  def init_poly_views(self, win, tilesize, gapsize, origin, deltaz = 1.00):
#    def make_xz_tile(tile_center, tilesize):
#      radius = 0.5 * tilesize
#      n = 4
#      dtheta = 2.0 * math.pi / n
#      points = []
#      for i in range(n):
#        points.append([tile_center[0] - radius * math.cos(i * dtheta), \
#          tile_center[1], \
#          tile_center[2] + radius * math.sin(i * dtheta)])
#      return points

    def make_xz_tile(tile_center, tilesize):
      half = 0.5 * tilesize
      points = [[tile_center[0] - half, tile_center[1], tile_center[2] + half], \
                [tile_center[0] + half, tile_center[1], tile_center[2] + half], \
                [tile_center[0] + half, tile_center[1], tile_center[2] - half], \
                [tile_center[0] - half, tile_center[1], tile_center[2] - half]]
      return points

    def make_xy_tile(tile_center, tilesize):
      half = 0.5 * tilesize
      points = [[tile_center[0] - half, tile_center[1] - half, tile_center[2]], \
                [tile_center[0] + half, tile_center[1] - half, tile_center[2]], \
                [tile_center[0] + half, tile_center[1] + half, tile_center[2]], \
                [tile_center[0] - half, tile_center[1] + half, tile_center[2]]]
      return points

    def make_yz_tile(tile_center, tilesize):
      half = 0.5 * tilesize
      points = [[tile_center[0], tile_center[1] - half, tile_center[2] - half], \
                [tile_center[0], tile_center[1] - half, tile_center[2] + half], \
                [tile_center[0], tile_center[1] + half, tile_center[2] - half], \
                [tile_center[0], tile_center[1] + half, tile_center[2] + half]]
      return points

    def operate_on_list_of_tiles(trans, tile_list, origin):
      tile_list_copy = copy.deepcopy(tile_list)
      for i in range(len(tile_list_copy)):
        tile_list_copy[i] = trans.list_operate(tile_list_copy[i], origin)
      return tile_list_copy

    self.poly_views = []
    # make top face:
    # start at back left corner
    rotx = matrix.rotx(0.5 * math.pi)
    rotxi = matrix.rotx(-0.5 * math.pi)
    rotx2 = matrix.rotx(math.pi)
    rotz = matrix.rotz(0.5 * math.pi)
    rotz2 = matrix.rotz(math.pi)
    #roty = matrix.roty(0.5 * math.pi)
    #rotyi = matrix.roty(-0.5 * math.pi)

    tile_center = [origin[0] - tilesize - gapsize, \
                   origin[1] - 1.5 * tilesize - 2 * gapsize, \
                   origin[2] + tilesize + gapsize]

    # construct vertices for top face tile polygons
    top_points_list = []
    tile_points = make_xz_tile(tile_center, tilesize)
    top_points_list.append(list(tile_points))
    tile_points = matrix.translate_points(tile_points, [tilesize + gapsize, 0.0, 0.0])
    top_points_list.append(list(tile_points))
    tile_points = matrix.translate_points(tile_points, [tilesize + gapsize, 0.0, 0.0])
    top_points_list.append(list(tile_points))
    tile_points = matrix.translate_points(tile_points, [- 2 * (tilesize + gapsize), 0.0, -(tilesize + gapsize)])
    top_points_list.append(list(tile_points))
    tile_points = matrix.translate_points(tile_points, [tilesize + gapsize, 0.0, 0.0])
    top_points_list.append(list(tile_points))
    tile_points = matrix.translate_points(tile_points, [tilesize + gapsize, 0.0, 0.0])
    top_points_list.append(list(tile_points))
    tile_points = matrix.translate_points(tile_points, [- 2 * (tilesize + gapsize), 0.0, -(tilesize + gapsize)])
    top_points_list.append(list(tile_points))
    tile_points = matrix.translate_points(tile_points, [tilesize + gapsize, 0.0, 0.0])
    top_points_list.append(list(tile_points))
    tile_points = matrix.translate_points(tile_points, [tilesize + gapsize, 0.0, 0.0])
    top_points_list.append(list(tile_points))

    # construct other faces by copying and iteratively transforming top face tile polygons
    front_points_list = copy.deepcopy(top_points_list)
    front_points_list = operate_on_list_of_tiles(rotx, front_points_list, origin)
    bottom_points_list = copy.deepcopy(front_points_list)
    bottom_points_list = operate_on_list_of_tiles(rotx, bottom_points_list, origin)
    back_points_list = copy.deepcopy(bottom_points_list)
    back_points_list = operate_on_list_of_tiles(rotx, back_points_list, origin)
    back_points_list = operate_on_list_of_tiles(rotz2, back_points_list, origin)
    right_points_list = copy.deepcopy(top_points_list)
    right_points_list = operate_on_list_of_tiles(rotz, right_points_list, origin)
    right_points_list = operate_on_list_of_tiles(rotx, right_points_list, origin)
    left_points_list = copy.deepcopy(bottom_points_list)
    left_points_list = operate_on_list_of_tiles(rotz, left_points_list, origin)
    left_points_list = operate_on_list_of_tiles(rotxi, left_points_list, origin)

    facedict = { 'U': top_points_list, \
                 'F': front_points_list, \
                 'R': right_points_list, \
                 'B': back_points_list, \
                 'L': left_points_list, \
                 'D': bottom_points_list }

    self.pvc = view.PolyViewCollection([], win, origin, deltaz = 0.5, camera = self.camera)
    for face_name in ['U', 'F', 'R', 'B', 'L', 'D']:
      face = facedict[face_name]
      for points in face:
        if self.border_color == None:
          bc = self.color_pairs[face_name] # no border
        else:
          bc = self.border_color
        self.pvc.append(view.PolyView(win, graphics3d.Poly3d(points), deltaz = deltaz, \
                        border_color = bc, \
                        fill_color = self.color_pairs[face_name], \
                        char = ' '))
Exemple #3
0
 def translate(self, displacement):
   for view in self.views:
     view.poly3d.vertices = matrix.translate_points(view.poly3d.vertices, displacement)