Пример #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 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
 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
 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
 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 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
    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
        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
    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
    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
 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
 def set_identity(self):
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
Пример #25
0
 def set_identity(self):
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()