def disk(radius, **kwargs): ''' Draw a disk with given radius. ''' # Get any keyword arguments style = kwargs.get('style', 'wireframe') texture = kwargs.get('texture', None) quadric = _get_quadric() # Setup texture if specified if texture: style = 'solid' gluQuadricTexture(quadric, True) texture.bind() # Set the quadric draw style (line or fill) _set_draw_style(style) # Draw the disk gluDisk(quadric, 0, radius, DiskRes['slices'], DiskRes['loops']) # Clean up texture data if specified if texture: texture.unbind() gluQuadricTexture(quadric, False)
def draw_arrow(self, color): # Set material glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color) #glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color) #glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [1, 1, 1, 0.0]) #glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20) # Draw cylinder quad = gluNewQuadric() gluQuadricDrawStyle(quad, GLU_FILL) gluQuadricTexture(quad, True) gluQuadricNormals(quad, GLU_SMOOTH) gluCylinder(quad, self.size / 30, self.size / 30, self.size * 0.8, 20, 20) # Move to the arrowhead position glTranslatef(0, 0, self.size * 0.8) # Draw arrowhead gluQuadricDrawStyle(quad, GLU_FILL) gluQuadricTexture(quad, True) gluQuadricNormals(quad, GLU_SMOOTH) gluCylinder(quad, self.size / 15, 0, self.size * 0.2, 20, 20) # Revert to the original position glTranslatef(0, 0, -self.size * 0.8)
def sphere(radius, **kwargs): ''' Draw a sphere with the given radius.''' # Get any keyword arguments style = kwargs.get('style', 'wireframe') texture = kwargs.get('texture', None) quadric = _get_quadric() # Setup texture if specified if texture: style = 'solid' gluQuadricTexture(quadric, True) texture.bind() # Setup the quadric draw style (line or fill) _set_draw_style(style) # Draw the sphere gluSphere(quadric, radius, SphereRes['slices'], SphereRes['stacks']) # Clean up texture data if specified if texture: texture.unbind() gluQuadricTexture(quadric, False)
def draw(self, from_fixed_frame: bool = True): self.opgl_move_to_pose(from_fixed_frame) self.apply_material() # draw sphere quad = gluNewQuadric() gluQuadricDrawStyle(quad, GLU_FILL) gluQuadricTexture(quad, True) gluQuadricNormals(quad, GLU_SMOOTH) gluSphere(quad, self.radius, 20, 20)
def draw(self, from_fixed_frame: bool = True): self.opgl_move_to_pose(from_fixed_frame) self.apply_material() # draw parallelepiped quad = gluNewQuadric() gluQuadricDrawStyle(quad, GLU_FILL) gluQuadricTexture(quad, True) gluQuadricNormals(quad, GLU_SMOOTH) glScalef(self.length, self.width, self.height) glutSolidCube(1)
def cylinder(radius, height, **kwargs): """ Draw a cylinder with given radius and height.""" # Get any keyword arguments style = kwargs.get("style", "wireframe") texture = kwargs.get("texture", None) quadric = _get_quadric() # Setup texture if specified if texture: style = "solid" gluQuadricTexture(quadric, True) texture.bind() # Set the quadric draw style (line or fill) _set_draw_style(style) # Draw the bottom end of the cylinder glFrontFace(GL_CW) gluDisk(quadric, 0, radius, DiskRes["slices"], DiskRes["loops"]) glFrontFace(GL_CCW) # Draw the body of the cylinder gluCylinder(quadric, radius, radius, height, CylinderRes["slices"], CylinderRes["stacks"]) # Draw the top end of the cylinder glPushMatrix() translateZ(height) gluDisk(quadric, 0, radius, DiskRes["slices"], DiskRes["loops"]) glPopMatrix() # Clean up texture data if specified if texture: texture.unbind() gluQuadricTexture(quadric, False)