Beispiel #1
0
 def set_position(self, position):
     self.position = position
     current_position = self.points.access_row(0)
     # d_vector is a vector to calculate and store the difference between the new and current first points, which can then be applied to the whole points matrix
     self.d_vector = current_position[0] - position[0], current_position[1] - position[1], current_position[2] - position[2], current_position[3]
     self.projected = self.points = matrix_math.add_vector(self.points, matrix_math.inverse_vector(self.d_vector))
Beispiel #2
0
 def scale(self, scale_factor, anchor = None): # Anchor is a point object which stores the point to scale from
     ''' Scales the object from an arbetrary point '''
     if anchor == None:  # If no anchor is provided, scale from objects centre
         anchor = self.find_centre()
     scale_matrix = matrix_math.scale_matrix(*scale_factor)
     self.points = matrix_math.add_vector(matrix_math.multiply(matrix_math.add_vector(self.points, matrix_math.inverse_vector(anchor)), scale_matrix), anchor) # Equivalent to self.points = scale_factor * (self.points - anchor) + anchor
Beispiel #3
0
 def _rotate_y(self, anchor, y_rotation):
     rotate_y_matrix = matrix_math.rotate_y_matrix(y_rotation)      
     self.points = matrix_math.add_vector(matrix_math.multiply(matrix_math.add_vector(self.points, matrix_math.inverse_vector(anchor)), rotate_y_matrix), anchor)
Beispiel #4
0
 def project(self, projection_type, projection_anchor):
     self.projected = self.points.copy()
     for i, point in enumerate(self.projected):
         if projection_type == 'orthographic':
             projection_matrix = matrix_math.orthographic_projection_matrix()
         elif projection_type == 'perspective':
             projection_matrix = matrix_math.perspective_projection_matrix(point[2])
         else:
             print('ERROR: Invaild projection type entered: {}'.format(projection_type))
         self.projected.set_row(i, matrix_math.add_vector(matrix_math.multiply(matrix_math.add_vector(point, matrix_math.inverse_vector(projection_anchor)), projection_matrix), projection_anchor).access_row(0))