Exemple #1
1
    def add_bond(self, Atom1Pos, Atom2Pos, Radius=0.1, type='cylinder'):
        Radius2 = Radius
        if type == 'conus':
            Radius2 = 0
        Rel = [
            Atom2Pos[0] - Atom1Pos[0], Atom2Pos[1] - Atom1Pos[1],
            Atom2Pos[2] - Atom1Pos[2]
        ]
        BindingLen = math.sqrt(
            math.pow(Rel[0], 2) + math.pow(Rel[1], 2) +
            math.pow(Rel[2], 2))  # высота цилиндра
        if (BindingLen != 0):
            Fall = 180.0 / math.pi * math.acos(Rel[2] / BindingLen)
            Yaw = 180.0 / math.pi * math.atan2(Rel[1], Rel[0])

            gl.glPushMatrix()
            gl.glTranslated(Atom1Pos[0], Atom1Pos[1], Atom1Pos[2])
            gl.glRotated(Yaw, 0, 0, 1)
            gl.glRotated(Fall, 0, 1, 0)
            glu.gluCylinder(
                glu.gluNewQuadric(),
                Radius,  # /*baseRadius:*/
                Radius2,  # /*topRadius:*/
                BindingLen,  # /*height:*/
                self.quality * 15,  # /*slices:*/
                1)  #/*stacks:*/
            gl.glPopMatrix()
Exemple #2
0
 def to_OpenGL(self):
     if not GL_enabled:
         return
     GL.glPushMatrix()
     GL.glTranslate(self.center.x, self.center.y, self.center.z)
     if not hasattr(self, "_sphere"):
         self._sphere = GLU.gluNewQuadric()
     GLU.gluSphere(self._sphere, self.radius, 10, 10)
     if not hasattr(self, "_cylinder"):
         self._cylinder = GLU.gluNewQuadric()
     GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height, 10, 10)
     GL.glPopMatrix()
Exemple #3
0
 def to_OpenGL(self):
     if not GL_enabled:
         return
     GL.glPushMatrix()
     GL.glTranslate(self.center.x, self.center.y, self.center.z)
     if not hasattr(self, "_sphere"):
         self._sphere = GLU.gluNewQuadric()
     GLU.gluSphere(self._sphere, self.radius, 10, 10)
     if not hasattr(self, "_cylinder"):
         self._cylinder = GLU.gluNewQuadric()
     GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height,
                     10, 10)
     GL.glPopMatrix()
Exemple #4
0
def marker():
    GL.glPushMatrix()
    GL.glTranslate(0.00, 0.00, 0.00)
    GL.glColor(0, 0, 1)
    GLU.gluCylinder(GLU.gluNewQuadric(), 0.01, 0.01, 1.0, 6, 1)
    GL.glRotate(-90, 1, 0, 0)
    GL.glColor(0, 1, 0)
    GLU.gluCylinder(GLU.gluNewQuadric(), 0.01, 0.01, 1.0, 6, 1)
    GL.glRotate(90, 0, 1, 0)
    GL.glColor(1, 0, 0)
    GLU.gluCylinder(GLU.gluNewQuadric(), 0.01, 0.01, 1.0, 6, 1)
    GL.glColor(1, 1, 1)
    GL.glPopMatrix()
Exemple #5
0
 def to_OpenGL(self):
     if not GL_enabled:
         return
     GL.glPushMatrix()
     GL.glTranslate(self.center[0], self.center[1], self.center[2])
     if not hasattr(self, "_cylinder"):
         self._cylinder = GLU.gluNewQuadric()
     GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height,
             10, 10)
     if not hasattr(self, "_disk"):
         self._disk = GLU.gluNewQuadric()
     GLU.gluDisk(self._disk, 0, self.radius, 10, 10)
     GL.glPopMatrix()
Exemple #6
0
 def to_opengl(self):
     if not GL_enabled:
         return
     GL.glPushMatrix()
     GL.glTranslate(self.center[0], self.center[1], self.center[2])
     if not hasattr(self, "_cylinder"):
         self._cylinder = GLU.gluNewQuadric()
     GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height,
                     10, 10)
     if not hasattr(self, "_disk"):
         self._disk = GLU.gluNewQuadric()
     GLU.gluDisk(self._disk, 0, self.radius, 10, 10)
     GL.glPopMatrix()
Exemple #7
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
Exemple #8
0
	def __init__(self, world, w, h, d, offset_matrix=None):
		pynewton.Sphere.__init__( self, world, w, h, d, offset_matrix )
		self.width  = w
		self.height = h
		self.depth  = d
		if GLPresent:
			self.quad   = GLU.gluNewQuadric()
Exemple #9
0
    def __init__(self, molecule, hide_hydrogens=False, randomize_single_bonds=False,
                       bond_width=.1, bond_length=2):
        self.molecule = molecule
        self.hide_hydrogens = hide_hydrogens
        self.randomize_single_bonds = randomize_single_bonds
        self.rotate_atoms(self.molecule)

        self.bond_width = bond_width
        self.bond_length = bond_length

        self.quad = glu.gluNewQuadric()
        glu.gluQuadricNormals(self.quad, glu.GLU_SMOOTH)
        glu.gluQuadricDrawStyle(self.quad, glu.GLU_FILL)

        self.cylinder_resolution = 100
        self.sphere_resolution = 100

        self.zoom = 5
        self.rotations = []

        self.scroll_up_button = 3
        self.scroll_down_button = 4
        self.scroll_buttons = [self.scroll_up_button,
                               self.scroll_down_button]
        self.zoom_increment = 0.2

        self.default_element_color = (221/255, 119/255, 1)
        self.bond_color = (128/255,) * 3

        self.drag_start = None
Exemple #10
0
def gl_init( width, height ):
    global __legocaptex,__quadratic
    
    setviewport(width, height)
    
    __legocaptex = layer_manager.load_2d_texture(pygame.image.tostring(__image, "RGBA"), LEGO_CAP_WIDTH, LEGO_CAP_HEIGHT)
    __quadratic = GLU.gluNewQuadric()
    
    GLU.gluQuadricTexture(__quadratic, GLU.GLU_TRUE)
    GLU.gluQuadricDrawStyle(__quadratic,GLU.GLU_FILL)    
    GLU.gluQuadricOrientation(__quadratic, GLU.GLU_OUTSIDE)
    GLU.gluQuadricNormals(__quadratic, GLU.GLU_SMOOTH)
    
    GL.glClearColor( 0.0, 0.2, 0.5, 1.0 )
    
    GL.glEnable(GL.GL_POINT_SMOOTH)
    GL.glEnable(GL.GL_LINE_SMOOTH)
    GL.glEnable(GL.GL_TEXTURE_2D)
    GL.glEnable(GL.GL_ALPHA_TEST)
    GL.glEnable(GL.GL_COLOR_MATERIAL)
    GL.glDisable(GL.GL_CULL_FACE)
    GL.glAlphaFunc(GL.GL_GREATER,0.1)
    
    GL.glClearAccum(0.0, 0.0, 0.0, 1.0)
    GL.glClear(GL.GL_ACCUM_BUFFER_BIT)
    
    #GL.glGenLists(1)
    
    draw_mode_3d()
