def on_draw(self): self.clear() self.set_3d() glColor3d(1, 1, 1) self.model.batch.draw() self.set_2d() self.draw_label() self.draw_reticle()
def on_draw(self): self.joystick.update() self.clear() self.set_3d() glColor3d(1, 1, 1) self.model.batch.draw() self.set_2d() self.draw_label()
def on_draw(self, size): self.set_3d(size) GL.glColor3d(1, 1, 1) self.world.start_shader() self.world.batch.draw() self.world.stop_shader() self.draw_focused_block() self.set_2d(size) self.draw_labels() self.draw_reticle()
def on_draw(self, size): self.set_3d(size) GL.glColor3d(1, 1, 1) # self.world.start_shader() self.world.batch.draw() self.world.stop_shader() self.draw_focused_block() self.set_2d(size) self.draw_labels() self.draw_reticle()
def on_draw(self): """ Called by pygl.glet to draw the canvas. """ self.clear() self.set_3d() gl.glColor3d(1, 1, 1) self.model.batch.draw() self.draw_focused_block() self.set_2d() self.draw_label() self.draw_reticle()
def draw_focused_block(self): """Draw black edges around the block that is currently under the crosshairs. """ block = self.player.hit(self.world.area.blocks)[0] if block: x, y, z = block vertex_data = cube_vertices(x, y, z, 0.51) GL.glColor3d(0, 0, 0) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) pyglet.graphics.draw(24, GL.GL_QUADS, ('v3f/static', vertex_data)) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
def on_draw(self): # Clears anything. self.clear() # sets the 3d viewport. self.set3d() gl.glColor3d(1, 1, 1) # Draws the main batch. self.model.draw() # Then it draws the remaining things, the info label and reticle. self.set2d() self.draw_label() self.draw_reticle()
def on_draw(self): """ Called by pyglet to draw the canvas. """ self.clear() self.set_3d() gl.glColor3d(1, 1, 1) self.model.draw(self.position,self.get_frustum_circle()) self.draw_focused_block() self.set_2d() self.draw_label() self.draw_reticle() self.draw_inventory_item()
def on_draw(self): """ Called by pyglet to draw the canvas. """ self.clear() self.set_3d() gl.glColor3d(1, 1, 1) self.model.draw(self.position, self.get_frustum_circle()) self.draw_focused_block() self.set_2d() self.draw_label() self.draw_reticle() self.draw_inventory_item()
def draw_circle(x, y, radius): iterations = 20 s = math.sin(2 * math.pi / iterations) c = math.cos(2 * math.pi / iterations) dx, dy = radius, 0 gl.glBegin(gl.GL_LINE_STRIP) gl.glColor3d(255, 0, 0) for i in range(iterations + 1): gl.glVertex2f(x + dx, y + dy) dx, dy = (dx * c - dy * s), (dy * c + dx * s) gl.glEnd()
def draw_focused_block(self): """ Draw black edges around the block that is currently under the crosshairs. """ vector = self.get_sight_vector() block = self.model.hit_test(self.position, vector)[0] if block: x, y, z = block vertex_data = cube_vertices(x, y, z, 0.51) gl.glColor3d(0, 0, 0) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) pyglet.graphics.draw(24, gl.GL_QUADS, ('v3f/static', vertex_data)) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
def draw_rectangle(position, size, color=(.0, .0, .0)): x, y = position dx, dy = size if len(color) == 3: gl.glColor3d(*color) else: gl.glColor4d(*color) gl.glBegin(gl.GL_TRIANGLES) gl.glVertex2f(x, y + dy) gl.glVertex2f(x, y) gl.glVertex2f(x + dx, y + dy) gl.glVertex2f(x + dx, y + dy) gl.glVertex2f(x, y) gl.glVertex2f(x + dx, y) gl.glEnd()
def view(self, drone_state, dt, expected_velocity=None): # NOTE: because sim coord is (x => left, y => inner, z => up), # gl coord is (x => left, y => up, z => outer), # we remap gl-y to sim-z, gl-z to sim-y, then reverse sim-y # In this way, we can transform gl coord to sim coord. # Here use `-drone_state[y]'. self.position = (drone_state['x'] + self.x_offset, -drone_state['y'] + self.y_offset, drone_state['z'] + self.z_offset) rot = (drone_state['yaw'], drone_state['pitch'], drone_state['roll']) if self.task == 'velocity_control': assert expected_velocity is not None ev_x, ev_y, ev_z = expected_velocity expected_velocity = np.array([ev_x, ev_z, ev_y]) velocity = np.array([ drone_state['g_v_x'], drone_state['g_v_z'], drone_state['g_v_y'] ]) cid = abs(int(drone_state['z'] / 0.1)) % len(self.colors) self._gl_set_background(self.colors[cid]) # Actually, `dt` does not work now, as we update the state in env.py self.update(dt) self.clear() self._setup_3d() gl.glColor3d(1, 1, 1) self.internal_map.batch.draw() self.internal_map.show_drone(self.position, rot) if self.task == 'velocity_control': self.internal_map.show_velocity(self.position, velocity, expected_velocity) self._setup_2d() self._draw_label() self.dispatch_events() self.flip() time.sleep(dt)
def view(self, drone_state, dt, expected_velocity=None): self.position = (drone_state['x'], drone_state['y'], drone_state['z']) rot = (drone_state['yaw'], drone_state['pitch'], drone_state['roll']) if self.task == 'velocity_control': assert expected_velocity is not None ev_x, ev_y, ev_z = expected_velocity expected_velocity = np.array([ev_x, ev_z, ev_y]) velocity = np.array([ drone_state['g_v_x'], drone_state['g_v_z'], drone_state['g_v_y'] ]) cid = abs(int(drone_state['z'] / 0.1)) % len(self.colors) self._gl_set_background(self.colors[cid]) # Actually, `dt` does not work now, as we update the state in env.py self.update(dt) self.clear() self._setup_3d() gl.glColor3d(1, 1, 1) self.internal_map.batch.draw() self.internal_map.show_drone(self.position, rot) if self.task == 'velocity_control': self.internal_map.show_velocity(self.position, velocity, expected_velocity) self._setup_2d() self._draw_label() self.dispatch_events() self.flip() time.sleep(dt)
def draw_reticle(self): # hårkors glColor3d(0, 0, 0) self.reticle.draw(GL_LINES)
def draw_line(f, t, color=(.0, .0, .0)): gl.glColor3d(*color) gl.glBegin(gl.GL_LINES) gl.glVertex2f(*f) gl.glVertex2f(*t) gl.glEnd()
def draw_reticle(self): gl.glColor3d(0, 0, 0) self.reticle.draw(gl.GL_LINES)
def draw_reticle(self): """Draw the crosshairs in the center of the screen.""" GL.glColor3d(0, 0, 0) self.reticle.draw(GL.GL_LINES)