Esempio n. 1
0
    def draw_light_source(self):

        glColor3f(1.0, 1.0, 1.0)

        # 15 is radius of the sphere that light source around
        self.light_source_position = [
            15 * sin(self.theta_light_angle * pi / 180) *
            sin(self.phi_light_angle * pi / 180),
            15 * cos(self.theta_light_angle * pi / 180),
            15 * sin(self.theta_light_angle * pi / 180) *
            cos(self.phi_light_angle * pi / 180)
        ]

        glTranslate(self.light_source_position[0],
                    self.light_source_position[1],
                    self.light_source_position[2])
        # set light source position
        glLightfv(GL_LIGHT0, GL_POSITION, [*self.light_source_position, 1])
        # set light color
        glLightfv(GL_LIGHT0, GL_DIFFUSE, self.light_color)
        # set light intensity
        glLightfv(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.7)
        glLightfv(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0001)

        # turning the rays of light so that the back of the ball is shaded
        gl_q = gluNewQuadric()
        gluQuadricOrientation(gl_q, GLU_INSIDE)

        # draw visual envelope (ball)
        gluSphere(gl_q, 1, 20, 20)

        glLoadIdentity()
Esempio n. 2
0
    def draw_arrow(self, color):

        # Set material
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color)
        #glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color)
        #glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [1, 1, 1, 0.0])
        #glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 20)

        # Draw cylinder
        quad = gluNewQuadric()
        gluQuadricDrawStyle(quad, GLU_FILL)
        gluQuadricTexture(quad, True)
        gluQuadricNormals(quad, GLU_SMOOTH)
        gluCylinder(quad, self.size / 30, self.size / 30,
                    self.size * 0.8, 20, 20)

        # Move to the arrowhead position
        glTranslatef(0, 0, self.size * 0.8)

        # Draw arrowhead
        gluQuadricDrawStyle(quad, GLU_FILL)
        gluQuadricTexture(quad, True)
        gluQuadricNormals(quad, GLU_SMOOTH)
        gluCylinder(quad, self.size / 15, 0,
                    self.size * 0.2, 20, 20)

        # Revert to the original position
        glTranslatef(0, 0, -self.size * 0.8)
Esempio n. 3
0
File: draw.py Progetto: imc/pymt
def drawStippledCircle(pos=(0,0), inner_radius=200, outer_radius=400, segments=10):
    '''
    Draw a stippled circle. A stippled circle consists of several equally-sized
    segments, with a gap between every two segments. The gap is the size of a
    segment. The circle's position and thickness can be specified.

    :Parameters:
        `pos` : tuple, default to (0, 0)
            Center position of the circle
        `inner_radius` : int, default to 100
            Radius of the inner circle
        `outer_radius` : int, default to 120
            Radius of the outer circle
        `segments` : int, defaults to 10
            Number of visible segments
    '''
    angle_delta = (360/segments)/2
    current_angle = 0
    quadric = gluNewQuadric()
    with gx_matrix:
        glTranslatef(pos[0], pos[1], 0)
        for i in range(segments):
            next_angle = current_angle + angle_delta
            gluPartialDisk(quadric, inner_radius, outer_radius, 32, 1, current_angle, angle_delta)
            # For the stipple effect, leave a part of the Disk out
            current_angle = next_angle + angle_delta
Esempio n. 4
0
def make_sphere():
    """create ball's rend function list"""
    glNewList(G_OBJ_SPHERE, GL_COMPILE)
    quad = gluNewQuadric()
    gluSphere(quad, 0.5, 30, 30)
    gluDeleteQuadric(quad)
    glEndList()