Exemple #11
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)
Exemple #12
0
def _draw_one_robot(posture_pos: list, highlight=None):
    """Permet de dessiner un robot avec ces link et ses moteurs.
    `posture_pos` - liste de matrice de rotation décrivant le robot dans sa posture"""
    global _section_color, _joint_color, _hjoint_color

    # Chaque section est representee par un segment noir
    gl.glBegin(gl.GL_LINE_STRIP)
    gl.glColor4f(_section_color[0], _section_color[1], _section_color[2],
                 _section_color[3])

    for section in posture_pos:
        gl.glVertex3f(section[0][3], section[1][3], section[2][3])

    gl.glEnd()

    # Chaque moteur est represente par une sphere bleue
    for i in range(len(posture_pos)):
        # Si on veux mettre en valeur un moteur, on l'affiche en rouge (pour l'animation)
        if highlight is not None and i == highlight + 1:
            gl.glColor4f(_hjoint_color[0], _hjoint_color[1], _hjoint_color[2],
                         _hjoint_color[3])
        else:
            gl.glColor4f(_joint_color[0], _joint_color[1], _joint_color[2],
                         _joint_color[3])
        gl.glPushMatrix()
        gl.glTranslatef(posture_pos[i][0][3], posture_pos[i][1][3],
                        posture_pos[i][2][3])
        glu.gluSphere(glu.gluNewQuadric(), 0.003, 16, 16)
        gl.glPopMatrix()
Exemple #13
0
class BoundingSphere(object):
    quadratic = GLU.gluNewQuadric()

    def __init__(self, center, radius):
        self.center = center
        self.radius = radius

    def __str__(self):
        return "Center: %s, Radius: %s" % (str(self.center), str(self.radius))

    def transformedBy(self, transform_matrix):
        return BoundingSphere(
            MathUtil.transformPoint(self.center, transform_matrix),
            self.radius)

    def transformedTo(self, position, yaw, pitch, roll):
        m = MathUtil.buildTransformMatrix(position, yaw, pitch, roll)
        return self.transformedBy(m)

    def draw(self):
        GL.glPushMatrix()
        GL.glTranslatef(self.center.x, self.center.y, self.center.z)
        GL.glScalef(self.radius, self.radius, self.radius)
        GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)
        GL.glDisable(GL.GL_TEXTURE_2D)
        GLU.gluSphere(self.quadratic, 1.0, 24, 24)
        GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
        GL.glPopMatrix()
Exemple #14
0
 def draw(self):
     quad = glu.gluNewQuadric()
     ogl.glPushMatrix()
     ogl.glMultMatrixd(self.frame.matrix())
     glu.gluSphere(quad, 0.03, 10, 6)
     glu.gluCylinder(quad, 0.03, 0.0, 0.09, 10, 1)
     ogl.glPopMatrix()
Exemple #15
0
    def __init__(self,
                 molecule,
                 hide_hydrogens=False,
                 randomize_single_bonds=False,
                 bond_width=.1,
                 bond_length=2):
        self.molecule = molecule
        self.hide_hydrogens = hide_hydrogens
        self.randomize_single_bonds = randomize_single_bonds
        self.rotate_atoms(self.molecule)

        self.bond_width = bond_width
        self.bond_length = bond_length

        self.quad = glu.gluNewQuadric()
        glu.gluQuadricNormals(self.quad, glu.GLU_SMOOTH)
        glu.gluQuadricDrawStyle(self.quad, glu.GLU_FILL)

        self.cylinder_resolution = 100
        self.sphere_resolution = 100

        self.zoom = 5
        self.rotations = []

        self.scroll_up_button = 3
        self.scroll_down_button = 4
        self.scroll_buttons = [self.scroll_up_button, self.scroll_down_button]
        self.zoom_increment = 0.2

        self.default_element_color = (221 / 255, 119 / 255, 1)
        self.bond_color = (128 / 255, ) * 3

        self.drag_start = None
 def init_gl(self):
     """
         Initialise OpenGL settings
     """
     self.sphere = GL.glGenLists(1)
     GL.glNewList(self.sphere, GL.GL_COMPILE)
     quad_obj = GLU.gluNewQuadric()
     GLU.gluQuadricDrawStyle(quad_obj, GLU.GLU_FILL)
     GLU.gluQuadricNormals(quad_obj, GLU.GLU_SMOOTH)
     GLU.gluSphere(quad_obj, 1, 16, 16)
     GL.glEndList()
     GL.glShadeModel(GL.GL_SMOOTH)
     GL.glEnable(GL.GL_DEPTH_TEST)
     GL.glEnable(GL.GL_CULL_FACE)
     GL.glEnable(GL.GL_LIGHTING)
     # make sure normal vectors of scaled spheres are normalised
     GL.glEnable(GL.GL_NORMALIZE)
     GL.glEnable(GL.GL_LIGHT0)
     light_pos = list(_LIGHT_POSITION) + [1]
     GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_pos)
     GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, [1.0, 1.0, 1.0, 1.0])
     GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
     GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
     GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, [0.2, .2, .2, 1])
     GL.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, [0.7, 0.7, 0.7, 1])
     GL.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, [0.1, 0.1, 0.1, 1])
     GL.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, 20)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     GLU.gluPerspective(60, 1, .01, 10)
     GL.glMatrixMode(GL.GL_MODELVIEW)
    def DrawWire(self, yangle, xangle, vfrom, vto):
        lm1 = self.colony.polyp_list[vfrom - 1]
        lm2 = self.colony.polyp_list[vto - 1]
        # print lm1.x, lm2.x
        axis_start = [0, 0, 1]
        axis_end = [lm1.pos[0] - lm2.pos[0], lm1.pos[1] - lm2.pos[1], lm1.pos[2] - lm2.pos[2]]
        # print vfrom, vto, axis_start, axis_end
        angle = math.acos(axis_start[0] * axis_end[0] + axis_start[1] * axis_end[1] + axis_start[2] * axis_end[2] / (
        (axis_start[0] ** 2 + axis_start[1] ** 2 + axis_start[2] ** 2) ** 0.5 * (
        axis_end[0] ** 2 + axis_end[1] ** 2 + axis_end[2] ** 2) ** 0.5))
        angle = angle * (180 / math.pi)
        axis_rotation = [0, 0, 0]
        axis_rotation[0] = axis_start[1] * axis_end[2] - axis_start[2] * axis_end[1]
        axis_rotation[1] = axis_start[2] * axis_end[0] - axis_start[0] * axis_end[2]
        axis_rotation[2] = axis_start[0] * axis_end[1] - axis_start[1] * axis_end[0]
        if angle == 180:
            axis_rotation = [1, 0, 0]

        length = (axis_end[0] ** 2 + axis_end[1] ** 2 + axis_end[2] ** 2) ** 0.5
        radius = self.wire_radius
        cyl = glu.gluNewQuadric()
        gl.glPushMatrix()
        gl.glLoadIdentity()
        # glTranslate(0, 0, self.offset)
        gl.glRotatef(yangle, 1.0, 0.0, 0.0)
        gl.glRotatef(xangle, 0.0, 1.0, 0.0)
        gl.glTranslate(lm2.pos[0], lm2.pos[1], lm2.pos[2])
        if (angle != 0):
            gl.glRotate(angle, axis_rotation[0], axis_rotation[1], axis_rotation[2])

        glu.gluCylinder(cyl, radius, radius, length, 10, 10)
        gl.glPopMatrix()
