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))
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)
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
def translate(self, translation): translation_matrix = matrix_math.translation_matrix(*translation) self.points = matrix_math.multiply(self.points, translation_matrix)