Beispiel #1
0
 def get_normals_plain(self, x, y):
     cell = self.get_cell(x, y)
     ret = []
     if cell is not None:
         north, west, south, east = self.get_cell_nwse(x, y)
     else:
         north, west, south, east = 0, 0, 0, 0
     if (north == west) and (west == east) and (north == south):
         # actually it calls result[x].init( 0, 0, 1 )
         ret = [ [0, 0, 1] for x in xrange(4) ]
     else:
         ret.append(vectorial.normalize(
                    vectorial.cross(
                     [-BOX_SIZE, BOX_SIZE, (north - east) * 4],
                     [-BOX_SIZE, -BOX_SIZE, (west - north) * 4])))
         ret.append(vectorial.normalize(
                    vectorial.cross(
                     [BOX_SIZE, BOX_SIZE, (east - south) * 4],
                     [-BOX_SIZE, BOX_SIZE, (north - east) * 4])))
         ret.append(vectorial.normalize(
                    vectorial.cross(
                     [BOX_SIZE, -BOX_SIZE, (south - west) * 4],
                     [BOX_SIZE, BOX_SIZE, (east - south) * 4])))
         ret.append(vectorial.normalize(
                    vectorial.cross(
                     [BOX_SIZE, BOX_SIZE, (west - north) * 4],
                     [-BOX_SIZE, BOX_SIZE, (south - west) * 4])))
     return ret
Beispiel #2
0
 def get_normals(self, x, y):
     """
         returns a the normals for x,y
     """
     cells = []
     normals = []
     for i in [0, 1, 2]:
         inner_cells = []
         for j in [0, 1, 2]:
             inner_cells.append(self.get_normals_plain(x - 1 + i, y - 1 + j))
         cells.append(inner_cells)
     # this matrix represents:
     # normalization 1-4 of n'th element of i,j
     for m in [ [ [2, 0, 0], [1, 0, 1], [3, 1, 0], [0, 1, 1], ],
                [ [2, 1, 0], [1, 1, 1], [3, 2, 0], [0, 2, 1], ],
                [ [2, 1, 1], [1, 1, 2], [3, 2, 1], [0, 2, 2], ],
                [ [2, 0, 1], [1, 0, 2], [3, 1, 1], [0, 1, 2], ],
               ]:
         v = [0.0, 0.0, 0.0]
         for n, i, j in m:
             # here we actually use the matrix:
             v = vectorial.add(v, cells[i][j][n])
         normals.append(vectorial.normalize(v))
     return normals