Ejemplo n.º 1
0
 def __del__(self):
     """Get rid of display lists, quadrics etc."""
     GLU.gluDeleteQuadric(self.quadric)
     for name,dlist in self.dlists.items():
         if glIsList(dlist):
             glDeleteLists(dlist,1)
     super(BodyPart,self).__del__()
Ejemplo n.º 2
0
    def paintGL(self):
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glLoadIdentity()
        #        gl.glPushMatrix()
        glu.gluLookAt(self.camera[0], self.camera[1], self.camera[2],
                      self.center[0], self.center[1], self.center[2], 0, 1, 0)
        self.paintAxes()

        normalSize = numpy.max(self.center - self.b_box[1]) / 100.0

        gl.glEnable(gl.GL_BLEND)
        gl.glEnable(gl.GL_CULL_FACE)
        gl.glCullFace(gl.GL_BACK)

        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gluQuadric = glu.gluNewQuadric()
        for cmd, (array, colors, sizes) in self.commands:
            for (x, y, z), (r, g, b), size in zip(array, colors, sizes):
                gl.glPushMatrix()
                gl.glTranslatef(x, y, z)
                gl.glColor4f(r, g, b, 0.3)
                glu.gluSphere(gluQuadric, normalSize * size, 10, 10)
                gl.glPopMatrix()
        glu.gluDeleteQuadric(gluQuadric)
Ejemplo n.º 3
0
 def applyShape(self):
     self._Quadric=GLU.gluNewQuadric()
     GLU.gluQuadricNormals(self._Quadric, self.GL(self._normals))
     GLU.gluQuadricTexture(self._Quadric, self.GL(self._texture))
     GLU.gluCylinder(self._Quadric, self._base, self._top, self._height, self._subdiv, 1)
     GLU.gluDeleteQuadric(self._Quadric)
     self._Quadric = None
 def __del__(self):
     """Get rid of display lists, quadrics etc."""
     GLU.gluDeleteQuadric(self.quadric)
     for name, dlist in self.dlists.items():
         if glIsList(dlist):
             glDeleteLists(dlist, 1)
     super(BodyPart, self).__del__()
Ejemplo n.º 5
0
 def applyShape(self):
     self._Quadric = GLU.gluNewQuadric()
     GLU.gluQuadricNormals(self._Quadric, self.GL(self._normals))
     GLU.gluQuadricTexture(self._Quadric, self.GL(self._texture))
     GLU.gluCylinder(self._Quadric, self._base, self._top, self._height,
                     self._subdiv, 1)
     GLU.gluDeleteQuadric(self._Quadric)
     self._Quadric = None
Ejemplo n.º 6
0
def draw_sphere(color, pos, radius=2):
    gl.glColor(*color)

    gl.glPushMatrix()

    x, y = pos
    gl.glTranslate(x, y, 3)

    q = glu.gluNewQuadric()
    glu.gluSphere(q, radius, 20, 20)
    glu.gluDeleteQuadric(q)

    gl.glPopMatrix()
Ejemplo n.º 7
0
def draw_sphere(color, pos, radius=2):
    gl.glColor(*color)

    gl.glPushMatrix()

    x, y = pos
    gl.glTranslate(x, y, 3)

    q = glu.gluNewQuadric()
    glu.gluSphere(q, radius, 20, 20)
    glu.gluDeleteQuadric(q)

    gl.glPopMatrix()