Exemple #18
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()
Exemple #19
0
 def to_OpenGL(self):
     if not GL_enabled:
         return
     GL.glPushMatrix()
     GL.glTranslate(self.center[0], self.center[1], self.center[2])
     GLUT.glutSolidTorus(self.minorradius, self.majorradius, 10, 20)
     if not hasattr(self, "_cylinder"):
         self._cylinder = GLU.gluNewQuadric()
     GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height,
                     10, 20)
     GL.glPopMatrix()
     GL.glPushMatrix()
     GL.glTranslate(self.location[0], self.location[1], self.location[2])
     if not hasattr(self, "_disk"):
         self._disk = GLU.gluNewQuadric()
     GLU.gluDisk(self._disk, 0, self.majorradius, 20, 10)
     GL.glPopMatrix()
Exemple #20
0
 def to_OpenGL(self):
     if not GL_enabled:
         return
     GL.glPushMatrix()
     GL.glTranslate(self.center.x, self.center.y, self.center.z)
     GLUT.glutSolidTorus(self.minorradius, self.majorradius, 10, 20)
     if not hasattr(self, "_cylinder"):
         self._cylinder = GLU.gluNewQuadric()
     GLU.gluCylinder(self._cylinder, self.radius, self.radius, self.height,
             10, 20)
     GL.glPopMatrix()
     GL.glPushMatrix()
     GL.glTranslate(self.location.x, self.location.y, self.location.z)
     if not hasattr(self, "_disk"):
         self._disk = GLU.gluNewQuadric()
     GLU.gluDisk(self._disk, 0, self.majorradius, 20, 10)
     GL.glPopMatrix()
Exemple #21
0
    def __init__(self, node):
        """
        Constructor.

        @param node The adaptable node.
        """
        super(GLQuadricCylinderAdapter, self).__init__(node)
        self.__quadric = GLU.gluNewQuadric()
Exemple #22
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
Exemple #23
0
 def __init__(self, radius, pos, color, visible=True):
     self.radius = radius
     self.pos = pos[:]
     self.visible = visible
     self.color = color
     self.slices = 25  # meridijani
     self.stacks = 15  # paralele
     self.quadric = glu.gluNewQuadric()
Exemple #24
0
 def __init__(self, *args):
     if args and isinstance(args[0], hal.component):
         self.comp = args[0]
         args = args[1:]
     else:
         self.comp = None
     self._coords = args
     self.q = GLU.gluNewQuadric()
Exemple #25
0
def draw_points_cloud(end_points: list,
                      max_dist=0.3,
                      robot=None,
                      sphere=0,
                      rota=False):
    """Dessine un nuage de point 3d.
    `end_points` - les coordonnees des points en (x, y, z) ou liste d'end_points"""
    global _cloud_point_color

    _init_display()

    # Calcul de la couleur des points avant affichage
    points = []
    for ep in end_points:
        if isinstance(ep, EndPoint):
            pos = ep.get_pos()
        else:
            pos = ep

        if _cloud_point_color is None:
            d = 0
            for p in pos:
                d += p**2
            d = math.sqrt(d)

            fact = d / max_dist
            color = _get_rainbow_color(fact)
            points.append((pos, color))
        else:
            points.append((pos, _cloud_point_color))

    while _StaticVars.is_running:
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        if rota:
            gl.glRotatef(1, 0, 0, 1)

        _draw_axes()

        gl.glBegin(gl.GL_POINTS)
        for (p, c) in points:
            gl.glColor3f(c[0], c[1], c[2])
            gl.glVertex3f(p[0], p[1], p[2])

        gl.glEnd()

        if robot is not None:
            posture = robot.get_posture_pos((0, 0, 0, 0, 0, 0))
            _draw_one_robot(posture)

        if sphere != 0:
            gl.glColor4f(_sphere_color[0], _sphere_color[1], _sphere_color[2],
                         _sphere_color[3])
            glu.gluSphere(glu.gluNewQuadric(), sphere, 64, 32)

        # _draw_fps()
        pg.display.flip()
        _event_handler()
        pg.time.wait(10)
Exemple #26
0
    def __init__(self, node):
        """
        Constructor.

        @param radius   The radius of the sphere.
        @param parent   The parent SceneGraphNode instance.
        """
        super(GLQuadricSphereAdapter, self).__init__(node)
        self.__quadric = GLU.gluNewQuadric()
Exemple #27
0
 def display(self):
     ogl.glPushMatrix()
     ogl.glTranslate(-1, -3.3, 1)
     ang = ((time.time() / 40) % 1) * 360  # 2*3.14
     ogl.glRotate(ang, 0, 0, 1)
     quad = oglu.gluNewQuadric()
     oglu.gluQuadricDrawStyle(quad, oglu.GLU_LINE)
     oglu.gluSphere(quad, 0.7, 15, 15)
     ogl.glPopMatrix()
