コード例 #1
0
ファイル: SwarmRender.py プロジェクト: ogratton/Murmurations
    def draw_model(self, model):

        # gl.glLoadIdentity()
        gl.glPushMatrix()

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

        # sets the position
        gl.glTranslatef(model.x - self.cx, model.y - self.cy, model.z - self.cz)

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

        # sets the scale
        gl.glScalef(model.scale, model.scale, model.scale)

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

        # draws the triangles
        pyglet.graphics.draw_indexed(len(model.vertices) // 3, gl.GL_TRIANGLES, model.triangle_indices,
                                     ('v3f', model.vertices))

        gl.glPopMatrix()
コード例 #2
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)
コード例 #3
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()
コード例 #4
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)
コード例 #5
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)
コード例 #6
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)
コード例 #7
0
    def draw(self):

        gl.glPushMatrix()
        # 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)

        # draw primitives with batch or vertex_list
        #        batch=pyglet.graphics.Batch();
        #        vertex_list=batch.add(len(self.vertices) // 3,gl.GL_QUADS,None,('v3f', self.vertices));
        #        batch.draw();

        #        # draw by texture rendering
        if len(self.text_indices) > 0:
            gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
            print("text mode!")
            self.vertex_list.draw(gl.GL_TRIANGLES)

        # draw by wire-frame mode
        else:
            # sets wire-frame mode
            gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)
            # 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))
        gl.glPopMatrix()
コード例 #8
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))