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()
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()
def draw(self): gl.glPushMatrix() gl.glTranslatef(int(-self.x + window.width / 2), int(-self.y + window.height / 2), 0) for drawable in self.drawables: drawable.draw() self.drawLightBuffer() glPopMatrix()
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)
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()
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()
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)
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)
def draw(self): self.moneylabel.document.text = 'Money: $%d' % self.money self.weightlabel.document.text = 'Weight: %dkg' % self.squid.total_weight() cap = self.squid.fuel_capacity() if cap: self.fuellabel.document.text = 'Fuel Capacity: %dkg' % cap else: self.fuellabel.document.text = 'Fuel Capacity: -' tr = v(SCREEN_SIZE) pos = tr - self.tile_size - v(10, 10) gl.glPushMatrix() gl.glTranslatef(pos.x, pos.y + self.scroll, 0) for item in self.items: item.draw() gl.glTranslatef(0, -self.tile_size.y - 10, 0) gl.glPopMatrix() self.moneylabel.draw() self.weightlabel.draw() self.fuellabel.draw() self.startbutton.draw()
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)
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()
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))
def draw_world(self): gl.glEnableClientState(gl.GL_NORMAL_ARRAY) self.projection.set_perspective(45) self.modelview.set_world() for item in self.world: if not hasattr(item, 'shape'): continue glyph = item.glyph gl.glPushMatrix() if hasattr(item, 'position'): gl.glTranslatef(*item.position) # TODO: item orientation gl.glVertexPointer( Glyph.DIMENSIONS, gl.GL_FLOAT, 0, glyph.glvertices) gl.glColorPointer( Color.NUM_COMPONENTS, gl.GL_UNSIGNED_BYTE, 0, glyph.glcolors) gl.glNormalPointer(gl.GL_FLOAT, 0, glyph.glnormals) gl.glDrawElements( gl.GL_TRIANGLES, len(glyph.glindices), type_to_enum[glyph.glindex_type], glyph.glindices) gl.glPopMatrix()
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)
def end(self): gl.glScalef(1 / self._zoom, 1 / self._zoom, 1) gl.glTranslatef(self.offset_x * self._zoom, self.offset_y * self._zoom, 0)
def begin(self): gl.glTranslatef(-self.offset_x * self._zoom, -self.offset_y * self._zoom, 0) gl.glScalef(self._zoom, self._zoom, 1)