Exemple #28
0
 def __init__(self, win, size_px, pos_px=(0,0)):
     self.win=win
     self._quad=GLU.gluNewQuadric() 
     #self.winSize = win.monitor.getSizePix()
     #print self.winSize
     if win.winType == 'pyglet':
         self.winSize = win.winHandle.get_size()
     self.winAspect = self.winSize[1] / float(self.winSize[0])
     self.setSize(size_px, False)
     self.setPos(pos_px)
Exemple #29
0
 def __init__(self, win, size_px, pos_px=(0, 0)):
     self.win = win
     self._quad = GLU.gluNewQuadric()
     #self.winSize = win.monitor.getSizePix()
     #print self.winSize
     if win.winType == 'pyglet':
         self.winSize = win.winHandle.get_size()
     self.winAspect = self.winSize[1] / float(self.winSize[0])
     self.setSize(size_px, False)
     self.setPos(pos_px)
Exemple #30
0
 def paintGL(self):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glColor3f(1.0, 2.0, 1.0)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glPushMatrix()
     gl.glTranslatef(0, 0, 0)
     qobj = glu.gluNewQuadric()
     glu.gluQuadricOrientation(qobj, glu.GLU_OUTSIDE)
     glu.gluSphere(qobj, 0.67, 100, 100)
     gl.glPopMatrix()
Exemple #31
0
    def add_atoms(self):
        prop = self.prop
        mendeley = TPeriodTable()
        gl.glNewList(self.object, gl.GL_COMPILE)

        min_val = 0
        max_val = 0
        mean_val = 0

        if (len(prop) > 0) and (prop != "charge"):
            min_val = self.MainModel.atoms[0].properties[prop]
            max_val = self.MainModel.atoms[0].properties[prop]
            mean_val = self.MainModel.atoms[0].properties[prop]
            for at in self.MainModel.atoms:
                val = at.properties[prop]
                if min_val > val: min_val = val
                if max_val < val: max_val = val
                mean_val += val
            mean_val /= self.MainModel.nAtoms()

        for at in self.MainModel.atoms:
            gl.glPushMatrix()
            gl.glTranslatef(at.x, at.y, at.z)
            self.QuadObjS.append(glu.gluNewQuadric())
            rad = mendeley.Atoms[at.charge].radius / mendeley.Atoms[6].radius

            if at.isSelected() == False:
                if (len(prop) > 0) and (prop != "charge"):
                    val = at.properties[prop]
                    if val > mean_val:
                        gl.glColor3f(
                            0,
                            math.fabs((val - mean_val) / (max_val - mean_val)),
                            0)
                    else:
                        gl.glColor3f(
                            0, 0,
                            math.fabs((val - mean_val) / (min_val - mean_val)))
                else:
                    color = self.color_of_atoms[at.charge]
                    if (self.SelectedFragmentMode == True) and (at.fragment1
                                                                == True):
                        gl.glColor4f(color[0], color[1], color[2],
                                     self.SelectedFragmentAtomsTransp)
                    else:
                        gl.glColor3f(color[0], color[1], color[2])
                glu.gluSphere(self.QuadObjS[-1], 0.3 * rad, self.quality * 70,
                              self.quality * 70)
            else:
                gl.glColor3f(1, 0, 0)
                glu.gluSphere(self.QuadObjS[-1], 0.35 * rad, self.quality * 70,
                              self.quality * 70)
            gl.glPopMatrix()
        gl.glEndList()
        self.active = True
Exemple #32
0
 def __drawSaucer(self):
     quadric = glu.gluNewQuadric()
     ogl.glTranslatef(0.0, 0.0, -0.014)
     glu.gluCylinder(quadric, 0.015, 0.03, 0.004, 32, 1)
     ogl.glTranslatef(0.0, 0.0, 0.004)
     glu.gluCylinder(quadric, 0.03, 0.04, 0.01, 32, 1)
     ogl.glTranslatef(0.0, 0.0, 0.01)
     glu.gluCylinder(quadric, 0.05, 0.03, 0.02, 32, 1)
     ogl.glTranslatef(0.0, 0.0, 0.02)
     glu.gluCylinder(quadric, 0.03, 0.0, 0.003, 32, 1)
     ogl.glTranslatef(0.0, 0.0, -0.02)
Exemple #33
0
 def __init__(self,radius=1.0, slices=20, stacks=20):
     _engine.Object_model.__init__(self)
     prim=_engine.Primitive()
     sphere_gl_list=_gl.glGenLists(1)
     quadric=_glu.gluNewQuadric()
     _gl.glNewList(sphere_gl_list,_gl.GL_COMPILE)
     _glu.gluSphere(quadric,radius,slices,stacks)
     _gl.glEndList()
     prim.gl_list=sphere_gl_list
     self.add_primitive(prim)
     self.scale=[1.,1.,1.]
Exemple #34
0
    def __init__(self, width: int, height: int):
        """
        Arguments:
            width {int} -- Window width in pixels
            height {int} -- Window height in pixels
        """
        self.resize(width, height)

        self.quad = glu.gluNewQuadric()
        glu.gluQuadricDrawStyle(self.quad, gl.GL_LINE)
        glu.gluQuadricTexture(self.quad, gl.GL_TRUE)
Exemple #35
0
 def add_selected_atom(self):
     gl.glNewList(self.object + 7, gl.GL_COMPILE)
     for at in self.MainModel.atoms:
         if at.isSelected() == True:
             gl.glPushMatrix()
             gl.glTranslatef(at.x, at.y, at.z)
             self.QuadObjS.append(glu.gluNewQuadric())
             gl.glColor3f(1, 0, 0)
             glu.gluSphere(self.QuadObjS[-1], 0.35, 70, 70)
             gl.glPopMatrix()
     gl.glEndList()