Esempio n. 5
0
 def drawBallAndStick(self, r_ball = 0.4, r_stick = 0.1):
     res = self.quality * 6
     quad = gluNewQuadric()
     glNewList(1,GL_COMPILE)
     for i in range(self.mol.natoms):
         glPushMatrix()
         # set atom color
         r,g,b = self.mol.col[i]
         glColor3f(r,g,b)
         # translate to atom position
         x,y,z = self.mol.pos[i]
         glTranslatef(x,y,z)
         # draw the atom
         gluSphere(quad, r_ball*self.mol.rad[i], res, res)
         glPopMatrix()
     for i,c in enumerate(self.mol.con):
         m = c[0]
         n = c[1]
         glPushMatrix()
         # set bond color
         r,g,b = self.mol.col[m]
         glColor3f(r,g,b)
         # translate to atom position
         x,y,z = self.mol.pos[m]
         glTranslatef(x,y,z)
         # draw the bond
         v = self.mol.pos[n] - self.mol.pos[m]
         angle = math.acos(numpy.dot([0.0,0.0,1.0], v)/self.mol.dist[i])*180./math.pi
         x,y,z = numpy.cross([0.0,0.0,1.0], v)
         glRotatef(angle,x,y,z)
         h = self.mol.dist[i] * self.mol.rad[m] / (self.mol.rad[m] + self.mol.rad[n])
         gluCylinder(quad, r_stick, r_stick, h, res, res)
         glPopMatrix()
     glEndList()
Esempio n. 6
0
def drawSemiCircle(pos=(0, 0),
                   inner_radius=100,
                   outer_radius=120,
                   slices=32,
                   loops=1,
                   start_angle=0,
                   sweep_angle=360):
    '''Draw a semi-circle. You can choose the start angle,
    and the ending angle (from 0 to 360), and the inner/outer radius !

    :Parameters:
        `pos`: tuple, default to (0, 0)
            Center position of the circle
        `inner_radius`: int, default to 100
            Radius of the inner circle
        `outer_radius`: int, default to 120
            Radius of the outer circle
        `slices`: int, default to 32
            Precision of circle drawing
        `start_angle`: int, default to 0
            Angle to start drawing
        `sweep_angle`: int, default to 360
            Angle to finish drawing
    '''
    with gx_matrix:
        glTranslatef(pos[0], pos[1], 0)
        gluPartialDisk(gluNewQuadric(), inner_radius, outer_radius, slices,
                       loops, start_angle, sweep_angle)
Esempio n. 7
0
def make_Cylinder():  #2
    #glNewList(G_OBJ_PLANE, GL_COMPILE)                             #2
    #glLineWidth(50.0)                                              #2
    #glColor3f(0.0, 0.0, 0.0)                                       #2
    #glBegin(GL_LINES)                                              #2
    #glVertex3f(1.0, 0.0, 0.0)                                      #2
    #glVertex3f(0.0, 1.0, 0.0)                                      #2
    #glEnd()                                                        #2
    #2
    #glColor3f(1.0, 0.0, 0.0)                                       #2
    #glBegin(GL_TRIANGLE_STRIP)                                     #2
    #glVertex3f(1.000000 ,0.000000, 0.000000)
    #glVertex3f(0.000000, 1.000000, 0.000000)
    #glVertex3f(1.000000, 1.000000, 1.000000)
    #glEnd()

    glNewList(G_OBJ_CYLINDER, GL_COMPILE)

    quad = gluNewQuadric()

    gluCylinder(quad, 0.2, 0.2, 2.0, 32, 32)  #半径半径长切分次数切分次数

    #glRotatef(2, 0, 0, 1)

    gluDeleteQuadric(quad)

    glEndList()  #2
Esempio n. 8
0
def make_sphere():
    """ 创建球形的渲染函数列表 """
    glNewList(G_OBJ_SPHERE, GL_COMPILE)
    quad = gluNewQuadric()
    gluSphere(quad, 0.5, 30, 30)
    gluDeleteQuadric(quad)
    glEndList()
Esempio n. 9
0
def drawStippledCircle(
        pos=(0, 0), inner_radius=200, outer_radius=400, segments=10):
    '''
    Draw a stippled circle. A stippled circle consists of several equally-sized
    segments, with a gap between every two segments. The gap is the size of a
    segment. The circle's position and thickness can be specified.

    :Parameters:
        `pos`: tuple, default to (0, 0)
            Center position of the circle
        `inner_radius`: int, default to 100
            Radius of the inner circle
        `outer_radius`: int, default to 120
            Radius of the outer circle
        `segments`: int, defaults to 10
            Number of visible segments
    '''
    angle_delta = (360 / segments) / 2
    current_angle = 0
    quadric = gluNewQuadric()
    with gx_matrix:
        glTranslatef(pos[0], pos[1], 0)
        for i in range(segments):
            next_angle = current_angle + angle_delta
            gluPartialDisk(quadric, inner_radius, outer_radius, 32, 1,
                           current_angle, angle_delta)
            # For the stipple effect, leave a part of the Disk out
            current_angle = next_angle + angle_delta
