def draw(self, coordslinear, index): """ tell the gui how to represent your system using openGL objects Parameters ---------- coords : array index : int we can have more than one molecule on the screen at one time. index tells which one to draw. They are viewed at the same time, so they should be visually distinct, e.g. different colors. accepted values are 1 or 2 """ # index = 1 or 2 from OpenGL import GL,GLUT coords = coordslinear.reshape(coordslinear.size/3, 3) com=np.mean(coords, axis=0) size = 0.5 if index == 1: color = [0.65, 0.0, 0.0, 1.] else: color = [0.00, 0.65, 0., 1.] GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color) for i,xx in enumerate(coords): if i == self.ntypeA: size *= 0.88 #this should be dependent on lj parameters if index == 1: color = [0.25, 0.00, 0., 1.] else: color = [0.00, 0.25, 0., 1.] GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color) x=xx-com GL.glPushMatrix() GL.glTranslate(x[0],x[1],x[2]) GLUT.glutSolidSphere(size,30,30) GL.glPopMatrix()
def draw_sphere(xyz, radius=0.5, color=None): if color is not None: change_color(color) GL.glPushMatrix() GL.glTranslate(xyz[0], xyz[1], xyz[2]) GLUT.glutSolidSphere(radius, 30, 30) GL.glPopMatrix()
def draw(self, coordslinear, index, subtract_com=True): # pragma: no cover """ tell the gui how to represent your system using openGL objects Parameters ---------- coords : array index : int we can have more than one molecule on the screen at one time. index tells which one to draw. They are viewed at the same time, so they should be visually distinct, e.g. different colors. accepted values are 1 or 2 """ from OpenGL import GL, GLUT coords = coordslinear.reshape([-1, 3]) if subtract_com: com = np.mean(coords, axis=0) else: com = np.zeros(3) size = 0.5 * self.r0 for xx in coords: x = xx - com GL.glPushMatrix() GL.glTranslate(x[0], x[1], x[2]) GLUT.glutSolidSphere(size, 30, 30) GL.glPopMatrix()
def draw(self, rbcoords, index): from OpenGL import GL,GLUT coords = self.aasystem.to_atomistic(rbcoords) com=np.mean(coords, axis=0) i=0 for xx in coords: if(i%3 == 0): color = [1.0, 0.0, 0.0] radius = 0.35 else: color = [1.0, 1.0, 1.0] radius = 0.3 if index == 2: color = [0.5, 1.0, .5] i+=1 GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color) x=xx-com GL.glPushMatrix() GL.glTranslate(x[0],x[1],x[2]) GLUT.glutSolidSphere(radius,30,30) GL.glPopMatrix() for i in xrange(self.nrigid): color = [1.0, 0.0, 0.0] if index == 2: color = [0.5, 1.0, .5] GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color) self.drawCylinder(coords[3*i]-com, coords[3*i+1]-com) self.drawCylinder(coords[3*i]-com, coords[3*i+2]-com)
def draw(self): gl.glPushMatrix() # get global points point1 = self.body1.convert_to_global(self.__contact_point1) point2 = self.body2.convert_to_global(self.__contact_point2) current_length = la.norm(point1 - point2) # draw contact points as spheres gl.glColor3f(self.color[0], self.color[1], self.color[2]) gl.glPushMatrix() gl.glTranslatef(point1[0], point1[1], point1[2]) glut.glutSolidSphere(0.2, 8, 8) gl.glPopMatrix() gl.glPushMatrix() gl.glTranslatef(point2[0], point2[1], point2[2]) glut.glutSolidSphere(0.2, 8, 8) gl.glPopMatrix() # draw a line between them if current_length < self.length: gl.glColor3f(0.0, 1.0, 0.0) else: gl.glColor3f(1.0, 0.0, 0.0) gl.glBegin(gl.GL_LINES) gl.glVertex3f(point1[0], point1[1], point1[2]) gl.glVertex3f(point2[0], point2[1], point2[2]) gl.glEnd() gl.glPopMatrix()
def display_sphere(self): GL.glPointSize(1); GL.glLineWidth(0.5); GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, [1, 1, 1, 0.1]) GLUT.glutWireSphere(0.97, 20, 20) GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, [1, 1, 1, 0.5]) GLUT.glutSolidSphere(0.98, 20, 20)
def draw(self, coordsl, index): from OpenGL import GL,GLUT coords=coordsl.reshape(coordsl.size/3,3) com=np.mean(coords, axis=0) # draw atoms as spheres for i in self.potential.prmtop.topology.atoms(): atomElem = i.name[0] atomNum = i.index x = coords[atomNum] - com GL.glPushMatrix() GL.glTranslate(x[0],x[1],x[2]) col = elements[atomElem]['color'] if index == 2: col = [0.5, 1.0, .5] # scaling down the radius by factor of 5, else the spheres fuse into one another rad = elements[atomElem]['radius']/5 GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, col) GLUT.glutSolidSphere(rad,30,30) GL.glPopMatrix() # draw bonds for atomPairs in self.potential.prmtop.topology.bonds(): # note that atom numbers in topology start at 0 if self.OpenMMVer == 5: xyz1 = coords[atomPairs[0].index] - com xyz2 = coords[atomPairs[1].index] - com else: xyz1 = coords[atomPairs[0]] - com xyz2 = coords[atomPairs[1]] - com self.drawCylinder(xyz1, xyz2)
def draw(self, coordslinear, index): """ tell the gui how to represent your system using openGL objects Parameters ---------- coords : array index : int we can have more than one molecule on the screen at one time. index tells which one to draw. They are viewed at the same time, so they should be visually distinct, e.g. different colors. accepted values are 1 or 2 """ # index = 1 or 2 from OpenGL import GL, GLUT coords = coordslinear.reshape(coordslinear.size / 3, 3) com = np.mean(coords, axis=0) size = 0.5 if index == 1: color = [0.65, 0.0, 0.0, 1.] else: color = [0.00, 0.65, 0., 1.] GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color) for i, xx in enumerate(coords): if i == self.ntypeA: size *= 0.88 #this should be dependent on lj parameters if index == 1: color = [0.25, 0.00, 0., 1.] else: color = [0.00, 0.25, 0., 1.] GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color) x = xx - com GL.glPushMatrix() GL.glTranslate(x[0], x[1], x[2]) GLUT.glutSolidSphere(size, 30, 30) GL.glPopMatrix()
def drawSensor(self): gl.glPushMatrix() gl.glTranslatef(rx[i],ry[i],rz[i]) gl.glColor3f(colr[i],colg[i],colb[i]) glut.glutSolidSphere(rad[i],20,20) gl.glPopMatrix()
def OnDraw(self): if not self.init: self.InitGL() self.init = True #self.InitGL() # clear color and depth buffers gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # use a fresh transformation matrix gl.glPushMatrix() # # position object # #gl.glTranslate(0.0, 0.0, -2.0) # gl.glRotate(30.0, 1.0, 0.0, 0.0) # gl.glRotate(30.0, 0.0, 1.0, 0.0) # gl.glTranslate(0, -1, 0) # gl.glRotate(250, 1, 0, 0) glut.glutSolidCone(0.5, 1, 30, 5) gl.glPopMatrix() for s in _spheres: # use a fresh transformation matrix gl.glPushMatrix() # position object gl.glTranslate(s.x, s.y, s.z) glut.glutSolidSphere(s.radius, 60, 60) gl.glPopMatrix() # rotate the camera gl.glRotate((self.y - self.lasty), 0.0, 0.0, 1.0); gl.glRotate((self.x - self.lastx), 1.0, 0.0, 0.0); # push into visible buffer self.SwapBuffers()
def draw(self, coordslinear, index, subtract_com=True): """ tell the gui how to represent your system using openGL objects Parameters ---------- coords : array index : int we can have more than one molecule on the screen at one time. index tells which one to draw. They are viewed at the same time, so they should be visually distinct, e.g. different colors. accepted values are 1 or 2 """ from OpenGL import GL,GLUT coords = coordslinear.reshape([-1, 3]) if subtract_com: com = np.mean(coords, axis=0) else: com = np.zeros(3) size = 0.5 * self.r0 for xx in coords: x=xx-com GL.glPushMatrix() GL.glTranslate(x[0],x[1],x[2]) GLUT.glutSolidSphere(size, 30, 30) GL.glPopMatrix()
def paintGL(self, p0=0, p1=None, drawOpts=DRAWOPT_DEFAULT): if not self.visible: return is_click = (p1 is not None) if p1 is None: p1 = len(self) if p1 <= p0: return # draw nothing GL.glShadeModel(GL.GL_SMOOTH) GL.glPushMatrix() GL.glMultMatrixf(self.transform) GL.glColor4f(*self.colour) GL.glDisable(GL.GL_BLEND) GL.glEnable(GL.GL_DEPTH_TEST) primType = self.primitiveType.lower() if primType == 'sphere': radius = self.attrs.get('radius', 100.) slices = self.attrs.get('slices', 10) stacks = self.attrs.get('stacks', 10) if self.attrs.get('wire',None): GLUT.glutWireSphere(radius, slices, stacks) else: GLUT.glutSolidSphere(radius, slices, stacks) elif primType == 'cube': size = self.attrs.get('size', 100.) if self.attrs.get('wire',None): GLUT.glutWireCube(size) else: GLUT.glutSolidCube(size) GL.glPopMatrix()
def _render_geom(self, geom): """ Render either a ode.GeomBox or ode.GeomSphere object. """ #allowed = [ode.GeomSphere, ode.GeomCylinder] allowed = [ode.GeomBox, ode.GeomSphere, ode.GeomCylinder] ok = False for klass in allowed: ok = ok or isinstance(geom, klass) if (not ok): return ogl.glPushMatrix() ogl.glMultMatrixd(self._extract_matrix(geom)) ogl.glMaterialfv(ogl.GL_FRONT, ogl.GL_SPECULAR, (0.0, 0.0, 0.0)) if (isinstance(geom, ode.GeomBox)): sx, sy, sz = geom.getLengths() ogl.glScale(sx, sy, sz) oglut.glutSolidCube(1) elif (isinstance(geom, ode.GeomSphere)): r = geom.getRadius() oglut.glutSolidSphere(r, 20, 20) elif (isinstance(geom, ode.GeomCylinder)): r, h = geom.getParams() oglut.glutSolidCylinder(r, h, 20, 20) ogl.glPopMatrix()
def render(self): x, y, z = self.position color = self.color[:3] + (self.life,) GL.glPushMatrix() GL.glColor(*color) GL.glTranslate(x, y, -z) GLUT.glutSolidSphere(self.size * self.life, 5, 5) GL.glPopMatrix()
def render(self): x, y, z = self.position color = self.color[:3] + (self.life, ) GL.glPushMatrix() GL.glColor(*color) GL.glTranslate(x, y, -z) GLUT.glutSolidSphere(self.size * self.life, 5, 5) GL.glPopMatrix()
def _draw(self): # use a fresh transformation matrix gl.glPushMatrix() # position object gl.glTranslate(value(self.pos.x), value(self.pos.y), value(self.pos.z)) gl.glMaterialfv(gl.GL_FRONT,gl.GL_DIFFUSE,self.color.rgb()) check_units('radius must have dimensions of distance', self.radius, meter) glut.glutSolidSphere(value(self.radius), 60, 60) gl.glPopMatrix()
def draw(self): """Function draws coin.""" set_color(self.coin_color) gl.glPushMatrix() gl.glTranslatef(self.pos_x + 0.5, 0.0, self.pos_z + 0.5) glut.glutSolidSphere(self.radius, 10, 10) gl.glPopMatrix()
def create_sphere(lats=10, longs=10, color=None): """ Creates an sphere. :param lats: Latitude :param longs: Longitude :param color: Color :type lats: int :type longs: int :type color: list :return: OpenGL list """ if lats >= 3 and longs >= 10: obj = _gl.glGenLists(1) _gl.glNewList(obj, _gl.GL_COMPILE) _gl.glPushMatrix() if color is not None: _gl.glColor4fv(color) # noinspection PyBroadException try: _glut.glutSolidSphere(1.0, lats, longs) except: if not _FIGURES_ERRS[0]: _print_gl_error( 'OpenGL actual version does not support glutSolidSphere function' ) _FIGURES_ERRS[0] = True for _i in range(0, lats + 1): lat0 = _pi * (-0.5 + float(float(_i - 1) / float(lats))) z0 = _sin(lat0) zr0 = _cos(lat0) lat1 = _pi * (-0.5 + float(float(_i) / float(lats))) z1 = _sin(lat1) zr1 = _cos(lat1) # Use Quad strips to draw the sphere _gl.glBegin(_gl.GL_QUAD_STRIP) for _j in range(0, longs + 1): _long = 2 * _pi * float(float(_j - 1) / float(longs)) x = _cos(_long) y = _sin(_long) _gl.glNormal3f(x * zr0, y * zr0, z0) _gl.glVertex3f(x * zr0, y * zr0, z0) _gl.glNormal3f(x * zr1, y * zr1, z1) _gl.glVertex3f(x * zr1, y * zr1, z1) _gl.glEnd() _gl.glPopMatrix() _gl.glEndList() return obj else: raise Exception('Latitude and logitude must be greater than 3')
def draw(self): """""" set_color(self.color) gl.glPushMatrix() gl.glTranslatef(self.pos_x + 0.5, 0.0, self.pos_z + 0.5) gl.glRotate(self.rotate, 0, 1, 0) glut.glutSolidSphere(self.radius, 10, 10) gl.glPopMatrix()
def _drawSpheres(self, elapsedTime): for sphere in self._spheres: gl.glPopMatrix() gl.glPushMatrix() sphereCenter = sphere.currentLocation sphereRadius = sphere.radius sphereColor = sphere.color gl.glTranslate(sphereCenter.x, sphereCenter.y, sphereCenter.z) gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, [sphereColor.getRedAsPercent(), sphereColor.getGreenAsPercent(), sphereColor.getBlueAsPercent(), sphereColor.getAlphaAsPercent()]) glut.glutSolidSphere(sphereRadius, 15, 15) sphere.move(elapsedTime) return
def draw(self, coordslinear, index): ca = CoordsAdapter(nrigid=coordslinear.size/6,coords=coordslinear) from OpenGL import GL,GLUT com=np.mean(ca.posRigid, axis=0) for xx, rot in zip(ca.posRigid, ca.rotRigid): p = np.dot(rotations.aa2mx(rot), np.array([1., 0., 0.])) x=xx-com x = x - 0.4*p GL.glPushMatrix() GL.glTranslate(x[0],x[1],x[2]) GLUT.glutSolidSphere(0.3,30,30) p=0.8*p self.drawCylinder([0.,0.,0.], p) GL.glTranslate(p[0],p[1],p[2]) GLUT.glutSolidSphere(0.1,30,30) GL.glPopMatrix()
def _render_helper(self, helper): """ Draw a sphere. `helper`: (coordinates, color). The color is a vector of three values in the range [0..1]. """ coords, color = helper ogl.glPushMatrix() ogl.glMultMatrixd((1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, coords[0], coords[1], coords[2], 1)) ogl.glMaterialfv(ogl.GL_FRONT, ogl.GL_SPECULAR, (color[0], color[1], color[2])) oglut.glutSolidSphere(0.2, 20, 20) ogl.glPopMatrix()
def init(self): self.list_index = gl.glGenLists(1) gl.glNewList( self.list_index, gl.GL_COMPILE) gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1) #gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 1) gl.glDisable(gl.GL_LIGHTING) gl.glColor3f(1,1,0) glut.glutSolidSphere(50.,50,50) for i in range(len(self.points)): r,g,b = self.colors[i] print r,g,b gl.glColor3f(r,g,b) x,y,z = self.points[i] print x,y,z gl.glRasterPos3f(x,y,z) label = self.labels[i] print label for c in label: print c glut.glutBitmapCharacter(glut.GLUT_BITMAP_TIMES_ROMAN_24, ord(c)) gl.glEnable(gl.GL_LIGHTING) gl.glEnd()
def render(self): GL.glEnable(GL.GL_LIGHTING) GL.glEnable(GL.GL_LIGHT0) GLUT.glutSolidSphere(.99,128,128) GL.glDisable(GL.GL_LIGHTING) GL.glColor3f(0., 1.0, 0.2) super(Simulation, self).render() if not self.position_data is None: i0 = int(len(self.position_data) / 2) x, y, z = self.position_data[i0] GL.glPushMatrix() GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glTranslated(x, y, z) GL.glColor4f(1, 1, 0, 0.5) GLUT.glutSolidSphere(self.world.cutoff, 16, 16) GL.glPopMatrix()
def draw(self, coordslinear, index): from OpenGL import GL,GLUT xyzlinear = self.mysys.getxyz(coordslinear) xyz = xyzlinear.reshape(xyzlinear.size/3, 3) com=np.mean(xyz, axis=0) if index == 1: color1 = [0.65, 0.0, 0.0, 1.] color2 = [0.35, 0.0, 0.0, 1.] else: color1 = [0.00, 0.65, 0., 1.] color2 = [0.00, 0.35, 0., 1.] GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color2) for i, xx in enumerate(xyz): if i % 3 == 0: GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color1) else: GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color2) x=xx-com GL.glPushMatrix() GL.glTranslate(x[0],x[1],x[2]) GLUT.glutSolidSphere(0.4,30,30) GL.glPopMatrix() #now try to draw cylinders connecting atoms in a molecule nsites = len(xyz[:,0]) z = np.array([0.,0.,1.]) #default cylinder orientation for j1 in range(0,nsites,3): X1 = xyz[j1,:] - com for j2 in range(j1+1,j1+3,1): #draw a cylinder from xyz[j1] to xyz[j2] X2 = xyz[j2,:] - com p = X2-X1 #desired cylinder orientation r = np.linalg.norm(p) t = np.cross(z,p) #angle about which to rotate a = np.arccos( np.dot( z,p) / r ) #rotation angle a *= (180. / np.pi) #change units to angles GL.glPushMatrix() GL.glTranslate( X1[0], X1[1], X1[2] ) GL.glRotate( a, t[0], t[1], t[2] ) GLUT.glutSolidCone(.2,r,30,30) #I can't seem to draw a cylinder GL.glPopMatrix()
def draw(self): set_color(self.color) gl.glPushMatrix() gl.glTranslatef(self.pos_x + 0.5, 0.0, self.pos_z + 0.5) gl.glRotate(self.rotate, 0, 1, 0) # gl.glBegin(gl.GL_TRIANGLE_FAN) # gl.glColor3f(0, 1, 0) # gl.glVertex2f(self.pos_x, self.pos_z) # for i in range(13): # Rysujemy okrag z odcietym malym kawalkiem # Obrocony o podany offset. # # i = i + DisplayFunc.dolna + DisplayFunc.off # x = self.pos_x + 0.3 * sin(2 * pi * i / 24.0) # y = self.pos_z + 0.3 * cos(2 * pi * i / 24.0) # gl.glVertex2f(x, y) # gl.glEnd() glut.glutSolidSphere(self.radius, 10, 10) gl.glPopMatrix()
def draw(self, coordsl, index): from OpenGL import GL,GLUT coords=coordsl.reshape(coordsl.size/3,3) #coords = coords.reshape(GMIN.getNAtoms, 3) com=np.mean(coords, axis=0) for xx in coords: x = xx-com GL.glPushMatrix() GL.glTranslate(x[0],x[1],x[2]) GLUT.glutSolidSphere(0.3,30,30) GL.glPopMatrix() # get bond list from amber params mol = readAmb.readAmberParam() mol.populateBondConn() # draw bonds for atomPairs in mol.bondConn: xyz1 = coords[atomPairs[0]-1] - com xyz2 = coords[atomPairs[1]-1] - com self.drawCylinder(xyz1, xyz2)
def draw(self, coordslinear, index): """ tell the gui how to represent your system using openGL objects Parameters ---------- coords : array index : int we can have more than one molecule on the screen at one time. index tells which one to draw. They are viewed at the same time, so they should be visually distinct, e.g. different colors. accepted values are 1 or 2 """ from OpenGL import GL, GLUT coords = coordslinear.reshape(coordslinear.size / 3, 3) com = np.mean(coords, axis=0) for xx in coords: x = xx - com GL.glPushMatrix() GL.glTranslate(x[0], x[1], x[2]) GLUT.glutSolidSphere(0.5, 30, 30) GL.glPopMatrix()
def draw(self, coords_rigid, index): from OpenGL import GL,GLUT coords=np.zeros([GMIN.getNAtoms(), 3]) GMIN.toAtomistic(coords.reshape(coords.size), coords_rigid) #coords = coords.reshape(GMIN.getNAtoms, 3) com=np.mean(coords, axis=0) if index == 1: color = [[0.65, 0.0, 0.0, 1.], [0.35, 0.0, 0.0, 1.]] else: color = [[0.00, 0.65, 0., 1.], [0.00, 0.35, 0., 1.]] i=0 for xx in coords[:-2]: GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color[i%2]) i+=1 x = xx-com GL.glPushMatrix() GL.glTranslate(x[0],x[1],x[2]) GLUT.glutSolidSphere(0.5,30,30) GL.glPopMatrix() GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, [0.,0.,1.,1.]) from pygmin.utils import lattice l = lattice.lowerTriangular(coords_rigid[-6:]) mb = l[:,0] + l[:,1] + l[:,2] GL.glPushMatrix() GL.glTranslate(-0.5*mb[0],-0.5*mb[1],-0.5*mb[2]) for i in xrange(3): self.drawCylinder([0.,0.,0.], l[:,i]) for i in xrange(1,3): self.drawCylinder(l[:,0], l[:,0] + l[:,i]) mb = l[:,0] + l[:,1] + l[:,2] for i in xrange(0,3): self.drawCylinder(mb, mb - l[:,i]) for i in xrange(1,3): self.drawCylinder(mb-l[:,0], mb - l[:,i]-l[:,0]) self.drawCylinder(l[:,1], l[:,1] + l[:,0]) self.drawCylinder(l[:,2], l[:,2] + l[:,0]) GL.glPopMatrix()
def drawStuff(aspect): GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(40., aspect, 1., 40.) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GLU.gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0) GL.glClearColor(0, 1, 0, 1) GL.glShadeModel(GL.GL_SMOOTH) GL.glEnable(GL.GL_CULL_FACE) GL.glEnable(GL.GL_DEPTH_TEST) GL.glEnable(GL.GL_LIGHTING) lightPosition = [10, 4, 10, 1] lightColor = [1, 1, 1, 1] GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, lightPosition) GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, lightColor) GL.glLightf(GL.GL_LIGHT0, GL.GL_CONSTANT_ATTENUATION, 0.1) GL.glLightf(GL.GL_LIGHT0, GL.GL_LINEAR_ATTENUATION, 0.05) GL.glEnable(GL.GL_LIGHT0) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) color = [1, 0, 0, 1] GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, color) GLUT.glutSolidSphere(2, 40, 40)
def draw(self, rbcoords, index, shift_com=True): from OpenGL import GL, GLUT coords = self.aasystem.to_atomistic(rbcoords) if shift_com: com=np.mean(coords, axis=0) else: com = np.zeros(3) self.aasystem.sites i=0 for atom_type, xx in zip(self.atom_types, coords): color = [1.0, 0.0, 0.0] radius = 0.3 if elements.has_key(atom_type): color = elements[atom_type]["color"] radius = elements[atom_type]["radius"]*self.render_scale if index == 2: color = [0.5, 1.0, .5] i+=1 GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color) x=xx-com GL.glPushMatrix() GL.glTranslate(x[0],x[1],x[2]) GLUT.glutSolidSphere(radius,10,10) GL.glPopMatrix() color = [1.0, 1.0, 1.0] if index == 2: color = [0.5, 1.0, .5] GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color) if hasattr(self, "draw_bonds"): for i1, i2 in self.draw_bonds: self.drawCylinder(coords[i1]-com, coords[i2]-com)
def sphere(): gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glColor(1.0, 1.0, 1.0, 1.0) glut.glutSolidSphere(1, 40, 40)
def render_sphere(self, pos, r, num_seg1=20, num_seg2=10): GL.glPushMatrix() GL.glTranslated(*pos) GLUT.glutSolidSphere(r, num_seg1, num_seg2) GL.glPopMatrix()
def DrawColony(self, colony, xangle, yangle, size=0.1, color=(1.0, 1.0, 0.0), show_index=False, single_object_mode=True): # print "draw colony:"#, object.objname #original_color = color # i = 0 gl.glColor3f(color[0], color[1], color[2]) gl.glLoadIdentity() gl.glPushMatrix() # glTranslate(0, 0, self.offset) gl.glRotatef(yangle, 1.0, 0.0, 0.0) gl.glRotatef(xangle, 0.0, 1.0, 0.0) # single_object_mode = True if not single_object_mode: # print "point size, glbegin" gl.glPointSize(5) gl.glDisable(gl.GL_LIGHTING) gl.glBegin(gl.GL_POINTS) for cr in colony.polyp_list: if cr.dead: # continue # glColor3f( self.color.selected_landmark[0], self.color.selected_landmark[1], self.color.selected_landmark[2] ) gl.glColor3f(0.1, 0.1, 0.1) elif cr.selected: # print cr.id, "selected" gl.glColor3f(0.5, 0.5, 0.0) elif cr.is_neighbor: # print cr.id, "neighbor" gl.glColor3f(0.2, 0.2, 0.5) else: gl.glColor3f(color[0], color[1], color[2]) if single_object_mode: gl.glPushMatrix() gl.glTranslate(cr.pos[0], cr.pos[1], cr.pos[2]) if cr.dead: glut.glutSolidSphere(1, 20, 20) # glutSolidCube( size ) else: glut.glutSolidSphere(1, 20, 20) # glutSolidCube( size ) gl.glPopMatrix() else: gl.glVertex3f(cr.pos[0], cr.pos[1], cr.pos[2]) if not single_object_mode: # print "glend" gl.glEnd() gl.glEnable(gl.GL_LIGHTING) if show_index: i = 0 for cr in colony.polyp_list: i += 1 if cr.dead: continue gl.glDisable(gl.GL_LIGHTING) gl.glColor3f(.5, .5, 1.0) gl.glRasterPos3f(cr.pos[0], cr.pos[1] + size * 2, cr.pos[2]) for letter in list(str(i)): glut.glutBitmapCharacter(glut.GLUT_BITMAP_HELVETICA_18, ord(letter)) gl.glEnable(gl.GL_LIGHTING) gl.glPopMatrix()
def __init__(self, color=(0, 0, 0, 1)): Renderable.__init__(self, color) GL.glNewList(self.gl_list, GL.GL_COMPILE) GLUT.glutSolidSphere(.5, Sphere.slices, Sphere.stacks) GL.glEndList()
def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glColor3f(1.0, 0, 0) GLUT.glutSolidSphere(2, 16, 16)