Exemple #36
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()
Exemple #37
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()
Exemple #38
0
def draw_nodes(pos,
               nodelist,
               node_color,
               node_size,
               node_border_size,
               node_border_color,
               scale,
               fancy,
               lights):
    GL.glDisable(GL.GL_DEPTH_TEST)
    i = 0
    if fancy:
        vp = GL.glGetIntegerv(GL.GL_VIEWPORT)
        sphere_size_scale = 2./(vp[2]+vp[3])
    for n in nodelist:
        if fancy:
            if lights:
                GL.glEnable(GL.GL_LIGHTING)
            GL.glPushMatrix()
            if len(pos[n]) ==2:
                position = tuple(list(pos[n]) + [0.])
            else:
                position = pos[n]
            GL.glTranslate(*position)
            GL.glScale(scale,scale,scale)

            GL.glColor(*node_color[i])
            sphere = GLU.gluNewQuadric()
            GLU.gluQuadricNormals(sphere,GLU.GLU_SMOOTH)
            GLU.gluQuadricTexture(sphere,GLU.GLU_TRUE)
            GLU.gluSphere(sphere,
                          node_size[i]*sphere_size_scale,
                          32,
                          32)
            GL.glPopMatrix()
            if lights:
                GL.glDisable(GL.GL_LIGHTING)
        else:                   
            GL.glPointSize(node_size[i]+node_border_size[i])
            GL.glBegin(GL.GL_POINTS)
            GL.glColor(*node_border_color[i])
            GL.glVertex(*tuple(pos[n]))
            GL.glEnd()

            GL.glPointSize(node_size[i])
            GL.glBegin(GL.GL_POINTS)
            GL.glColor(*node_color[i])
            GL.glVertex(*tuple(pos[n]))
            GL.glEnd()
        i+=1
    GL.glEnable(GL.GL_DEPTH_TEST)
Exemple #39
0
    def draw_arrow(self, pos, ori, length, col):
        # glfw.make_context_current(self.window)
        # self.gui_lock.acquire()

        gl.glLoadIdentity()

        gl.glTranslatef(pos[0], pos[1], pos[2])

        gl.glRotatef(ori[0],1.0,0.0,0.0)
        gl.glRotatef(ori[1],0.0,1.0,0.0)
        gl.glRotatef(ori[2],0.0,0.0,1.0)

        gl.glColor3f(col[0], col[1], col[2])

        quadObj=glu.gluNewQuadric()
        
        glu.gluCylinder(quadObj, 0.25, 0.25, length, 32, 16)

        gl.glTranslatef(0, 0, length)

        quadObj=glu.gluNewQuadric()
        
        glu.gluCylinder(quadObj, 0.45, 0., 4, 32, 16)
Exemple #40
0
 def add_axes(self):
     gl.glNewList(self.object + 7, gl.GL_COMPILE)
     gl.glColor3f(self.color_of_axes[0], self.color_of_axes[1],
                  self.color_of_axes[2])
     size = 2
     sizeCone = 0.2
     letter_height = sizeCone
     letter_width = 0.6 * sizeCone
     width = 0.06
     self.QuadObjS.append(glu.gluNewQuadric())
     glu.gluSphere(self.QuadObjS[-1], 2 * width, 70, 70)
     p0 = np.array([0, 0, 0])
     p1 = np.array([size, 0, 0])
     p1cone = np.array([size + sizeCone, 0, 0])
     p2 = np.array([0, size, 0])
     p2cone = np.array([0, size + sizeCone, 0])
     p3 = np.array([0, 0, size])
     p3cone = np.array([0, 0, size + sizeCone])
     self.add_bond(p0, p1, width)
     self.add_bond(p1, p1cone, 2 * width, 'conus')
     self.add_bond(p0, p2, width)
     self.add_bond(p2, p2cone, 2 * width, 'conus')
     self.add_bond(p0, p3, width)
     self.add_bond(p3, p3cone, 2 * width, 'conus')
     # lets drow "X"
     pX = p1cone + np.array([0, 1.5 * sizeCone, 0])
     pX1 = pX + np.array([-0.5 * letter_width, -0.5 * letter_height, 0])
     pX2 = pX + np.array([+0.5 * letter_width, +0.5 * letter_height, 0])
     pX3 = pX + np.array([-0.5 * letter_width, +0.5 * letter_height, 0])
     pX4 = pX + np.array([+0.5 * letter_width, -0.5 * letter_height, 0])
     self.add_bond(pX1, pX2, 0.5 * width)
     self.add_bond(pX3, pX4, 0.5 * width)
     # lets drow "Y"
     pY = p2cone + np.array([0, 1.5 * sizeCone, 0])
     pY1 = pY
     pY2 = pY + np.array([0, +0.5 * letter_height, +0.5 * letter_width])
     pY3 = pY + np.array([0, -0.5 * letter_height, +0.5 * letter_width])
     pY4 = pY + np.array([0, +0.5 * letter_height, -0.5 * letter_width])
     self.add_bond(pY1, pY2, 0.5 * width)
     self.add_bond(pY3, pY4, 0.5 * width)
     # lets drow "Z"
     pZ = p3cone + np.array([1.5 * sizeCone, 0, 0])
     pZ1 = pZ + np.array([-0.5 * letter_height, 0, -0.5 * letter_width])
     pZ2 = pZ + np.array([+0.5 * letter_height, 0, +0.5 * letter_width])
     pZ3 = pZ + np.array([-0.5 * letter_height, 0, +0.5 * letter_width])
     pZ4 = pZ + np.array([+0.5 * letter_height, 0, -0.5 * letter_width])
     self.add_bond(pZ1, pZ3, 0.5 * width)
     self.add_bond(pZ1, pZ2, 0.5 * width)
     self.add_bond(pZ2, pZ4, 0.5 * width)
     gl.glEndList()
Exemple #41
0
 def drawCylinder(self, X1, X2):
     from OpenGL import GL, GLU
     z = np.array([0.,0.,1.]) #default cylinder orientation
     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] )
     g=GLU.gluNewQuadric()
     GLU.gluCylinder(g, .1,0.1,r,30,30)  #I can't seem to draw a cylinder
     GL.glPopMatrix()
Exemple #42
0
 def drawCylinder(self, X1, X2):
     from OpenGL import GL,GLUT, GLU
     z = np.array([0.,0.,1.]) #default cylinder orientation
     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] )
     g=GLU.gluNewQuadric()
     GLU.gluCylinder(g, .1,0.1,r,30,30)  #I can't seem to draw a cylinder
     GL.glPopMatrix()