Ejemplo n.º 8
0
 def visualisation_particle(self):
     #print('visualisation_particle')
     if len(self.list_of_solar_system) == 9:
         for k in range(len(self.list_of_solar_system)):
             sphere = glu.gluNewQuadric() 
             gl.glPushMatrix()                      
             gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, self.list_of_solar_system[k].color) #цвет задаем
             gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, self.list_of_solar_system[k].color)
             gl.glTranslatef(self.list_of_solar_system[k].x*7, self.list_of_solar_system[k].y*7, self.list_of_solar_system[k].z*7)
             glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL) 
             if k == 0:   
                 glu.gluSphere(sphere, self.list_of_solar_system[k].m / 150000.0, 16, 16) 
             if k == 1:
                 glu.gluSphere(sphere, self.list_of_solar_system[k].m * 20, 16, 16) 
             if k == 2:
                 glu.gluSphere(sphere, self.list_of_solar_system[k].m * 2, 16, 16) 
             if k == 3:
                 glu.gluSphere(sphere, self.list_of_solar_system[k].m * 1.5, 16, 16) 
             if k == 4:
                 glu.gluSphere(sphere, self.list_of_solar_system[k].m * 7, 16, 16) 
             if k == 5:
                 glu.gluSphere(sphere, self.list_of_solar_system[k].m / 30, 16, 16)
             if k == 6:
                 glu.gluSphere(sphere, self.list_of_solar_system[k].m / 12, 16, 16)
             if k == 7:
                 glu.gluSphere(sphere, self.list_of_solar_system[k].m / 2.3, 16, 16)
             if k == 8:
                 glu.gluSphere(sphere, self.list_of_solar_system[k].m / 3.2, 16, 16)
             
             gl.glTranslatef(-self.list_of_solar_system[k].x*7, -self.list_of_solar_system[k].y*7, -self.list_of_solar_system[k].z*7)
             gl.glPopMatrix() 
             glu.gluDeleteQuadric(sphere)
             self.update()
     else:
         for k in range(len(self.list_of_particles)):
             sphere = glu.gluNewQuadric() 
             gl.glPushMatrix()                      
             gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, self.list_of_particles[k].color) #цвет задаем
             gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, self.list_of_particles[k].color)
             gl.glTranslatef(self.list_of_particles[k].x, self.list_of_particles[k].y, self.list_of_particles[k].z)
             glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL)    
             glu.gluSphere(sphere, self.list_of_particles[k].m / 100.0, 16, 16) 
             gl.glTranslatef(-self.list_of_particles[k].x, -self.list_of_particles[k].y, -self.list_of_particles[k].z)
             gl.glPopMatrix() 
             glu.gluDeleteQuadric(sphere)
             self.update()
Ejemplo n.º 9
0
def draw_cone(color, pos, vel, speed):
    gl.glColor(*color)

    gl.glPushMatrix()

    x, y = pos
    gl.glTranslate(x, y, 3)

    vx, vy = vel
    gl.glRotate(360 / TAU * math.atan2(vy, vx), 0, 0, 1)
    gl.glRotate(90, 0, 0, 1)
    gl.glRotate(90, 1, 0, 0)

    q = glu.gluNewQuadric()
    glu.gluCylinder(q, 2, 0, max(1, speed / 3), 20, 20)
    glu.gluDeleteQuadric(q)

    gl.glPopMatrix()
Ejemplo n.º 10
0
def draw_cone(color, pos, vel, speed):
    gl.glColor(*color)

    gl.glPushMatrix()

    x, y = pos
    gl.glTranslate(x, y, 3)

    vx, vy = vel
    gl.glRotate(360 / TAU * math.atan2(vy, vx), 0, 0, 1)
    gl.glRotate(90, 0, 0, 1)
    gl.glRotate(90, 1, 0, 0)

    q = glu.gluNewQuadric()
    glu.gluCylinder(q, 2, 0, max(1, speed / 3), 20, 20)
    glu.gluDeleteQuadric(q)

    gl.glPopMatrix()
