Ejemplo n.º 1
0
 def do_Step(self, dx, dy, scale):
     v = self.viewer
     rc = v.rotation_center
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gltbx.util.rotate_object_about_eye_x_and_y(scale, rc[0], rc[1], rc[2],
                                                dx, dy, 0, 0)
     v.OnRedraw()
Ejemplo n.º 2
0
 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()
Ejemplo n.º 3
0
 def draw_spheres(self, solid=False):
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gray = 0.3
     gl.glColor3f(gray, gray, gray)
     if solid:
         gl.glEnable(gl.GL_LIGHTING)
         gl.glEnable(gl.GL_LIGHT0)
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, [1, 1, 1, 1])
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, [0, 0, 1, 0])
         gl.glEnable(gl.GL_BLEND)
         gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
         gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, [1, 1, 1, 0.5])
         sphere = gltbx.util.SolidSphere
         grid = 50
     else:
         sphere = gltbx.util.WireSphere
         grid = 20
     for i, (x, r) in enumerate(self.spheres):
         gl.glPushMatrix()
         gl.glTranslated(*(x))
         sphere(radius=r, slices=grid, stacks=grid)
         gl.glPopMatrix()
     if solid:
         gl.glDisable(gl.GL_LIGHTING)
         gl.glDisable(gl.GL_LIGHT0)
         gl.glDisable(gl.GL_BLEND)
Ejemplo n.º 4
0
 def snap_back_rotation(self):
     rc = self.rotation_center
     rotation_to_undo = matrix.sqr(
         gltbx.util.extract_rotation_from_gl_modelview_matrix())
     if self.marked_rotation is not None:
         rotation_to_undo *= self.marked_rotation.inverse()
     aa = scitbx.math.r3_rotation_axis_and_angle_from_matrix(
         r=rotation_to_undo.as_mat3())
     u, v, w = aa.axis
     angle = -aa.angle(deg=True)
     mvm = gltbx.util.get_gl_modelview_matrix()
     for f in animation_stepper(
             time_move=self.animation_time,
             move_factor=self.rotation_move_factor(angle)):
         gl.glMatrixMode(gl.GL_MODELVIEW)
         gl.glLoadMatrixd(mvm)
         gltbx.util.rotate_object_about_eye_vector(
             xcenter=rc[0],
             ycenter=rc[1],
             zcenter=rc[2],
             xvector=u,
             yvector=v,
             zvector=w,
             angle=f * angle,
         )
         self.OnRedraw()
Ejemplo n.º 5
0
 def do_AutoSpin(self):
     spin_factor = 0.05
     rc = self.rotation_center
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gltbx.util.rotate_object_about_eye_x_and_y(spin_factor, rc[0], rc[1],
                                                rc[2], self.yspin,
                                                self.xspin, 0, 0)
     self.OnRedraw()
Ejemplo n.º 6
0
 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()
Ejemplo n.º 7
0
 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()
Ejemplo n.º 8
0
 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()
Ejemplo n.º 9
0
 def setup_fog(self):
     if self.flag_show_fog:
         near, far = self.get_clipping_distances()
         fog_start = near + self.fog_scale_factor * (far - near)
         fog_end = max(fog_start + 5, far)
         gl.glMatrixMode(gl.GL_MODELVIEW)
         gl.glEnable(gl.GL_FOG)
         gl.glFogi(gl.GL_FOG_MODE, gl.GL_LINEAR)
         gl.glFogf(gl.GL_FOG_START, fog_start)
         gl.glFogf(gl.GL_FOG_END, fog_end)
         b = self.background_rgb
         gl.glFogfv(gl.GL_FOG_COLOR, [b[0], b[1], b[2], 1.0])
     else:
         gl.glDisable(gl.GL_FOG)
Ejemplo n.º 10
0
 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,
     )