Exemple #43
0
 def buildAxisIndicator(self):
     """Assemble the axis indicator into a display list.
     """
     # single axis specs
     bodyLen = GLView.axisLen * 0.75
     tipLen = GLView.axisLen * 0.25
     majDia = GLView.axisLen * 0.125
     slices = 8
     stacks = 2
     # build one axis
     axisId = gl.glGenLists(1)
     quadric = glu.gluNewQuadric()
     gl.glNewList(axisId, gl.GL_COMPILE)
     glu.gluCylinder(quadric, 0.0, majDia, bodyLen, slices, stacks)
     gl.glPushMatrix()
     gl.glTranslate(0, 0, bodyLen)
     glu.gluCylinder(quadric, majDia, 0, tipLen, slices, stacks)
     gl.glPopMatrix()
     gl.glEndList()
     # now assemble all three
     self.axisIndicatorId = gl.glGenLists(1)
     gl.glNewList(self.axisIndicatorId, gl.GL_COMPILE)
     # always lit and smooth shaded with a bit a spec
     gl.glEnable(gl.GL_LIGHTING)
     gl.glPolygonMode(gl.GL_FRONT, gl.GL_FILL)
     gl.glShadeModel(gl.GL_SMOOTH)
     gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR,
                     [1.0, 1.0, 1.0, 1.0])
     gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SHININESS, 64)
     # X axis, red
     gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE,
                     [0.7, 0.0, 0.0, 1.0])
     gl.glPushMatrix()
     gl.glRotate(90, 0, 1, 0)
     gl.glCallList(axisId)
     gl.glPopMatrix()
     # Y axis, green
     gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE,
                     [0.0, 0.7, 0.0, 1.0])
     gl.glPushMatrix()
     gl.glRotate(-90, 1, 0, 0)
     gl.glCallList(axisId)
     gl.glPopMatrix()
     # Z axis, blue
     gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE,
                     [0.0, 0.0, 0.7, 1.0])
     gl.glCallList(axisId)
     gl.glEndList()
Exemple #44
0
 def buildAxisIndicator(self):
     """Assemble the axis indicator into a display list.
     """
     # single axis specs
     bodyLen = GLView.axisLen * 0.75
     tipLen = GLView.axisLen * 0.25
     majDia = GLView.axisLen * 0.125
     slices = 8
     stacks = 2
     # build one axis
     axisId = gl.glGenLists(1)
     quadric = glu.gluNewQuadric()
     gl.glNewList(axisId, gl.GL_COMPILE)
     glu.gluCylinder(quadric, 0.0, majDia, bodyLen, slices, stacks)
     gl.glPushMatrix()
     gl.glTranslate(0, 0, bodyLen)
     glu.gluCylinder(quadric, majDia, 0, tipLen, slices, stacks)
     gl.glPopMatrix()
     gl.glEndList()
     # now assemble all three
     self.axisIndicatorId = gl.glGenLists(1)
     gl.glNewList(self.axisIndicatorId, gl.GL_COMPILE)
     # always lit and smooth shaded with a bit a spec
     gl.glEnable(gl.GL_LIGHTING)
     gl.glPolygonMode(gl.GL_FRONT, gl.GL_FILL)
     gl.glShadeModel(gl.GL_SMOOTH)
     gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR,
                     [1.0, 1.0, 1.0, 1.0])
     gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SHININESS, 64)
     # X axis, red
     gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE,
                     [0.7, 0.0, 0.0, 1.0])
     gl.glPushMatrix()
     gl.glRotate(90, 0, 1, 0)
     gl.glCallList(axisId)
     gl.glPopMatrix()
     # Y axis, green
     gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE,
                     [0.0, 0.7, 0.0, 1.0])
     gl.glPushMatrix()
     gl.glRotate(-90, 1, 0, 0)
     gl.glCallList(axisId)
     gl.glPopMatrix()
     # Z axis, blue
     gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE,
                     [0.0, 0.0, 0.7, 1.0])
     gl.glCallList(axisId)
     gl.glEndList()
