Exemple #1
0
 def __init__(self, loc=[0, 0, 0], los=[0, 0, 1]):
     losvector = matrix(4, 1)
     losvector.set_entire_matrix([[los[0]], [los[1]], [los[2]], [1]])
     locvector = matrix(4, 1)
     locvector.set_entire_matrix([[loc[0]], [loc[1]], [loc[2]], [1]])
     self.rotation_matrix = self.init_rotation_matrix(losvector, locvector)
     self.translation_matrix = self.init_translation_matrix(loc[0], loc[1], loc[2])
     self.transform_matrix = self.rotation_matrix.multiply(self.translation_matrix)
Exemple #2
0
 def roll(self, angle):
     cos = math.cos(angle)
     sin = math.sin(angle)
     temp_rot_matrix = matrix(4, 4)
     temp_rot_matrix.set_entire_matrix([[cos, -sin, 0, 0], [sin, cos, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
     self.rotation_matrix = temp_rot_matrix.multiply(self.rotation_matrix)
     self.update_transform_matrix()
Exemple #3
0
    def init_rotation_matrix(self, los, location):
    ##vectors x, y, and z will be their respective axes on a normalized coordinate system with the character at (0, 0, 0) looking directly down the z axis,
        ##z is calculated first as it is used in the calculation of the others
        los = los.subtract(location)
        los.set_cell(3, 0, 1)
        z = los.normalize()
        #world y axis unit vector
        yw = matrix(4, 1)
        yw.set_cell(1, 0, 1)
        y = yw.subtract(z.multiply(yw.dot(z)))
        x = z.cross(y)

        ##the vectors each become their own row in the final matrix
        rot_matrix = matrix(4, 4)
        rot_matrix.set_entire_matrix([[x.get_cell(0, 0), x.get_cell(1, 0), x.get_cell(2, 0), 0],
                                      [y.get_cell(0, 0), y.get_cell(1, 0), y.get_cell(2, 0), 0],
                                      [z.get_cell(0, 0), z.get_cell(1, 0), z.get_cell(2, 0), 0],
                                      [0, 0, 0, 1]])
        return rot_matrix
    def init_rotation_matrix(self, los, location):
        '''initializes a rotation matrix using the method explained on http://www.fastgraph.com/makegames/3drotation/ given a starting line of sight'''
        ##vectors x, y, and z will be their respective axes on a normalized coordinate system with the character at (0, 0, 0) looking directly down the z axis,
        ##z is calculated first as it is used in the calculation of the others
        los = los.subtract(location)
        los.set_cell(3, 0, 1)
        z = los.normalize()
        #world y axis unit vector
        yw = matrix(4, 1)
        yw.set_cell(1, 0, 1)
        y = yw.subtract(z.multiply(yw.dot(z)))
        x = z.cross(y)

        ##the vectors each become their own row in the final matrix
        rot_matrix = matrix(4, 4)
        rot_matrix.set_entire_matrix([[x.get_cell(0, 0), x.get_cell(1, 0), x.get_cell(2, 0), 0],
                                      [y.get_cell(0, 0), y.get_cell(1, 0), y.get_cell(2, 0), 0],
                                      [z.get_cell(0, 0), z.get_cell(1, 0), z.get_cell(2, 0), 0],
                                      [0, 0, 0, 1]])
        return rot_matrix
Exemple #5
0
 def init_translation_matrix(self, x, y, z):
     """initializes a translation matrix for movement, this is just an identity matrix with the last column changed to the location vector"""
     trans_matrix = matrix(4, 4)
     trans_matrix.set_entire_matrix([[1, 0, 0, x], [0, 1, 0, y], [0, 0, 1, z], [0, 0, 0, 1]])
     return trans_matrix
Exemple #6
0
 def add_point(self, x, y, z):
     point = matrix(4, 1)
     point.set_entire_matrix([[x], [y], [z], [1]])
     self.points.append(point)
Exemple #7
0
 def init_translation_matrix(self, x, y, z):
     trans_matrix = matrix(4, 4)
     trans_matrix.set_entire_matrix([[1, 0, 0, x], [0, 1, 0, y], [0, 0, 1, z], [0, 0, 0, 1]])
     return trans_matrix