Esempio n. 10
0
def drawCircle(pos=(0, 0), radius=1.0, linewidth=0):
    '''Draw a simple circle

    :Parameters:
        `pos`: tuple, default to (0, 0)
            Position of circle
        `radius`: float, default to 1.0
            Radius of circle
    '''
    x, y = pos[0], pos[1]
    with gx_matrix:
        glTranslatef(x, y, 0)
        glScalef(radius, radius, 1.0)
        if linewidth > 0:
            gluDisk(gluNewQuadric(), 1 - linewidth / float(radius), 1, 32, 1)
        else:
            gluDisk(gluNewQuadric(), 0, 1, 32, 1)
Esempio n. 11
0
File: draw.py Progetto: imc/pymt
def drawCircle(pos=(0,0), radius=1.0, linewidth=0):
    '''Draw a simple circle

    :Parameters:
        `pos` : tuple, default to (0, 0)
            Position of circle
        `radius` : float, default to 1.0
            Radius of circle
    '''
    x, y = pos[0], pos[1]
    with gx_matrix:
        glTranslatef(x, y, 0)
        glScalef(radius, radius, 1.0)
        if linewidth > 0:
            gluDisk(gluNewQuadric(), 1-linewidth/float(radius), 1, 32,1)
        else:
            gluDisk(gluNewQuadric(), 0, 1, 32,1)
Esempio n. 12
0
    def _C_quadric(self):
        """
        set up self.quadric
        """
        # see PyOpenGL Demo/NeHe/lesson18.py
        quadric = gluNewQuadric() #e it may be that this object could be shared by all instances, or even more globally -- not sure
        gluQuadricNormals(quadric, GLU_SMOOTH) # Create Smooth Normals
##        gluQuadricTexture(quadric, GL_TRUE)    # Create Texture Coords
        return quadric
Esempio n. 13
0
    def paint(self):
        if self.quad is None:
            self.quad = gluNewQuadric()

        glPushMatrix()
        glColor(self.color.red, self.color.green, self.color.blue)
        glTranslate(self.center.x, self.center.y, self.center.z)
        gluSphere(self.quad, self.radius, 25, 25)
        glPopMatrix()
Esempio n. 14
0
 def _C_quadric(self):
     """
     set up self.quadric
     """
     # see PyOpenGL Demo/NeHe/lesson18.py
     quadric = gluNewQuadric(
     )  #e it may be that this object could be shared by all instances, or even more globally -- not sure
     gluQuadricNormals(quadric, GLU_SMOOTH)  # Create Smooth Normals
     ##        gluQuadricTexture(quadric, GL_TRUE)    # Create Texture Coords
     return quadric
Esempio n. 15
0
def draw_sphere(coords, radius, color_s=BLUE):
    quad: gluNewQuadric = gluNewQuadric()
    gluQuadricDrawStyle(quad, GLU_LINE)
    glColor3f(color_s[0], color_s[1], color_s[2])

    glPushMatrix()
    glTranslatef(coords[0], coords[1], coords[2])

    gluSphere(quad, radius, 12, 12)
    glPopMatrix()
Esempio n. 16
0
    def draw(self, from_fixed_frame: bool = True):
        self.opgl_move_to_pose(from_fixed_frame)
        self.apply_material()

        # draw sphere
        quad = gluNewQuadric()
        gluQuadricDrawStyle(quad, GLU_FILL)
        gluQuadricTexture(quad, True)
        gluQuadricNormals(quad, GLU_SMOOTH)
        gluSphere(quad, self.radius, 20, 20)