Exemple #45
0
 def paintGL(self):
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     glColor3f(1.0, 1.0, 1.0)  # Default color is white
     # Draw the flashlight
     self.drawFlashLight()
     # Draw the sphere
     glMaterialfv(GL_FRONT, GL_AMBIENT, [0.3, 0.3, 0.3, 1.0])
     glMaterialfv(GL_FRONT, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
     glMaterialfv(GL_FRONT, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
     glLightfv(self.light, GL_POSITION, self.lightposition)
     glMaterialf(GL_FRONT, GL_SHININESS, 25.0)
     quad = GLU.gluNewQuadric()
     GLU.gluQuadricDrawStyle(quad, GLU.GLU_FILL)
     GLU.gluQuadricNormals(quad, GLU.GLU_SMOOTH)
     GLU.gluSphere(quad, 3.0, 30, 30)
     glFlush()
Exemple #46
0
 def paintGL(self):
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     glColor3f(1.0, 1.0, 1.0)  # Default color is white
     # Draw the flashlight
     self.drawFlashLight()
     # Draw the sphere
     glMaterialfv(GL_FRONT, GL_AMBIENT, [0.3, 0.3, 0.3, 1.0])
     glMaterialfv(GL_FRONT, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
     glMaterialfv(GL_FRONT, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
     glLightfv(self.light, GL_POSITION, self.lightposition)
     glMaterialf(GL_FRONT, GL_SHININESS, 25.0)
     quad = GLU.gluNewQuadric()
     GLU.gluQuadricDrawStyle(quad, GLU.GLU_FILL)
     GLU.gluQuadricNormals(quad, GLU.GLU_SMOOTH)
     GLU.gluSphere(quad, 3.0, 30, 30)
     glFlush()
Exemple #47
0
    def _initGL(self,Width,Height):
        GL.glShadeModel(GL.GL_SMOOTH); 
        GL.glClearColor(0.0, 0.0, 0.0, 0.0)    # This Will Clear The Background Color To Black
        GL.glClearDepth(1.0)                   # Enables Clearing Of The Depth Buffer
        GL.glDepthFunc(GL.GL_LESS)                # The Type Of Depth Test To Do
        GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST)
        GL.glEnable(GL.GL_BLEND);                         # Enable Blending
        GL.glLineWidth(1.);
        GL.glDisable(GL.GL_LINE_SMOOTH)
        GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

        self.width = Width
        self.height = Height
        self.quad = GLU.gluNewQuadric()
        GLU.gluQuadricNormals(self.quad, GLU.GLU_SMOOTH)
        GLU.gluQuadricTexture(self.quad, GL.GL_TRUE)
Exemple #48
0
	def drawPoints(self) :
		GL.glEnable(GL.GL_CULL_FACE)
		GL.glEnable(GL.GL_LIGHTING)
		quadric = GLU.gluNewQuadric()
		for e,a,d in self._points :
			ra, re = math.radians(a), math.radians(e)
			sa, se = math.sin(ra), math.sin(re)
			ca, ce = math.cos(ra), math.cos(re)
			if d<0 :
				GL.glColor(1., 1., 1., .5)
				d = -d
			else :
				GL.glColor(1., .6, .6, .5)
			GL.glPushMatrix()
			GL.glTranslate(d*ce*ca, d*ce*sa,d*se)
			GLU.gluSphere(quadric, .1, 10, 10)
			GL.glPopMatrix()
Exemple #49
0
def draw_cone(X1, X2, rbase=0.1, rtop=0.0, color=None):
    """draw a cylinder from X1 to X2"""
    if color is not None:
        change_color(color)
    from OpenGL import GL, GLU

    z = np.array([0., 0., 1.])  # default cylinder orientation
    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])
    g = GLU.gluNewQuadric()
    GLU.gluCylinder(g, rbase, rtop, r, 30, 30)  # I can't seem to draw a cylinder
    GL.glPopMatrix()
Exemple #50
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()
Exemple #51
0
 def drawFlashLight(self):
     glPushMatrix()
     glRotate(-self.phi, 1.0, 0.0, 0.0)
     glRotate(-self.theta, 0.0, 1.0, 0.0)
     glTranslate(0, 0, 4)
     glMaterialfv(GL_FRONT, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0])
     glMaterialfv(GL_FRONT, GL_DIFFUSE, [0.0, 0.0, 0.0, 1.0])
     glMaterialfv(GL_FRONT, GL_SPECULAR, [0.0, 0.0, 0.0, 1.0])
     glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 1.0, 0.0, 1.0])
     flashlight = GLU.gluNewQuadric()
     GLU.gluQuadricDrawStyle(flashlight, GLU.GLU_FILL)
     GLU.gluCylinder(flashlight, 0.3, 0.3, 1.5, 30, 30)
     GLU.gluCylinder(flashlight, 0.5, 0.3, 0.4, 30, 30)
     glPushMatrix()
     glTranslate(0, 0, 1.5)
     GLU.gluDisk(flashlight, 0.0, 0.3, 30, 30)
     glPopMatrix()
     glMaterialfv(GL_FRONT, GL_EMISSION, self.diffuse)
     GLU.gluDisk(flashlight, 0.0, 0.5, 30, 30)
     glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 0.0, 0.0, 1.0])
     glPopMatrix()
    def render(self):

        # create openGL list if render has not yet been called
        if not self.has_rendered:
            w = self.width
            h = self.height
            color1 = self.color1
            color2 = self.color2
            board_width = w * self.nrows
            board_height = h * self.nrows
            #gl.glDisable(gl.GL_LIGHTING)

            self.glListIndex = gl.glGenLists(1)
            gl.glNewList(self.glListIndex, gl.GL_COMPILE) # begin OpengGL list
            try:
                for x in range(0, self.nrows):
                    for y in range(0, self.nrows):
                        if (x + y) % 2 == 0:
                            gl.glColor3f(*color1)
                        else:
                            gl.glColor3f(*color2)
                        gl.glRectf(w*x, h*y, w*(x + 1), h*(y + 1))

                if self.show_fixation_dot:
                    gl.glColor3f(*COLORS['red'])
                    gl.glTranslatef(board_width / 2.0, board_height / 2.0, 0)
                    glu.gluDisk(glu.gluNewQuadric(), 0, 0.005, 45, 1)

            finally:
                pass
                #gl.glEnable(gl.GL_LIGHTING)
            gl.glEndList()  # end OpenGL list
            self.has_rendered = True

        # display checkerboard
        gl.glDisable(gl.GL_LIGHTING)
        gl.glCallList(self.glListIndex)
        gl.glEnable(gl.GL_LIGHTING)
    def render(self):
        color1 = self.color1
        color2 = self.color2

        # create display lists if not yet done
        if self.display_list_multi is None:
            w = self.check_width
            h = self.check_height
            board_width = w * self.nrows
            board_height = h * self.nrows

            # get needed display list ints
            if self.fixation_dot_color:
                self.num_lists = 3  # include list for fixation dot
            else:
                self.num_lists = 2
            self.display_list_multi = gl.glGenLists(self.num_lists)

            # Create a display list for color 1
            try:
                gl.glNewList(self.display_list_multi, gl.GL_COMPILE)

                # render the checkerboard's color1 checks
                gl.glDisable(gl.GL_LIGHTING)
                for x in range(0, self.nrows):
                    for y in range(0, self.nrows):
                        if (x + y) % 2 == 0:
                            gl.glRectf(w*x, h*y, w*(x + 1), h*(y + 1))
            finally:
                gl.glEnable(gl.GL_LIGHTING)
                # End the display list
                gl.glEndList()

            # create a display list for color 2
            try:
                gl.glNewList(self.display_list_multi + 1, gl.GL_COMPILE)

                # render the checkerboard's color2 checks
                gl.glDisable(gl.GL_LIGHTING)
                for x in range(0, self.nrows):
                    for y in range(0, self.nrows):
                        if (x + y) % 2 == 1:
                            gl.glRectf(w*x, h*y, w*(x + 1), h*(y + 1))
            finally:
                gl.glEnable(gl.GL_LIGHTING)
                # End the display list
                gl.glEndList()

            # create list for fixation dot
            if not self.fixation_dot_color is None:
                gl.glNewList(self.display_list_multi + 2, gl.GL_COMPILE)
                gl.glDisable(gl.GL_LIGHTING)
                r, g, b = self.fixation_dot_color
                gl.glColor3f(r, g, b)
                gl.glTranslatef(board_width / 2.0, board_height / 2.0, 0)
                glu.gluDisk(glu.gluNewQuadric(), 0, 0.005, 45, 1)
                gl.glEnable(gl.GL_LIGHTING)
                gl.glEndList()

            self.show_display_lists(color1, color2)

        else:
            # render display lists
            self.show_display_lists(color1, color2)
