def circle(pos, radius, color=(1.0,1.0,1.0), alpha=1.0,segments=6): """ Draws a circle with gluDisk :param pos: center of the circle :type pos: 2-float tuple :param radius: radius of the circle :type radius: float :param color: the color in [0..1] range :type color: 3-float tuple :param alpha: the alpha value in [0..1] range :param segments: number of segments :type segments: int """ glDisable(GL_TEXTURE_2D) c = gluNewQuadric() glColor4f(color[0], color[1], color[2], alpha) glPushMatrix() glTranslatef(pos[0], pos[1], 0) gluDisk(c, 0, radius, segments, 1) glPopMatrix() glColor4f(1.0,1.0,1.0,1.0) glEnable(GL_TEXTURE_2D)
def __init__(self, x, y, z=50, radius=1, color=(0, 0, 1, 0)): super(Sphere, self).__init__(color) self.x = x # Need to swap y and z (y is up) self.y = z self.z = y self.radius = radius self.sphere = gl.gluNewQuadric()
def draw_shape_circle(self, circle, position): glPushMatrix() center = position + circle.center # We have no need for unit perfect circle, as we will still have a # projection in the game. # draw_circle(center.x, center.y, circle.radius, iterations=32) glTranslatef(center.x, center.y, 0) sphere = gluNewQuadric() gluSphere(sphere, circle.radius, 32, 5) glPopMatrix()
def render_mesh(self, segment: bool, enable_leds: bool): self.mesh.render(segment=segment) if enable_leds and self.kind == MapFormat1Constants.KIND_DUCKIEBOT: # attrs = # gl.glPushAttrib(gl.GL_ALL_ATTRIB_BITS) s_main = 0.01 # 1 cm sphere # LIGHT_MULT_MAIN = 10 s_halo = 0.04 height = 0.05 positions = { "front_left": [0.1, -0.05, height], "front_right": [0.1, +0.05, height], "center": [0.1, +0.0, height], "back_left": [-0.1, -0.05, height], "back_right": [-0.1, +0.05, height], } if isinstance(self, DuckiebotObj): colors = self.leds_color else: colors = { "center": (0, 0, 1), "front_left": (0, 0, 1), "front_right": (0, 0, 1), "back_left": (0, 0, 1), "back_right": (0, 0, 1), } for light_name, (px, py, pz) in positions.items(): color = np.clip(colors[light_name], 0, +1) color_intensity = float(np.mean(color)) gl.glPushMatrix() gl.glTranslatef(px, pz, py) gl.glEnable(gl.GL_BLEND) # gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE) sphere = gluNewQuadric() gl.glColor4f(color[0], color[1], color[2], 1.0) gluSphere(sphere, s_main, 10, 10) gl.glColor4f(color[0], color[1], color[2], 0.2) s_halo_effective = color_intensity * s_halo gluSphere(sphere, s_halo_effective, 10, 10) gl.glColor4f(1.0, 1.0, 1.0, 1.0) gl.glBlendFunc(gl.GL_ONE, gl.GL_ZERO) gl.glDisable(gl.GL_BLEND) gl.glPopMatrix()
def draw(self): """ Draws a circle. """ self.before_draw() sphere = gl.gluNewQuadric() gl.glTranslatef(self.x, self.y, -10) gl.gluSphere(sphere, self.radius, 25, 25) # Restore the transformation matrix gl.glPopMatrix()
def __init__(self, x, y, z=0, color=(0., 0., 0., 1.), stroke=0, rotation=0): # try : # self.rect # except AttributeError: # self.rect = Rect(x,y,1,1) # this inits x,y and loc as well self.visible = 1 # self.z = z self.rotation = rotation self.stroke = stroke self.color = color self.q = gl.gluNewQuadric()
def on_draw(): # Reset # ===== gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() # Camera view # =========== gl.gluPerspective(70, window.width / window.height, 1, 1000) gl.gluLookAt(2, 1, 1, 0, 0, 0, 0, 0, 1) # Draw the cube # ============= gl.glBegin(gl.GL_QUADS) # Left face gl.glColor3f(1.0, 0, 0) gl.glVertex3f(1, -1, -1) gl.glVertex3f(1, -1, 1) gl.glVertex3f(-1, -1, 1) gl.glVertex3f(-1, -1, -1) # Right face gl.glColor3f(0, 1.0, 0) gl.glVertex3f(-1, -1, 1) gl.glVertex3f(-1, 1, 1) gl.glVertex3f(-1, 1, -1) gl.glVertex3f(-1, -1, -1) #Bottom face gl.glColor3f(0, 0, 1.0) gl.glVertex3f(1, -1, -1) gl.glVertex3f(-1, -1, -1) gl.glVertex3f(-1, 1, -1) gl.glVertex3f(1, 1, -1) gl.glEnd() gl.glColor3f(0, 0, 0) pointer = gl.gluNewQuadric() gl.gluSphere(pointer, 0.1, 20, 20)