コード例 #1
0
ファイル: modelview.py プロジェクト: mjs/pyweek11-cube
 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
ファイル: mainwindow.py プロジェクト: ceronman/prisionescape
 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 on_draw():
     window.clear()
     gl.glLoadIdentity()
     gl.glTranslated(self.x, self.y, self.z)
     gl.glRotatef(self.rx, 1, 0, 0)
     gl.glRotatef(self.ry, 0, 1, 0)
     gl.glRotatef(self.rz, 0, 0, 1)
     visualization.draw(self.mesh)
コード例 #7
0
ファイル: modelview.py プロジェクト: mjs/pyweek11-cube
 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)
コード例 #8
0
ファイル: camera.py プロジェクト: fathat/a-murder-of-crows
 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)
コード例 #9
0
ファイル: renderer.py プロジェクト: bingjeff/trex-gym
 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
ファイル: Scene.py プロジェクト: yannicksuter/faceter
    def draw(self):
        gl.glLoadIdentity()
        gl.glTranslatef(self.x, self.y, self.z)
        gl.glRotatef(self.rx, 1, 0, 0)
        gl.glRotatef(self.ry, 0, 1, 0)
        gl.glRotatef(self.rz, 0, 0, 1)

        # sets the color
        gl.glColor4f(*self.color)

        for facet in self.facets:
            facet.draw()
コード例 #12
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
コード例 #13
0
ファイル: renderer.py プロジェクト: bingjeff/trex-gym
    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)
コード例 #14
0
ファイル: SwarmRender.py プロジェクト: ogratton/Murmurations
        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
コード例 #15
0
ファイル: SwarmRender.py プロジェクト: ogratton/Murmurations
    def draw(self):
        # clears the screen with the background color
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        gl.glClear(gl.GL_DEPTH_BUFFER_BIT)

        gl.glLoadIdentity()

        # # sets the position for the camera
        gl.glTranslatef(self.x, self.y, self.z)

        # sets the rotation for the camera
        gl.glRotatef(self.rx, 1, 0, 0)
        gl.glRotatef(self.ry, 0, 1, 0)
        gl.glRotatef(self.rz, 0, 0, 1)

        # self.draw_axes()

        for box in self.boxes:
            self.render_model(box, fill=False)

        # TODO Note: won't account for changing number of boids if that is ever implemented
        for i, (boids_m, atts) in enumerate(self.swarm_models):
            swarm = self.swarms[i]
            for j, boid_m in enumerate(boids_m):

                # experimental: invert colour if feeding
                # if swarm.boids[j].feeding:
                #     boid_m.color = invert_colour(boid_m.color)

                new_loc = list(swarm.boids[j].location)[:3]
                boid_m.x, boid_m.y, boid_m.z = new_loc

                # boid direction based on velocity
                new_vel = list(normalise(swarm.boids[j].velocity[:3]))
                # TODO completely wrong and also stupid but seems to be good enough if you don't look too hard
                # boid_m.rx = -90-math.degrees(math.asin(new_vel[2]/math.sqrt(new_vel[1]**2 + new_vel[2]**2)))
                boid_m.ry = (90-math.degrees(math.asin(new_vel[0]/math.sqrt(new_vel[2]**2 + new_vel[0]**2))))
                boid_m.rz = -(90-math.degrees(math.asin(new_vel[1]/math.sqrt(new_vel[0]**2 + new_vel[1]**2))))

                self.render_model(boid_m)

            for j, att in enumerate(atts):
                new_att = list(swarm.attractors[j].location)[:3]
                att.x, att.y, att.z = new_att
                if swarm.attractors[j].is_active:
                    self.render_model(att, frame=True)
コード例 #16
0
    def draw(self):
        # clears the screen with the background color
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        gl.glClear(gl.GL_DEPTH_BUFFER_BIT)

        gl.glLoadIdentity()

        # # sets the position
        gl.glTranslatef(self.x, self.y, self.z)

        # sets the rotation
        gl.glRotatef(self.rx, 1, 0, 0)
        gl.glRotatef(self.ry, 0, 1, 0)
        gl.glRotatef(self.rz, 0, 0, 1)

        self.draw_ground_plane()

        for model in self.models:
            self._model_render(model)
コード例 #17
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()
コード例 #18
0
ファイル: Graphics.py プロジェクト: Minoflaz/Chess
    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
コード例 #19
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()
コード例 #20
0
    def draw(self):
        # clears the screen with the background color
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        gl.glClear(gl.GL_DEPTH_BUFFER_BIT)

        gl.glLoadIdentity()

        # # sets the position for the camera
        gl.glTranslatef(self.x, self.y, self.z)

        # sets the rotation for the camera
        gl.glRotatef(self.rx, 1, 0, 0)
        gl.glRotatef(self.ry, 0, 1, 0)
        gl.glRotatef(self.rz, 0, 0, 1)

        self.render_model(self.box_model, fill=False)

        for colour_model in self.colour_models:
            self.render_model(colour_model, frame=False)

        for rc_model in self.rand_col_models:
            self.render_model(rc_model, frame=False)
コード例 #21
0
    def draw(self):
        gl.glLoadIdentity()

        # sets the position
        gl.glTranslatef(self.x, self.y, self.z)

        # sets the rotation
        gl.glRotatef(self.rx, 1, 0, 0)
        gl.glRotatef(self.ry, 0, 1, 0)
        gl.glRotatef(self.rz, 0, 0, 1)

        # sets the color
        gl.glColor4f(*self.color)

        # draws the quads
        pyglet.graphics.draw_indexed(
            len(self.vertices) / 3, gl.GL_QUADS, self.quad_indices,
            ('v3f', self.vertices))

        # draws the triangles
        pyglet.graphics.draw_indexed(
            len(self.vertices) / 3, gl.GL_TRIANGLES, self.triangle_indices,
            ('v3f', self.vertices))
コード例 #22
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))
コード例 #23
0
ファイル: camera.py プロジェクト: andrewrk/MonsterMechanics
 def set_matrix(self):
     gl.glLoadIdentity()
     gl.glTranslatef(self.viewport_offset.x, self.viewport_offset.y, 0)
     x, y = self.center
     gl.glScalef(self.scale, self.scale, 1)
     gl.glTranslatef(int(-x + 0.5), int(-y + 0.5), 0)
コード例 #24
0
ファイル: modelview.py プロジェクト: mjs/pyweek11-cube
 def set_identity(self):
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
コード例 #25
0
ファイル: modelview.py プロジェクト: mjs/pyweek11-cube
 def set_identity(self):
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()