Exemple #54
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()
Exemple #55
0
 def to_OpenGL(self, color=None, show_directions=False):
     if not GL_enabled:
         return
     if not color is None:
         GL.glColor4f(*color)
     GL.glBegin(GL.GL_TRIANGLES)
     # use normals to improve lighting (contributed by imyrek)
     normal_t = self.normal
     GL.glNormal3f(normal_t.x, normal_t.y, normal_t.z)
     # The triangle's points are in clockwise order, but GL expects
     # counter-clockwise sorting.
     GL.glVertex3f(self.p1.x, self.p1.y, self.p1.z)
     GL.glVertex3f(self.p3.x, self.p3.y, self.p3.z)
     GL.glVertex3f(self.p2.x, self.p2.y, self.p2.z)
     GL.glEnd()
     if show_directions: # display surface normals
         n = self.normal
         c = self.center
         d = 0.5
         GL.glBegin(GL.GL_LINES)
         GL.glVertex3f(c.x, c.y, c.z)
         GL.glVertex3f(c.x+n.x*d, c.y+n.y*d, c.z+n.z*d)
         GL.glEnd()
     if False: # display bounding sphere
         GL.glPushMatrix()
         middle = self.middle
         GL.glTranslate(middle.x, middle.y, middle.z)
         if not hasattr(self, "_sphere"):
             self._sphere = GLU.gluNewQuadric()
         GLU.gluSphere(self._sphere, self.radius, 10, 10)
         GL.glPopMatrix()
     if pycam.Utils.log.is_debug(): # draw triangle id on triangle face
         GL.glPushMatrix()
         c = self.center
         GL.glTranslate(c.x, c.y, c.z)
         p12 = self.p1.add(self.p2).mul(0.5)
         p3_12 = self.p3.sub(p12).normalized()
         p2_1 = self.p1.sub(self.p2).normalized()
         pn = p2_1.cross(p3_12)
         GL.glMultMatrixf((p2_1.x, p2_1.y, p2_1.z, 0, p3_12.x, p3_12.y,
                 p3_12.z, 0, pn.x, pn.y, pn.z, 0, 0, 0, 0, 1))
         n = self.normal.mul(0.01)
         GL.glTranslatef(n.x, n.y, n.z)
         maxdim = max((self.maxx - self.minx), (self.maxy - self.miny),
                 (self.maxz - self.minz))
         factor = 0.001
         GL.glScalef(factor * maxdim, factor * maxdim, factor * maxdim)
         w = 0
         id_string = "%s." % str(self.id)
         for ch in id_string:
             w += GLUT.glutStrokeWidth(GLUT.GLUT_STROKE_ROMAN, ord(ch))
         GL.glTranslate(-w/2, 0, 0)
         for ch in id_string:
             GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(ch))
         GL.glPopMatrix()
     if False: # draw point id on triangle face
         c = self.center
         p12 = self.p1.add(self.p2).mul(0.5)
         p3_12 = self.p3.sub(p12).normalized()
         p2_1 = self.p1.sub(self.p2).normalized()
         pn = p2_1.cross(p3_12)
         n = self.normal.mul(0.01)
         for p in (self.p1, self.p2, self.p3):
             GL.glPushMatrix()
             pp = p.sub(p.sub(c).mul(0.3))
             GL.glTranslate(pp.x, pp.y, pp.z)
             GL.glMultMatrixf((p2_1.x, p2_1.y, p2_1.z, 0, p3_12.x, p3_12.y,
                     p3_12.z, 0, pn.x, pn.y, pn.z, 0, 0, 0, 0, 1))
             GL.glTranslatef(n.x, n.y, n.z)
             GL.glScalef(0.001, 0.001, 0.001)
             w = 0
             for ch in str(p.id):
                 w += GLUT.glutStrokeWidth(GLUT.GLUT_STROKE_ROMAN, ord(ch))
                 GL.glTranslate(-w/2, 0, 0)
             for ch in str(p.id):
                 GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(ch))
             GL.glPopMatrix()
Exemple #56
0
def draw_arrows(pos,
                edgelist,
                edge_color,
                arrow_points,
                arrow_size,
                scale,
                lights,
                fancy):

    GL.glDisable(GL.GL_DEPTH_TEST)
    if lights:
        GL.glEnable(GL.GL_LIGHTING)
    k = 0
    for (i,j) in edgelist:
        d = []
        for r in range(len(pos[i])):
            d.append(pos[i][r]-pos[j][r])
        d = tuple(d + [0])
        GL.glPushMatrix()

        GL.glTranslate(arrow_points[k][0][0],
                       arrow_points[k][0][1],
                       arrow_points[k][0][2])
        GL.glScale(scale,scale,scale)
        GL.glRotate(arrow_points[k][1],-d[1],d[0],0)

        GL.glColor(*edge_color[k])
        vp = GL.glGetIntegerv(GL.GL_VIEWPORT)
        arrow_size_scale = 2./(vp[2]+vp[3])
        if fancy:
            cone = GLU.gluNewQuadric()
            GLU.gluQuadricNormals(cone,GLU.GLU_SMOOTH)
            GLU.gluQuadricTexture(cone,GLU.GLU_TRUE)
            GLU.gluCylinder(cone,
                            0,
                            arrow_size_scale*arrow_size[k]/3.,
                            arrow_size_scale*arrow_size[k],
                            32,
                            32)
        else:
            s1 = arrow_size[k]*arrow_size_scale
            s2 = arrow_size_scale*arrow_size[k]/3.
            GL.glBegin(GL.GL_POLYGON);
            GL.glVertex3d(0, 0, 0);
            GL.glVertex3d(-s2, s2, s1);
            GL.glVertex3d(-s2, -s2, s1);

            GL.glVertex3d(0, 0, 0);
            GL.glVertex3d(-s2, s2, s1);
            GL.glVertex3d(s2, s2, s1);

            GL.glVertex3d(0, 0, 0);
            GL.glVertex3d(s2, s2, s1);
            GL.glVertex3d(s2, -s2, s1);

            GL.glVertex3d(0, 0, 0);
            GL.glVertex3d(s2, -s2, s1);
            GL.glVertex3d(-s2, -s2, s1);

            GL.glVertex3d(-s2, -s2, s1);
            GL.glVertex3d(s2, -s2, s1);
            GL.glVertex3d(s2, s2, s1);
            GL.glVertex3d(-s2, s2, s1);
            GL.glEnd();
        GL.glPopMatrix()
        k+=1
    if lights:
        GL.glDisable(GL.GL_LIGHTING)
    GL.glEnable(GL.GL_DEPTH_TEST)
def drawSphere(s,color=cyan,ndiv=8):
    """Draws a centered sphere with radius s in given color."""
    quad = GLU.gluNewQuadric()
    GLU.gluQuadricNormals(quad, GLU.GLU_SMOOTH)
    GL.glColor(*color)
    GLU.gluSphere(quad,s,ndiv,ndiv)