def set_matrix(self, v): ''' To debug this, make sure gluPerspective and gluLookAt have the same parameter when given the same mouse events in cpp and in python ''' ############ # Projection glMatrixMode( GL_PROJECTION ) glLoadIdentity() pixel_ratio = self.w / float(self.h) zF = v.focal / 30.0 diam2 = 2.0 * self.scene.bb.sphere_beam() look = sub(v.tget, v.eye) diam = 0.5 * norm(look) recul = 2 * diam zNear = 0.01 * recul # 1% du segment de visee oeil-cible zFar = recul + diam2 if pixel_ratio < 1: zF /= pixel_ratio logger.info('gluPerspective %f %f %f %f' % (zF*30, pixel_ratio, zNear, zFar)) gluPerspective (zF*30, pixel_ratio, zNear, zFar) # For debug: hard-coded values for some models #gluPerspective ( 32, 1.34, 27, 54 ) # Gears #gluPerspective ( 32, 1.44, 204, 409 ) # spaceship ############ # Model View glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTranslatef(v.recenterX, v.recenterY, 0.0) # Take care of the eye rotation_matrix = quaternion_to_matrix(v.quat) new_look = [0, 0, recul] # LOL name v.eye = multiply_point_by_matrix(rotation_matrix, new_look) v.eye = add(v.eye, self.scene.bb.center()) # Vector UP (Y) vup_t = multiply_point_by_matrix(rotation_matrix, [0.0, 1.0, 0.0]) logger.info('gluLookAt eye %s' % str(v.eye)) logger.info('gluLookAt tget %s' % str(v.tget)) logger.info('gluLookAt vup %s' % str(vup_t)) gluLookAt ( v.eye[0], v.eye[1], v.eye[2], v.tget[0], v.tget[1], v.tget[2], vup_t[0], vup_t[1], vup_t[2] )
def set_matrix(self, v): ''' To debug this, make sure gluPerspective and gluLookAt have the same parameter when given the same mouse events in cpp and in python ''' ############ # Projection glMatrixMode(GL_PROJECTION) glLoadIdentity() pixel_ratio = self.w / float(self.h) zF = v.focal / 30.0 diam2 = 2.0 * self.scene.bb.sphere_beam() look = sub(v.tget, v.eye) diam = 0.5 * norm(look) recul = 2 * diam zNear = 0.01 * recul # 1% du segment de visee oeil-cible zFar = recul + diam2 if pixel_ratio < 1: zF /= pixel_ratio logger.info('gluPerspective %f %f %f %f' % (zF * 30, pixel_ratio, zNear, zFar)) gluPerspective(zF * 30, pixel_ratio, zNear, zFar) # For debug: hard-coded values for some models #gluPerspective ( 32, 1.34, 27, 54 ) # Gears #gluPerspective ( 32, 1.44, 204, 409 ) # spaceship ############ # Model View glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTranslatef(v.recenterX, v.recenterY, 0.0) # Take care of the eye rotation_matrix = quaternion_to_matrix(v.quat) new_look = [0, 0, recul] # LOL name v.eye = multiply_point_by_matrix(rotation_matrix, new_look) v.eye = add(v.eye, self.scene.bb.center()) # Vector UP (Y) vup_t = multiply_point_by_matrix(rotation_matrix, [0.0, 1.0, 0.0]) logger.info('gluLookAt eye %s' % str(v.eye)) logger.info('gluLookAt tget %s' % str(v.tget)) logger.info('gluLookAt vup %s' % str(vup_t)) gluLookAt(v.eye[0], v.eye[1], v.eye[2], v.tget[0], v.tget[1], v.tget[2], vup_t[0], vup_t[1], vup_t[2])
def reset(self, _bb): self.recenterX = 0.0 self.recenterY = 0.0 self.focal = 32.0 self.quat = common_quaternion_from_angles(180, 45 + 22.5, 0) self.quat = [-0.23, 0.40, 0.090, 0.88] recul = 1.5 * _bb.sphere_beam() if False: # try to mimic cpp but that does not work look = [0.0, 0.0, recul] self.eye = point_by_matrix(quaternion_to_matrix(self.quat), look) self.tget = look # Using sub(_bb.min(), [recul, recul, recul]) has the same effects self.eye = add([recul, recul, recul], _bb.max()) self.tget = _bb.center()
def reset(self, _bb): self.recenterX = 0.0 self.recenterY = 0.0 self.focal = 32.0 self.quat = common_quaternion_from_angles(180, 45+22.5, 0 ) self.quat = [-0.23, 0.40, 0.090, 0.88] recul = 1.5 * _bb.sphere_beam() if False: # try to mimic cpp but that does not work look = [0.0, 0.0, recul] self.eye = point_by_matrix(quaternion_to_matrix(self.quat), look) self.tget = look # Using sub(_bb.min(), [recul, recul, recul]) has the same effects self.eye = add([recul, recul, recul], _bb.max()) self.tget = _bb.center()
# -*- coding:utf-8 -*- ''' Python调试及单元测试 http://www.fuzhijie.me/?p=310 ''' import math_utils a = 3 b = 4 c = math_utils.add(a, b) print c