def drawBallAndStick(self, r_ball = 0.4, r_stick = 0.1): res = self.quality * 6 quad = gluNewQuadric() glNewList(1,GL_COMPILE) for i in range(self.mol.natoms): glPushMatrix() # set atom color r,g,b = self.mol.col[i] glColor3f(r,g,b) # translate to atom position x,y,z = self.mol.pos[i] glTranslatef(x,y,z) # draw the atom gluSphere(quad, r_ball*self.mol.rad[i], res, res) glPopMatrix() for i,c in enumerate(self.mol.con): m = c[0] n = c[1] glPushMatrix() # set bond color r,g,b = self.mol.col[m] glColor3f(r,g,b) # translate to atom position x,y,z = self.mol.pos[m] glTranslatef(x,y,z) # draw the bond v = self.mol.pos[n] - self.mol.pos[m] angle = math.acos(numpy.dot([0.0,0.0,1.0], v)/self.mol.dist[i])*180./math.pi x,y,z = numpy.cross([0.0,0.0,1.0], v) glRotatef(angle,x,y,z) h = self.mol.dist[i] * self.mol.rad[m] / (self.mol.rad[m] + self.mol.rad[n]) gluCylinder(quad, r_stick, r_stick, h, res, res) glPopMatrix() glEndList()
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 make_sphere(): """create ball's rend function list""" glNewList(G_OBJ_SPHERE, GL_COMPILE) quad = gluNewQuadric() gluSphere(quad, 0.5, 30, 30) gluDeleteQuadric(quad) glEndList()
def draw_light_source(self): glColor3f(1.0, 1.0, 1.0) # 15 is radius of the sphere that light source around self.light_source_position = [ 15 * sin(self.theta_light_angle * pi / 180) * sin(self.phi_light_angle * pi / 180), 15 * cos(self.theta_light_angle * pi / 180), 15 * sin(self.theta_light_angle * pi / 180) * cos(self.phi_light_angle * pi / 180) ] glTranslate(self.light_source_position[0], self.light_source_position[1], self.light_source_position[2]) # set light source position glLightfv(GL_LIGHT0, GL_POSITION, [*self.light_source_position, 1]) # set light color glLightfv(GL_LIGHT0, GL_DIFFUSE, self.light_color) # set light intensity glLightfv(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.7) glLightfv(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0001) # turning the rays of light so that the back of the ball is shaded gl_q = gluNewQuadric() gluQuadricOrientation(gl_q, GLU_INSIDE) # draw visual envelope (ball) gluSphere(gl_q, 1, 20, 20) glLoadIdentity()
def make_sphere(): """ 创建球形的渲染函数列表 """ glNewList(G_OBJ_SPHERE, GL_COMPILE) quad = gluNewQuadric() gluSphere(quad, 0.5, 30, 30) gluDeleteQuadric(quad) glEndList()
def paint(self): if self.quad is None: self.quad = gluNewQuadric() glPushMatrix() glColor(self.color.red, self.color.green, self.color.blue) glTranslate(self.center.x, self.center.y, self.center.z) gluSphere(self.quad, self.radius, 25, 25) glPopMatrix()
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_sphere(coords, radius, color_s=BLUE): quad: gluNewQuadric = gluNewQuadric() gluQuadricDrawStyle(quad, GLU_LINE) glColor3f(color_s[0], color_s[1], color_s[2]) glPushMatrix() glTranslatef(coords[0], coords[1], coords[2]) gluSphere(quad, radius, 12, 12) glPopMatrix()
def draw_led(self, x, y, color): glPushMatrix() if color < 0: glColor3f(*self.color_led_red) else: glColor3f(*self.color_led_green) glTranslatef(x, 0.1, -y) glRotatef(-90, 1.0, 0.0, 0.0) obj = gluNewQuadric() gluSphere(obj, 0.15, 10, 10) glPopMatrix()
def draw(self): #draw ball glPushMatrix() objects.Sphere.draw(self) glPopMatrix() #draw shadow shadowPosition = self.body.getPosition() glTranslatef(shadowPosition[0], 0.05, shadowPosition[2]) glColor4f(0.2, 0.2, 0.2, 0.2) glScalef(1.0, 0.0, 1.0) glDisable(GL_LIGHTING) gluSphere(self.q, self.geom.getRadius(), 32, 32) glEnable(GL_LIGHTING)
def prepDraw(self): glNewList(self.dl,GL_COMPILE) c = self.corners for h in c: glPushMatrix( ) glTranslatef(h.x,h.y,h.z) q = gluNewQuadric() gluSphere( q, GLdouble(0.45), GLint(10), GLint(10) ) glPopMatrix( ) glBegin(GL_QUADS) glVertex3fv(adaptVec(c[0])) glVertex3fv(adaptVec(c[2])) glVertex3fv(adaptVec(c[6])) glVertex3fv(adaptVec(c[4])) glVertex3fv(adaptVec(c[1])) glVertex3fv(adaptVec(c[3])) glVertex3fv(adaptVec(c[7])) glVertex3fv(adaptVec(c[5])) glVertex3fv(adaptVec(c[0])) glVertex3fv(adaptVec(c[1])) glVertex3fv(adaptVec(c[3])) glVertex3fv(adaptVec(c[2])) glVertex3fv(adaptVec(c[2])) glVertex3fv(adaptVec(c[3])) glVertex3fv(adaptVec(c[7])) glVertex3fv(adaptVec(c[6])) glVertex3fv(adaptVec(c[7])) glVertex3fv(adaptVec(c[6])) glVertex3fv(adaptVec(c[4])) glVertex3fv(adaptVec(c[5])) glVertex3fv(adaptVec(c[0])) glVertex3fv(adaptVec(c[1])) glVertex3fv(adaptVec(c[5])) glVertex3fv(adaptVec(c[4])) glEnd() glEndList()
def prepDraw(self): glNewList(self.dl, GL_COMPILE) c = self.corners for h in c: glPushMatrix() glTranslatef(h.x, h.y, h.z) q = gluNewQuadric() gluSphere(q, GLdouble(0.45), GLint(10), GLint(10)) glPopMatrix() glBegin(GL_QUADS) glVertex3fv(adaptVec(c[0])) glVertex3fv(adaptVec(c[2])) glVertex3fv(adaptVec(c[6])) glVertex3fv(adaptVec(c[4])) glVertex3fv(adaptVec(c[1])) glVertex3fv(adaptVec(c[3])) glVertex3fv(adaptVec(c[7])) glVertex3fv(adaptVec(c[5])) glVertex3fv(adaptVec(c[0])) glVertex3fv(adaptVec(c[1])) glVertex3fv(adaptVec(c[3])) glVertex3fv(adaptVec(c[2])) glVertex3fv(adaptVec(c[2])) glVertex3fv(adaptVec(c[3])) glVertex3fv(adaptVec(c[7])) glVertex3fv(adaptVec(c[6])) glVertex3fv(adaptVec(c[7])) glVertex3fv(adaptVec(c[6])) glVertex3fv(adaptVec(c[4])) glVertex3fv(adaptVec(c[5])) glVertex3fv(adaptVec(c[0])) glVertex3fv(adaptVec(c[1])) glVertex3fv(adaptVec(c[5])) glVertex3fv(adaptVec(c[4])) glEnd() glEndList()
def drawBallAndStick(self, r_ball=0.4, r_stick=0.1): res = self.quality * 6 quad = gluNewQuadric() glNewList(1, GL_COMPILE) for i in range(self.mol.natoms): glPushMatrix() # set atom color r, g, b = self.mol.col[i] glColor3f(r, g, b) # translate to atom position x, y, z = self.mol.pos[i] glTranslatef(x, y, z) # draw the atom gluSphere(quad, r_ball * self.mol.rad[i], res, res) glPopMatrix() for i, c in enumerate(self.mol.con): m = c[0] n = c[1] glPushMatrix() # set bond color r, g, b = self.mol.col[m] glColor3f(r, g, b) # translate to atom position x, y, z = self.mol.pos[m] glTranslatef(x, y, z) # draw the bond v = self.mol.pos[n] - self.mol.pos[m] angle = math.acos( numpy.dot([0.0, 0.0, 1.0], v) / self.mol.dist[i]) * 180. / math.pi x, y, z = numpy.cross([0.0, 0.0, 1.0], v) glRotatef(angle, x, y, z) h = self.mol.dist[i] * self.mol.rad[m] / (self.mol.rad[m] + self.mol.rad[n]) gluCylinder(quad, r_stick, r_stick, h, res, res) glPopMatrix() glEndList()
def render(self): o = self.motion.getWorldTransform().getOrigin() glColor(*self.color) glTranslate(o.x, o.y, o.z) gluSphere(self.quad, self.radius, 25, 25)
def make_sphere(n=30): glNewList(G_OBJ_SPHERE, GL_COMPILE) quad = gluNewQuadric() gluSphere(quad, 1.0, n, n) gluDeleteQuadric(quad) glEndList()
def make_sphere(): glNewList(G_OBJ_SPHERE, GL_COMPILE) quad = gluNewQuadric() gluSphere(quad, 0.5, 30, 30) gluDeleteQuadric(quad) glEndList()
def draw_sphere(self, radius, quality): gluSphere(self.quadric, radius, quality, quality / 2)
def __init__(self, mesh): self.outline_color = (1, 1, 1) vertices = mesh.vertex_list.getVertices() minV = Vector3() maxV = Vector3() vertices.sort(lambda x, y: cmp(y.x, x.x)) minV.x = vertices[0].x maxV.x = vertices[-1].x vertices.sort(lambda x, y: cmp(y.y, x.y)) minV.y = vertices[0].y maxV.y = vertices[-1].y vertices.sort(lambda x, y: cmp(y.z, x.z)) minV.z = vertices[0].z maxV.z = vertices[-1].z self.points = [] for i in range(8): self.points.append(Vector3()) for i in range(2): for j in range(2): self.points[int("%d%d%d" % (0, i, j), 2)].x = minV.x self.points[int("%d%d%d" % (1, i, j), 2)].x = maxV.x self.points[int("%d%d%d" % (i, 0, j), 2)].y = minV.y self.points[int("%d%d%d" % (i, 1, j), 2)].y = maxV.y self.points[int("%d%d%d" % (i, j, 0), 2)].z = minV.z self.points[int("%d%d%d" % (i, j, 1), 2)].z = maxV.z self.center = Vector3() for p in self.points: self.center += p self.center /= float(8) self.dl = glGenLists(1) glNewList(self.dl, GL_COMPILE) glLineWidth(5) c = self.outline_color glColor4f(c[0], c[1], c[2], 0.2) glBegin(GL_LINE_STRIP) for v in self.points: glVertex(v()) glEnd() c = self.points glBegin(GL_LINES) glVertex(c[0]()) glVertex(c[2]()) glVertex(c[6]()) glVertex(c[4]()) glVertex(c[1]()) glVertex(c[3]()) glVertex(c[7]()) glVertex(c[5]()) glVertex(c[0]()) glVertex(c[1]()) glVertex(c[3]()) glVertex(c[2]()) glVertex(c[2]()) glVertex(c[3]()) glVertex(c[7]()) glVertex(c[6]()) glVertex(c[7]()) glVertex(c[6]()) glVertex(c[4]()) glVertex(c[5]()) glVertex(c[0]()) glVertex(c[1]()) glVertex(c[5]()) glVertex(c[4]()) glEnd() glPushMatrix() glTranslatef(self.center.x, self.center.y, self.center.z) q = gluNewQuadric() gluSphere(q, GLdouble(0.25), GLint(10), GLint(10)) glPopMatrix() glEndList()
def draw_sphere(self, radius, quality): gluSphere(self.quadric, radius, quality, quality/2)