def setup_viewing_volume(self): aspect = self.w / max(1, self.h) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() near, far = self.get_clipping_distances() if self.orthographic: s = self.minimum_covering_sphere # c = s.center() c = self.rotation_center r = s.radius() rf = self.buffer_factor * r left = c[0] - rf right = c[0] + rf bottom = c[1] - rf top = c[1] + rf if aspect < 1: bottom /= aspect top /= aspect else: left *= aspect right *= aspect gl.glOrtho(left, right, bottom, top, near, far) else: glu.gluPerspective(self.field_of_view_y, aspect, near, far) self.set_lights() self.setup_fog()
def set_lights(self): if self.flag_use_lights: gl.glMatrixMode(gl.GL_MODELVIEW) gl.glPushMatrix() gl.glLoadIdentity() gl.glEnable(gl.GL_LIGHTING) gl.glEnable(gl.GL_LIGHT0) gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, self.light0_position) gl.glPopMatrix()
def fit_into_viewport(self): dx, dy, dz = self.compute_home_translation() move_factor = self.translation_move_factor((dx, dy, dz)) mvm = gltbx.util.get_gl_modelview_matrix() for f in animation_stepper(time_move=self.animation_time, move_factor=move_factor): gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glTranslated(f * dx, f * dy, f * dz) gl.glMultMatrixd(mvm) self.OnRedraw()
def move_to_center_of_viewport(self, obj_coor): dx, dy = [-x for x in gltbx.util.object_as_eye_coordinates(obj_coor)[:2]] move_factor = self.translation_move_factor((dx, dy, 0)) mvm = gltbx.util.get_gl_modelview_matrix() for f in animation_stepper( time_move=self.animation_time, move_factor=move_factor ): gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glTranslated(f * dx, f * dy, 0) gl.glMultMatrixd(mvm) self.OnRedraw()
def initialize_modelview(self, eye_vector=None, angle=None): gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() self.setup_lighting() glu.gluLookAt(0, 0, 0, 0, 0, -1, 0, 1, 0) translation = self.compute_home_translation() gl.glTranslated(*translation) rc = self.minimum_covering_sphere.center() self.rotation_center = rc if eye_vector is None: eye_vector = (1, 1, 1) if angle is None: angle = -120 gltbx.util.rotate_object_about_eye_vector( xcenter=rc[0], ycenter=rc[1], zcenter=rc[2], xvector=eye_vector[0], yvector=eye_vector[1], zvector=eye_vector[2], angle=angle, )