Ejemplo n.º 11
0
    def draw(self):
        global _particle_list
        sphere = glu.gluNewQuadric()

        #Solar system drawing
        if self.checkBox.isChecked():
            #Sun
            gl.glPushMatrix()

            gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,
                              _particle_list[0].color)
            gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR,
                            _particle_list[0].color)
            gl.glTranslatef(_particle_list[0].x, _particle_list[0].y,
                            _particle_list[0].z)
            glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL)
            glu.gluSphere(sphere, _particle_list[0].m / 120000.0, 16, 16)
            gl.glTranslatef(-_particle_list[0].x, -_particle_list[0].y,
                            -_particle_list[0].z)
            gl.glPopMatrix()

            #Mercury
            gl.glPushMatrix()
            gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,
                              _particle_list[1].color)
            gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR,
                            _particle_list[1].color)
            gl.glTranslatef(_particle_list[1].x, _particle_list[1].y,
                            _particle_list[1].z)
            glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL)
            glu.gluSphere(sphere, _particle_list[1].m * 10, 16, 16)
            gl.glTranslatef(-_particle_list[1].x, -_particle_list[1].y,
                            -_particle_list[1].z)
            gl.glPopMatrix()

            #Venus
            gl.glPushMatrix()
            gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,
                              _particle_list[2].color)
            gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR,
                            _particle_list[2].color)
            gl.glTranslatef(_particle_list[2].x, _particle_list[2].y,
                            _particle_list[2].z)
            glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL)
            glu.gluSphere(sphere, _particle_list[2].m, 16, 16)
            gl.glTranslatef(-_particle_list[2].x, -_particle_list[2].y,
                            -_particle_list[2].z)
            gl.glPopMatrix()

            #Earth
            gl.glPushMatrix()
            gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,
                              _particle_list[3].color)
            gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR,
                            _particle_list[3].color)
            gl.glTranslatef(_particle_list[3].x, _particle_list[3].y,
                            _particle_list[3].z)
            glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL)
            glu.gluSphere(sphere, _particle_list[3].m, 16, 16)
            gl.glTranslatef(-_particle_list[3].x, -_particle_list[3].y,
                            -_particle_list[3].z)
            gl.glPopMatrix()

            #Mars
            gl.glPushMatrix()
            gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,
                              _particle_list[4].color)
            gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR,
                            _particle_list[4].color)
            gl.glTranslatef(_particle_list[4].x, _particle_list[4].y,
                            _particle_list[4].z)
            glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL)
            glu.gluSphere(sphere, _particle_list[4].m * 7, 16, 16)
            gl.glTranslatef(-_particle_list[4].x, -_particle_list[4].y,
                            -_particle_list[4].z)
            gl.glPopMatrix()

            #Jupiter
            gl.glPushMatrix()
            gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,
                              _particle_list[5].color)
            gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR,
                            _particle_list[5].color)
            gl.glTranslatef(_particle_list[5].x, _particle_list[5].y,
                            _particle_list[5].z)
            glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL)
            glu.gluSphere(sphere, _particle_list[5].m / 30.0, 16, 16)
            gl.glTranslatef(-_particle_list[5].x, -_particle_list[5].y,
                            -_particle_list[5].z)
            gl.glPopMatrix()

            #Saturn
            gl.glPushMatrix()
            gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,
                              _particle_list[6].color)
            gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR,
                            _particle_list[6].color)
            gl.glTranslatef(_particle_list[6].x, _particle_list[6].y,
                            _particle_list[6].z)
            glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL)
            glu.gluSphere(sphere, _particle_list[6].m / 12.0, 16, 16)
            gl.glTranslatef(-_particle_list[6].x, -_particle_list[6].y,
                            -_particle_list[6].z)
            gl.glPopMatrix()

            #Uran
            gl.glPushMatrix()
            gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,
                              _particle_list[7].color)
            gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR,
                            _particle_list[7].color)
            gl.glTranslatef(_particle_list[7].x, _particle_list[7].y,
                            _particle_list[7].z)
            glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL)
            glu.gluSphere(sphere, _particle_list[7].m / 2.3, 16, 16)
            gl.glTranslatef(-_particle_list[7].x, -_particle_list[7].y,
                            -_particle_list[7].z)
            gl.glPopMatrix()

            #Neptune
            gl.glPushMatrix()
            gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,
                              _particle_list[8].color)
            gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR,
                            _particle_list[8].color)
            gl.glTranslatef(_particle_list[8].x, _particle_list[8].y,
                            _particle_list[8].z)
            glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL)
            glu.gluSphere(sphere, _particle_list[8].m / 3.2, 16, 16)
            gl.glTranslatef(-_particle_list[8].x, -_particle_list[8].y,
                            -_particle_list[8].z)
            gl.glPopMatrix()

        #other
        else:
            _particle_list = [p for p in _particle_list if p.alive == True]
            for i in range(len(_particle_list)):
                if ((_particle_list[i].x > -2000) &
                    (_particle_list[i].x < 2000)
                        & (_particle_list[i].y > -2000) &
                    (_particle_list[i].y < 2000)
                        & (_particle_list[i].z > -2000) &
                    (_particle_list[i].z < 2000)):
                    gl.glPushMatrix()
                    gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,
                                      _particle_list[i].color)
                    gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR,
                                    _particle_list[i].color)
                    gl.glTranslatef(_particle_list[i].x, _particle_list[i].y,
                                    _particle_list[i].z)
                    glu.gluQuadricDrawStyle(sphere, glu.GLU_FILL)
                    glu.gluSphere(sphere, _particle_list[i].m / 100.0, 16, 16)
                    gl.glTranslatef(-_particle_list[i].x, -_particle_list[i].y,
                                    -_particle_list[i].z)
                    gl.glPopMatrix()
                else:
                    _particle_list[i].alive = False
            glu.gluDeleteQuadric(sphere)

        glu.gluDeleteQuadric(sphere)
        label = str(len(_particle_list))
        self.label_12.setText(label)
