def create_matrix(self):
c = cos(radians(self.rotation))
s = sin(radians(self.rotation))
R = numpy.matrix([[c,-s,0],[s,c,0],[0,0,1]])
S = numpy.matrix([[self.scale_s,0,0],[0,self.scale_t,0],[0,0,1]])
C = numpy.matrix([[1,0,self.center_s],[0,1,self.center_t],[0,0,1]])
T = numpy.matrix([[1,0,self.translation_s],[0,1,self.translation_t],[0,0,1]])
# Only types 0x00, 0x06, 0x07, 0x08 and 0x09 have been tested
if self.matrix_type in {0x00,0x02,0x0A,0x0B,0x80}:
P = numpy.matrix([[1,0,0,0],[0,1,0,0],[0,0,0,1]])
elif self.matrix_type == 0x06:
P = numpy.matrix([[0.5,0,0,0.5],[0,-0.5,0,0.5],[0,0,0,1]])
elif self.matrix_type == 0x07:
P = numpy.matrix([[0.5,0,0.5,0],[0,-0.5,0.5,0],[0,0,1,0]])
elif self.matrix_type in {0x08,0x09}:
P = numpy.matrix([[0.5,0,0.5,0],[0,-0.5,0.5,0],[0,0,1,0]])*numpy.matrix(self.projection_matrix)
else:
raise ValueError('invalid texture matrix type')
M = T*C*S*R*C.I*P
if self.shape == gx.TG_MTX2x4:
return M[:2,:]
elif self.shape == gx.TG_MTX3x4:
return M
else:
raise ValueError('invalid texture matrix shape')
评论列表
文章目录