Esempio n. 17
0
    def draw(self, from_fixed_frame: bool = True):
        self.opgl_move_to_pose(from_fixed_frame)
        self.apply_material()

        # draw sphere
        quad = gluNewQuadric()
        gluQuadricDrawStyle(quad, GLU_FILL)
        gluQuadricTexture(quad, True)
        gluQuadricNormals(quad, GLU_SMOOTH)
        gluSphere(quad, self.radius, 20, 20)
Esempio n. 18
0
    def draw(self, from_fixed_frame: bool = True):
        self.opgl_move_to_pose(from_fixed_frame)
        self.apply_material()

        # draw parallelepiped
        quad = gluNewQuadric()
        gluQuadricDrawStyle(quad, GLU_FILL)
        gluQuadricTexture(quad, True)
        gluQuadricNormals(quad, GLU_SMOOTH)
        glScalef(self.length, self.width, self.height)
        glutSolidCube(1)
Esempio n. 19
0
    def draw(self, from_fixed_frame: bool = True):
        self.opgl_move_to_pose(from_fixed_frame)
        self.apply_material()

        # draw parallelepiped
        quad = gluNewQuadric()
        gluQuadricDrawStyle(quad, GLU_FILL)
        gluQuadricTexture(quad, True)
        gluQuadricNormals(quad, GLU_SMOOTH)
        glScalef(self.length, self.width, self.height)
        glutSolidCube(1)
Esempio n. 20
0
 def paintCylinder(self, diameter, height):
     r = diameter / 70.
     height = 2 * height / 70.
     glColor3f(0., 0., 0.)
     glPushMatrix()
     glTranslatef(*self.offsets)  # move down
     glRotatef(-90., 1., 0., 0.)
     quadric = gluNewQuadric()
     gluQuadricDrawStyle(quadric, GLU_LINE)
     slices = max(int(round(r * 32)), 15)
     gluCylinder(quadric, r, r, height, slices, 1)
     glPopMatrix()
Esempio n. 21
0
 def draw_pin(self, x, y):
     glPushMatrix()
     glColor3f(1.0, 1.0, 0.0)
     glTranslatef(x, 0.0, -y) 
     glRotatef(-90, 1.0, 0.0, 0.0)
     obj = gluNewQuadric()
     gluCylinder(obj, 0.05, 0.05, 0.5, 10, 10)
     glPushMatrix()
     gluDisk(obj, 0.0, 0.05, 10, 10)
     glTranslatef(0.0, 0.5, 0.0) 
     glPopMatrix()
     glPopMatrix()
Esempio n. 22
0
 def __init__(self, position, color, radius=2):
     self.radius = radius
     ballShape = SphereShape(self.radius)
     ballTransform = Transform()
     ballTransform.setIdentity()
     ballTransform.setOrigin(position)
     ballMotion = DefaultMotionState()
     ballMotion.setWorldTransform(ballTransform)
     self.body = RigidBody(ballMotion, ballShape, 2.0)
     self.body.setRestitution(0.9)
     self.motion = ballMotion
     self.quad = gluNewQuadric()
     self.color = color
Esempio n. 23
0
 def __init__(self, position, color, radius=2):
     self.radius = radius
     ballShape = SphereShape(self.radius)
     ballTransform = Transform()
     ballTransform.setIdentity()
     ballTransform.setOrigin(position)
     ballMotion = DefaultMotionState()
     ballMotion.setWorldTransform(ballTransform)
     self.body = RigidBody(ballMotion, ballShape, 2.0)
     self.body.setRestitution(0.9)
     self.motion = ballMotion
     self.quad = gluNewQuadric()
     self.color = color
Esempio n. 24
0
    def draw_led(self, x, y, color):
        glPushMatrix()
        
        if color < 0:
            glColor3f(*self.color_led_red)
        else:
            glColor3f(*self.color_led_green)

        glTranslatef(x, 0.1, -y) 
        glRotatef(-90, 1.0, 0.0, 0.0)
        obj = gluNewQuadric()
        gluSphere(obj, 0.15, 10, 10)
        
        glPopMatrix()
