def get_view_matrix(self): """Get the view matrix as a euclid.Matrix4.""" f = (v3(self.look_at) - v3(self.pos)).normalized() #print "f=", f up = Vector3(0, 1, 0) s = f.cross(up).normalize() #print abs(f), abs(up), abs(s) #print "s=", s u = s.cross(f) m = Matrix4.new( *itertools.chain(s, [0], u, [0], -f, [0], [0, 0, 0, 1])) #print m xlate = Matrix4.new_translate(*(-self.pos)) #print xlate mat = m.inverse() * xlate #print mat return mat
def get_view_matrix_gl(self): from ctypes import c_double mat = (c_double * 16)() glGetDoublev(GL_MODELVIEW_MATRIX, mat) return Matrix4.new(*mat)