Ejemplo n.º 12
0
 def cleanupCache(self):
     GLU.gluDeleteQuadric(self._Quadric)
     self._Quadric = None
Ejemplo n.º 13
0
 def cleanupCache(self):
     GLU.gluDeleteQuadric(self._Quadric)
     self._Quadric = None
Ejemplo n.º 14
0
 def applyShape(self):
     Q = GLU.gluNewQuadric()
     GLU.gluQuadricNormals(Q, self.GL(self._normals))
     GLU.gluQuadricTexture(Q, self.GL(self._texture))
     GLU.gluSphere(Q, self._radius, self._subdiv, self._subdiv / 2)
     GLU.gluDeleteQuadric(Q)
Ejemplo n.º 15
0
 def __exit__(self ,type, value, traceback):
     if self._quadric:
         GLU.gluDeleteQuadric(_quadric);
         self._quadric = None
     return not type
Ejemplo n.º 16
0
 def __del__(self):
     """Get rid of display lists, quadrics etc."""
     GLU.gluDeleteQuadric(self.quadric)
     super(StickMan,self).__del__()
Ejemplo n.º 17
0
 def __del__(self):
     """Get rid of display lists, quadrics etc."""
     GLU.gluDeleteQuadric(self.quadric)
     super(StickMan, self).__del__()
Ejemplo n.º 18
0
 def applyShape(self):
     Q=GLU.gluNewQuadric()
     GLU.gluQuadricNormals(Q, self.GL(self._normals))
     GLU.gluQuadricTexture(Q, self.GL(self._texture))
     GLU.gluSphere(Q, self._radius, self._subdiv, self._subdiv/2)
     GLU.gluDeleteQuadric( Q )
Ejemplo n.º 19
0
def finish():
    global __quadratic
    try:
        GLU.gluDeleteQuadric(__quadratic)
    except NameError as e:
        print e.message