Esempio n. 25
0
    def __init__(self, parent) -> None:
        """Initializes _Axes with constructors."""
        self.parent = parent

        self._vao_axes = None
        self._vao_arrows = None

        build_dimensions = self.parent.build_dimensions
        dist = 0.5 * (build_dimensions[1] +
                      max(build_dimensions[0], build_dimensions[2]))
        self._arrow_base_radius = dist / 75.0
        self._arrow_length = 2.5 * self._arrow_base_radius
        self._quadric = gluNewQuadric()
        gluQuadricDrawStyle(self._quadric, GLU_FILL)
Esempio n. 26
0
 def initialize_draw(self):
     self.quadric = gluNewQuadric()
     gluQuadricNormals(self.quadric, GLU_SMOOTH)
     self.set_specular(True)
     self.set_bright(False)
     glLight(GL_LIGHT0, GL_SPECULAR, [0.7, 0.7, 0.7, 1.0])
     glLight(GL_LIGHT0, GL_AMBIENT, [0.1, 0.1, 0.1, 1.0])
     glLight(GL_LIGHT0, GL_POSITION, [1.0, 1.0, 3.0, 0.0])
     glEnable(GL_LIGHT0)
     glEnable(GL_LIGHTING)
     glDepthFunc(GL_LESS)
     glEnable(GL_DEPTH_TEST)
     glCullFace(GL_BACK)
     VisBackend.initialize_draw(self)
     self.tool.initialize_gl()
Esempio n. 27
0
 def initialize_draw(self):
     self.quadric = gluNewQuadric()
     gluQuadricNormals(self.quadric, GLU_SMOOTH)
     self.set_specular(True)
     self.set_bright(False)
     glLight(GL_LIGHT0, GL_SPECULAR, [0.7, 0.7, 0.7, 1.0])
     glLight(GL_LIGHT0, GL_AMBIENT, [0.1, 0.1, 0.1, 1.0])
     glLight(GL_LIGHT0, GL_POSITION, [1.0, 1.0, 3.0, 0.0])
     glEnable(GL_LIGHT0)
     glEnable(GL_LIGHTING)
     glDepthFunc(GL_LESS)
     glEnable(GL_DEPTH_TEST)
     glCullFace(GL_BACK)
     VisBackend.initialize_draw(self)
     self.tool.initialize_gl()
Esempio n. 28
0
	def prepDraw(self):
		glNewList(self.dl,GL_COMPILE)
		
		c = self.corners
		for h in c:
			glPushMatrix(  )
			glTranslatef(h.x,h.y,h.z)
			q = gluNewQuadric()
			gluSphere( q, GLdouble(0.45), GLint(10), GLint(10) )
			glPopMatrix(  )

		glBegin(GL_QUADS)

		glVertex3fv(adaptVec(c[0]))
		glVertex3fv(adaptVec(c[2]))
		glVertex3fv(adaptVec(c[6]))
		glVertex3fv(adaptVec(c[4]))

		glVertex3fv(adaptVec(c[1]))
		glVertex3fv(adaptVec(c[3]))
		glVertex3fv(adaptVec(c[7]))
		glVertex3fv(adaptVec(c[5]))

		glVertex3fv(adaptVec(c[0]))
		glVertex3fv(adaptVec(c[1]))
		glVertex3fv(adaptVec(c[3]))
		glVertex3fv(adaptVec(c[2]))

		glVertex3fv(adaptVec(c[2]))
		glVertex3fv(adaptVec(c[3]))
		glVertex3fv(adaptVec(c[7]))
		glVertex3fv(adaptVec(c[6]))

		glVertex3fv(adaptVec(c[7]))
		glVertex3fv(adaptVec(c[6]))
		glVertex3fv(adaptVec(c[4]))
		glVertex3fv(adaptVec(c[5]))

		glVertex3fv(adaptVec(c[0]))
		glVertex3fv(adaptVec(c[1]))
		glVertex3fv(adaptVec(c[5]))
		glVertex3fv(adaptVec(c[4]))

		glEnd()
		glEndList()
