def translate(self, tx, ty, tz): tr = ((1.0, 0.0, 0.0, tx), (0.0, 1.0, 0.0, ty), (0.0, 0.0, 1.0, tz), (0.0, 0.0, 0.0, 1.0)) inv_tr = ((1.0, 0.0, 0.0, -tx), (0.0, 1.0, 0.0, -ty), (0.0, 0.0, 1.0, -tz), (0.0, 0.0, 0.0, 1.0)) self.m = mmmul(tr, self.m) self.inv_m = mmmul(self.inv_m, inv_tr)
def scale(self, sx, sy, sz): sc = ((sx, 0.0, 0.0, 0.0), (0.0, sy, 0.0, 0.0), (0.0, 0.0, sz, 0.0), (0.0, 0.0, 0.0, 1.0)) inv_sc = ((1.0 / sx, 0.0, 0.0, 0.0), (0.0, 1.0 / sy, 0.0, 0.0), (0.0, 0.0, 1.0 / sz, 0.0), (0.0, 0.0, 0.0, 1.0)) self.m = mmmul(sc, self.m) self.inv_m = mmmul(self.inv_m, inv_sc)
def rotatez(self, d): cosd = math.cos(math.radians(d)) sind = math.sin(math.radians(d)) rz = ((cosd, -sind, 0.0, 0.0), (sind, cosd, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 1.0)) inv_rz = ((cosd, sind, 0.0, 0.0), (-sind, cosd, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0), (0.0, 0.0, 0.0, 1.0)) self.m = mmmul(rz, self.m) self.inv_m = mmmul(self.inv_m, inv_rz)
def rotatey(self, d): cosd = math.cos(math.radians(d)) sind = math.sin(math.radians(d)) ry = ((cosd, 0.0, sind, 0.0), (0.0, 1.0, 0.0, 0.0), (-sind, 0.0, cosd, 0.0), (0.0, 0.0, 0.0, 1.0)) inv_ry = ((cosd, 0.0, -sind, 0.0), (0.0, 1.0, 0.0, 0.0), (sind, 0.0, cosd, 0.0), (0.0, 0.0, 0.0, 1.0)) self.m = mmmul(ry, self.m) self.inv_m = mmmul(self.inv_m, inv_ry)
def rotatex(self, d): cosd = math.cos(math.radians(d)) sind = math.sin(math.radians(d)) rx = ((1.0, 0.0, 0.0, 0.0), (0.0, cosd, -sind, 0.0), (0.0, sind, cosd, 0.0), (0.0, 0.0, 0.0, 1.0)) inv_rx = ((1.0, 0.0, 0.0, 0.0), (0.0, cosd, sind, 0.0), (0.0, -sind, cosd, 0.0), (0.0, 0.0, 0.0, 1.0)) self.m = mmmul(rx, self.m) self.inv_m = mmmul(self.inv_m, inv_rx)
def _check(self): res = mmmul(self.m, self.inv_m) if mcmp(res, identity()): print "OK" else: print "FAIL", res