Пример #1
0
 def set_world(self):
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     position = self.camera.position
     look_at = self.camera.look_at
     glu.gluLookAt(position.x, position.y, position.z, look_at.x, look_at.y,
                   look_at.z, 0, 1, -1)
Пример #2
0
 def on_draw(self):
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
     glTranslatef(-self.camera_rect.x, -self.camera_rect.y, 0)
     self.clear()
     self.map.draw()
     self.prisioner.draw()
Пример #3
0
 def init_view(self):
     # set the model view to initial setting
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     glu.gluLookAt(self.init_camera_param.eye[0],self.init_camera_param.eye[1],self.init_camera_param.eye[2],\
                   self.init_camera_param.eye[0]+self.init_camera_param.direction[0],self.init_camera_param.eye[1]+self.init_camera_param.direction[1],self.init_camera_param.eye[2]+self.init_camera_param.direction[2],\
                   self.init_camera_param.up[0],self.init_camera_param.up[1],self.init_camera_param.up[2])
Пример #4
0
 def view(self):
     # update the model view
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     glu.gluLookAt(self.camera_param.eye[0],self.camera_param.eye[1],self.camera_param.eye[2],\
                   self.camera_param.eye[0]+self.camera_param.direction[0],self.camera_param.eye[1]+self.camera_param.direction[1],self.camera_param.eye[2]+self.camera_param.direction[2],\
                   self.camera_param.up[0],self.camera_param.up[1],self.camera_param.up[2])
Пример #5
0
 def set_screen(self):
     '''
     Set ortho projection, showing world space coords 0 <= x < WIDTH,
     and 0 <= y < HEIGHT.
     '''
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     glu.gluOrtho2D(0, self.width - 1, 0, self.height - 1)
Пример #6
0
 def set_world(self):
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     position = self.camera.position
     look_at = self.camera.look_at
     glu.gluLookAt(
         position.x, position.y, position.z,
         look_at.x, look_at.y, look_at.z,
         0, 1, -1)
Пример #7
0
 def set_projection(self):
     w = (self.win.width / 2) / self.zoom
     h = (self.win.height / 2) / self.zoom
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     gl.glOrtho(-w, w, -h, h, -1, 1)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     gl.glTranslatef(-self.look_at.x, -self.look_at.y, 0)
Пример #8
0
 def modelview(self):
     gl.glPushMatrix()
     try:
         gl.glMatrixMode(gl.GL_MODELVIEW)
         x, y = self.pos - self.ss
         gl.glTranslatef(-x, -y, 0)
         yield
     finally:
         gl.glPopMatrix()
Пример #9
0
 def clear_and_setup_window(self):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glMatrixMode(gl.GL_PROJECTION)  # Select The Projection Matrix
     gl.glLoadIdentity()  # Reset The Projection Matrix
     field_of_view_y = 100
     aspect_ratio = self.window.width if self.window.height == 0 else self.window.width / self.window.height
     z_clip_near = 0.1
     z_clip_far = 1000.0
     glu.gluPerspective(field_of_view_y, aspect_ratio, z_clip_near,
                        z_clip_far)
Пример #10
0
 def set_perspective(self, fovy):
     '''
     Set perspective projection
     '''
     aspect = self.width / self.height
     zNear = 0.1
     zFar = 1000.0
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     glu.gluPerspective(fovy, aspect, zNear, zFar);
Пример #11
0
        def on_resize(width, height):
            # sets the viewport
            gl.glViewport(0, 0, width, height)

            # sets the projection
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            glu.gluPerspective(60.0, width / float(height), 0.1, 100.0)

            # sets the model view
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()

            return pyglet.event.EVENT_HANDLED
Пример #12
0
    def render(self, rotate_x, rotate_y, rotate_z):
        self.clear_and_setup_window()

        # Create the "camera location" to start drawing from.
        gl.glMatrixMode(gl.GL_MODELVIEW)  # Select The Model View Matrix
        gl.glLoadIdentity()
        z_radius = 3.0 * np.max(np.abs([self.z_min, self.z_max]))
        angle = np.deg2rad(rotate_y)
        origin = z_radius * np.array([np.sin(angle), 0.0, np.cos(angle)])
        self.set_light_position([0, 0, 0])
        camera = Camera(origin=origin, up_vector=[0, 1, 0])
        camera.load_view()

        # draw the display list
        gl.glCallList(self.displist)
Пример #13
0
        def on_resize(width, height):
            # sets the viewport
            gl.glViewport(0, 0, width, height)

            # sets the projection
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            # gluPerspective(vfov, aspect, near_clipping, far_clipping)
            glu.gluPerspective(90.0, width / height, 0.1, 10000.0)

            # sets the model view
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glEnable(gl.GL_DEPTH_TEST)
            gl.glLoadIdentity()

            return pyglet.event.EVENT_HANDLED
Пример #14
0
    def setupGl(self):
        gl.glViewport(0, 0, self.width, self.height)

        # sets the projection
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.glOrtho(-2, 2, -2, 2, -2, 2)

        # sets the model view
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        gluLookAt(
            0,
            0,
            1,  #eye
            0,
            0,
            0,  #lookAt
            0,
            1,
            0)  #up axis
Пример #15
0
    def set_ortho(self, zoom):
        '''
        Screen's shortest dimension (usually height) will show exactly
        self.zoom of the world from the center of the screen to each edge,
        regardless of screen resolution, window size.
        '''

        def ortho_bounds(self, zoom, aspect):
            left = bottom = -zoom
            right = top = zoom
            if self.width > self.height:
                # landscape mode window
                bottom /= aspect
                top /= aspect
            elif self.width < self.height:
                # portrait mode window
                left *= aspect
                right *= aspect
            return left, right, bottom, top

        aspect = self.width / self.height
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluOrtho2D(*ortho_bounds(zoom, aspect))
Пример #16
0
    def draw(self):
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()
        gl.glLoadIdentity()

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        gl.glOrtho(0, self.window.width, 0, self.window.height, -1, 1)

        self.batch.draw()
        for label_id, label in self.labels.items():
            if label['visible']:
                label['label'].raw_draw()

        gl.glPopMatrix()

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPopMatrix()
Пример #17
0
    def draw(self):
        """Draw the label.

        The OpenGL state is assumed to be at default values, except
        that the MODELVIEW and PROJECTION matrices are ignored.  At
        the return of this method the matrix mode will be MODELVIEW.
        """
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()
        gl.glLoadIdentity()

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        gl.glOrtho(0, self.window.width, 0, self.window.height, -1, 1)

        self.label.draw()

        gl.glPopMatrix()

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPopMatrix()
Пример #18
0
 def __exit__(self, *args):
     gl.glMatrixMode(gl.GL_PROJECTION); gl.glPopMatrix()
     gl.glMatrixMode(gl.GL_MODELVIEW); gl.glPopMatrix()
Пример #19
0
 def __enter__(self):
     gl.glMatrixMode(gl.GL_PROJECTION); gl.glPushMatrix()
     gl.glMatrixMode(gl.GL_MODELVIEW); gl.glPushMatrix()
     self.camera.set_projection()
Пример #20
0
 def set_identity(self):
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
Пример #21
0
 def set_identity(self):
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
Пример #22
0
 def on_resize(width, height):
     gl.glMatrixMode(gl.GL_PROJECTION)
     glu.gluPerspective(90, float(width)/height, 10, 1_000)
     gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     return pyglet.event.EVENT_HANDLED