Esempio n. 29
0
    def prepDraw(self):
        glNewList(self.dl, GL_COMPILE)

        c = self.corners
        for h in c:
            glPushMatrix()
            glTranslatef(h.x, h.y, h.z)
            q = gluNewQuadric()
            gluSphere(q, GLdouble(0.45), GLint(10), GLint(10))
            glPopMatrix()

        glBegin(GL_QUADS)

        glVertex3fv(adaptVec(c[0]))
        glVertex3fv(adaptVec(c[2]))
        glVertex3fv(adaptVec(c[6]))
        glVertex3fv(adaptVec(c[4]))

        glVertex3fv(adaptVec(c[1]))
        glVertex3fv(adaptVec(c[3]))
        glVertex3fv(adaptVec(c[7]))
        glVertex3fv(adaptVec(c[5]))

        glVertex3fv(adaptVec(c[0]))
        glVertex3fv(adaptVec(c[1]))
        glVertex3fv(adaptVec(c[3]))
        glVertex3fv(adaptVec(c[2]))

        glVertex3fv(adaptVec(c[2]))
        glVertex3fv(adaptVec(c[3]))
        glVertex3fv(adaptVec(c[7]))
        glVertex3fv(adaptVec(c[6]))

        glVertex3fv(adaptVec(c[7]))
        glVertex3fv(adaptVec(c[6]))
        glVertex3fv(adaptVec(c[4]))
        glVertex3fv(adaptVec(c[5]))

        glVertex3fv(adaptVec(c[0]))
        glVertex3fv(adaptVec(c[1]))
        glVertex3fv(adaptVec(c[5]))
        glVertex3fv(adaptVec(c[4]))

        glEnd()
        glEndList()
Esempio n. 30
0
File: draw.py Progetto: imc/pymt
def drawSemiCircle(pos=(0,0), inner_radius=100, outer_radius=120, slices=32, loops=1, start_angle=0, sweep_angle=360):
    '''Draw a semi-circle. You can choose the start angle,
    and the ending angle (from 0 to 360), and the inner/outer radius !

    :Parameters:
        `pos` : tuple, default to (0, 0)
            Center position of the circle
        `inner_radius` : int, default to 100
            Radius of the inner circle
        `outer_radius` : int, default to 120
            Radius of the outer circle
        `slices` : int, default to 32
            Precision of circle drawing
        `start_angle` : int, default to 0
            Angle to start drawing
        `sweep_angle` : int, default to 360
            Angle to finish drawing
    '''
    with gx_matrix:
        glTranslatef(pos[0], pos[1], 0)
        gluPartialDisk(gluNewQuadric(), inner_radius, outer_radius, slices, loops, start_angle, sweep_angle)
Esempio n. 31
0
 def paintArrow(self, direction, color):
     d = 0.01
     length = 0.5
     glPushMatrix()
     glColor3fv(color)
     if direction == 'n':
         glTranslatef(0., -1.1, 2.)
     elif direction == 'gamma':
         glTranslatef(1.2, -1.1, 0.)
     else:
         glTranslatef(-1., -1., 1.)
     quadric = gluNewQuadric()
     if direction in ('x', 'gamma'):
         glRotatef(90., 0., 1., 0.)
     elif direction == 'y':
         glRotatef(90, -1., 0., 0.)
     elif direction in ('z', 'n'):
         glRotatef(180, -1, 0, 0)
     gluCylinder(quadric, d, d, length, 48, 48)
     glTranslatef(0, 0, length)
     glutSolidCone(2. * d, 0.1, 48, 48)
     glPopMatrix()
Esempio n. 32
0
    def _fan_(self):
        '''
        '''
        i_r = 0
        o_r = 1
        glPushMatrix()

        glRotatef(90, 1, 0, 0)
        # blades=[-15,-15+45,-15+90]

        sweep = 30
        nblades = 8
        for start in [-15] * nblades:
            glRotatef(-360.0 / nblades, 0, 0, 1)
            glPushMatrix()
            glRotatef(25, 0 + math.cos(start), 1, 0)
            # glRotatef(5,math.sin(start),math.cos(start),0)

            gluPartialDisk(gluNewQuadric(), i_r, o_r, xseg, yseg,
                           start, sweep
                           )
            glPopMatrix()
        glPopMatrix()