Ejemplo n.º 20
0
def drawGLScene():
	
	GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
	for object in sceneObjects.values():

		# apply camera transform for > 3 dimensions
		iterateCamerasD()
		
		# apply 3D camera transform
		iterateCamerasD()
		
		# first we need to project geometry from > 3 dimensions to 3D
		projectFromHigherDimensions(object)

		vertexBuffer = object.getVertexData3D()
		edgesData = object.getEdgesData()		
		
		#print "edges:", edgesData
		#print "vertex:", vertexBuffer
		
		if vertexBuffer != None:		
		
			if renderingMode == RENDER_MODE_1:
				# in this rendering mode we represent edges as
				# cylinders and vertices as spheres
				
				if len(vertexBuffer) == 0: return
				
				# draw vertices (spheres)
				quadObj1 = GLU.gluNewQuadric()
				GLU.gluQuadricDrawStyle(quadObj1, GLU.GLU_FILL)
				#GLU.gluQuadricDrawStyle(quadObj1, GL.GL_WIREFRAME)
				
				for vertex in vertexBuffer.values():
					GL.glLoadIdentity()
					iterateCameras3D()			
					GL.glTranslatef(vertex[0], vertex[1], vertex[2])		
					GLU.gluSphere(quadObj1, 0.1, 15, 15)

				# draw faces
				GL.glBegin(GL.GL_TRIANGLES)
				
				GL.glEnd()
				
				# draw edges (cylinders)
				# initially all the cylinders must points towards the positive z
				# direction
				quadObj2 = GLU.gluNewQuadric()
				GLU.gluQuadricDrawStyle(quadObj2, GLU.GLU_FILL)
				for edge in edgesData.values():
                    
					GL.glLoadIdentity()
					
					iterateCameras3D()			
                    
					#modelview = GL.glGetDouble(GL.GL_MODELVIEW_MATRIX)
					#print "before"
					#dumpOGLMatrix(modelview)
					
					# get 'from' and 'to' vectors for the edge
					x0, y0, z0 = vertexBuffer[int(edge[0])]
					x1, y1, z1 = vertexBuffer[int(edge[1])]
                   
					# position a cylinder
					GL.glTranslatef(x0, y0, z0)
					
					# calculate edge length
					length = math.sqrt( (x1 - x0) ** 2 + (y1 - y0) ** 2 + (z1 - z0) ** 2 )
					
					tmp = Vector([x1 - x0, y1 - y0, z1 - z0])	
                    
					# get the cross products
					if (negZ == tmp.inv().normalize()):
						axis1 = Vector([0,1.0,0])						
					else:
						axis1 = Matrix.crossProduct3D(negZ, tmp.normalize())
					axis2 = Matrix.crossProduct3D(negZ, axis1)				
					axis3 = posZ
                    
					# get the angle we need to rotate to
					cos_angle = posZ.dotProduct(tmp.normalize())
					angle = math.degrees(math.acos(cos_angle))
					
					# calculate the transformation
					axis1.normalizeSelf()
					axis2.normalizeSelf()
                    
					# we need an inverse matrix and we know that the transpose of the rotation matrix is equal to its inverse
					a1, a2, a3 = axis1.getComponents(), axis2.getComponents(), axis3.getComponents()
					v1 = [ a1[0], a2[0], a3[0], 0 ]
					v2 = [ a1[1], a2[1], a3[1], 0 ]
					v3 = [ a1[2], a2[2], a3[2], 0 ]							
					axis1, axis2, axis3 = v1, v2, v3
					
					# feed to openGL				
					rotTransform = createOGLMatrixFromLists(axis1, axis2, axis3)
					rotTransform.extend(homogenousVec)				
					GL.glMultMatrixf(rotTransform)
					
					# rotate a cylinder around axis1
					GL.glRotatef(angle, 1.0, 0.0, 0.0)
				
					# draw a cylinder
					GLU.gluCylinder(quadObj2, 0.05, 0.05, length, 12, 12)					
				
				GLU.gluDeleteQuadric(quadObj1)
				GLU.gluDeleteQuadric(quadObj2)
				
	GL.glUseProgram(shaders[0])
				
	#renderString(100, 100, GLUT.GLUT_BITMAP_8_BY_13, "Hello World", (1.0, 0.0, 0.0))
	
	GLUT.glutSwapBuffers()
Ejemplo n.º 21
0
 def __exit__(self, type, value, traceback):
     if self._quadric:
         GLU.gluDeleteQuadric(_quadric)
         self._quadric = None
     return not type