Esempio n. 33
0
 def drawBallAndStick(self, r_ball=0.4, r_stick=0.1):
     res = self.quality * 6
     quad = gluNewQuadric()
     glNewList(1, GL_COMPILE)
     for i in range(self.mol.natoms):
         glPushMatrix()
         # set atom color
         r, g, b = self.mol.col[i]
         glColor3f(r, g, b)
         # translate to atom position
         x, y, z = self.mol.pos[i]
         glTranslatef(x, y, z)
         # draw the atom
         gluSphere(quad, r_ball * self.mol.rad[i], res, res)
         glPopMatrix()
     for i, c in enumerate(self.mol.con):
         m = c[0]
         n = c[1]
         glPushMatrix()
         # set bond color
         r, g, b = self.mol.col[m]
         glColor3f(r, g, b)
         # translate to atom position
         x, y, z = self.mol.pos[m]
         glTranslatef(x, y, z)
         # draw the bond
         v = self.mol.pos[n] - self.mol.pos[m]
         angle = math.acos(
             numpy.dot([0.0, 0.0, 1.0], v) /
             self.mol.dist[i]) * 180. / math.pi
         x, y, z = numpy.cross([0.0, 0.0, 1.0], v)
         glRotatef(angle, x, y, z)
         h = self.mol.dist[i] * self.mol.rad[m] / (self.mol.rad[m] +
                                                   self.mol.rad[n])
         gluCylinder(quad, r_stick, r_stick, h, res, res)
         glPopMatrix()
     glEndList()
Esempio n. 34
0
    def __init__(self, mesh):
        self.outline_color = (1, 1, 1)
        vertices = mesh.vertex_list.getVertices()
        minV = Vector3()
        maxV = Vector3()
        vertices.sort(lambda x, y: cmp(y.x, x.x))
        minV.x = vertices[0].x
        maxV.x = vertices[-1].x
        vertices.sort(lambda x, y: cmp(y.y, x.y))
        minV.y = vertices[0].y
        maxV.y = vertices[-1].y
        vertices.sort(lambda x, y: cmp(y.z, x.z))
        minV.z = vertices[0].z
        maxV.z = vertices[-1].z

        self.points = []
        for i in range(8):
            self.points.append(Vector3())
        for i in range(2):
            for j in range(2):
                self.points[int('%d%d%d' % (0, i, j), 2)].x = minV.x
                self.points[int('%d%d%d' % (1, i, j), 2)].x = maxV.x
                self.points[int('%d%d%d' % (i, 0, j), 2)].y = minV.y
                self.points[int('%d%d%d' % (i, 1, j), 2)].y = maxV.y
                self.points[int('%d%d%d' % (i, j, 0), 2)].z = minV.z
                self.points[int('%d%d%d' % (i, j, 1), 2)].z = maxV.z

        self.center = Vector3()
        for p in self.points:
            self.center += p
        self.center /= float(8)
        self.dl = glGenLists(1)
        glNewList(self.dl, GL_COMPILE)
        glLineWidth(5)
        c = self.outline_color
        glColor4f(c[0], c[1], c[2], 0.2)
        glBegin(GL_LINE_STRIP)
        for v in self.points:
            glVertex(v())
        glEnd()
        c = self.points
        glBegin(GL_LINES)

        glVertex(c[0]())
        glVertex(c[2]())
        glVertex(c[6]())
        glVertex(c[4]())

        glVertex(c[1]())
        glVertex(c[3]())
        glVertex(c[7]())
        glVertex(c[5]())

        glVertex(c[0]())
        glVertex(c[1]())
        glVertex(c[3]())
        glVertex(c[2]())

        glVertex(c[2]())
        glVertex(c[3]())
        glVertex(c[7]())
        glVertex(c[6]())

        glVertex(c[7]())
        glVertex(c[6]())
        glVertex(c[4]())
        glVertex(c[5]())

        glVertex(c[0]())
        glVertex(c[1]())
        glVertex(c[5]())
        glVertex(c[4]())

        glEnd()
        glPushMatrix()
        glTranslatef(self.center.x, self.center.y, self.center.z)
        q = gluNewQuadric()
        gluSphere(q, GLdouble(0.25), GLint(10), GLint(10))
        glPopMatrix()
        glEndList()
Esempio n. 35
0
 def _disk_(self, radius=1, inner_radius=0):
     '''
     '''
     gluDisk(gluNewQuadric(), inner_radius, radius, xseg, yseg)
Esempio n. 36
0
 def _cylinder_(self, r, h, rotate=True):
     '''
     '''
     if rotate:
         glRotatef(90, 1, 0, 0)
     gluCylinder(gluNewQuadric(), r, r, h, xseg, yseg)
Esempio n. 37
0
 def InitGL(self):
     # set viewing projection
     glMatrixMode(GL_PROJECTION)
     glLoadIdentity()
     glOrtho(0, self.model.L, 0, self.model.L, -1, 1)
     self.quadricObject = gluNewQuadric()
Esempio n. 38
0
def make_sphere(n=30):
    glNewList(G_OBJ_SPHERE, GL_COMPILE)
    quad = gluNewQuadric()
    gluSphere(quad, 1.0, n, n)
    gluDeleteQuadric(quad)
    glEndList()
Esempio n. 39
0
    def __init__(self, mesh):
        self.outline_color = (1, 1, 1)
        vertices = mesh.vertex_list.getVertices()
        minV = Vector3()
        maxV = Vector3()
        vertices.sort(lambda x, y: cmp(y.x, x.x))
        minV.x = vertices[0].x
        maxV.x = vertices[-1].x
        vertices.sort(lambda x, y: cmp(y.y, x.y))
        minV.y = vertices[0].y
        maxV.y = vertices[-1].y
        vertices.sort(lambda x, y: cmp(y.z, x.z))
        minV.z = vertices[0].z
        maxV.z = vertices[-1].z

        self.points = []
        for i in range(8):
            self.points.append(Vector3())
        for i in range(2):
            for j in range(2):
                self.points[int("%d%d%d" % (0, i, j), 2)].x = minV.x
                self.points[int("%d%d%d" % (1, i, j), 2)].x = maxV.x
                self.points[int("%d%d%d" % (i, 0, j), 2)].y = minV.y
                self.points[int("%d%d%d" % (i, 1, j), 2)].y = maxV.y
                self.points[int("%d%d%d" % (i, j, 0), 2)].z = minV.z
                self.points[int("%d%d%d" % (i, j, 1), 2)].z = maxV.z

        self.center = Vector3()
        for p in self.points:
            self.center += p
        self.center /= float(8)
        self.dl = glGenLists(1)
        glNewList(self.dl, GL_COMPILE)
        glLineWidth(5)
        c = self.outline_color
        glColor4f(c[0], c[1], c[2], 0.2)
        glBegin(GL_LINE_STRIP)
        for v in self.points:
            glVertex(v())
        glEnd()
        c = self.points
        glBegin(GL_LINES)

        glVertex(c[0]())
        glVertex(c[2]())
        glVertex(c[6]())
        glVertex(c[4]())

        glVertex(c[1]())
        glVertex(c[3]())
        glVertex(c[7]())
        glVertex(c[5]())

        glVertex(c[0]())
        glVertex(c[1]())
        glVertex(c[3]())
        glVertex(c[2]())

        glVertex(c[2]())
        glVertex(c[3]())
        glVertex(c[7]())
        glVertex(c[6]())

        glVertex(c[7]())
        glVertex(c[6]())
        glVertex(c[4]())
        glVertex(c[5]())

        glVertex(c[0]())
        glVertex(c[1]())
        glVertex(c[5]())
        glVertex(c[4]())

        glEnd()
        glPushMatrix()
        glTranslatef(self.center.x, self.center.y, self.center.z)
        q = gluNewQuadric()
        gluSphere(q, GLdouble(0.25), GLint(10), GLint(10))
        glPopMatrix()
        glEndList()
Esempio n. 40
0
def make_sphere():
    glNewList(G_OBJ_SPHERE, GL_COMPILE)
    quad = gluNewQuadric()
    gluSphere(quad, 0.5, 30, 30)
    gluDeleteQuadric(quad)
    glEndList()
Esempio n. 41
0
def _get_quadric():
   global _Quadric
   if not _Quadric:
      _Quadric = gluNewQuadric()
   return _Quadric