예제 #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()
예제 #2
1
 def _draw_cylinders(self, length, diffs):
     for x_translate, y_translate in diffs:
         gl.glPushMatrix()
         gl.glTranslate(x_translate, y_translate, 0)
         glu.gluCylinder(self.quad, self.bond_width, self.bond_width,
                         length, self.cylinder_resolution, 1)
         gl.glPopMatrix()
예제 #3
0
    def _glcylinder(quadric, radius, height, slices, stacks, loops):
        """
        Internal method to render a quadric cylinder with OpenGL commands

        @param quadric  The OpenGL quadric object
        @param radius   The radius of the cylinder's base.
        @param height   The height of the cylunder.
        @param slices   The number of subdivisions around the z-axis (similar to lines of longitude).
        @param stacks   The number of subdivisions along the z-axis (similar to lines of latitude).
        @param loops    The number of concentric rings about the origin into which the cylinder's base is subdivided.
        """
        GLU.gluCylinder(quadric, radius, radius, height, slices, stacks)

        # The positive Z-axis is the default direction fo Cylinder Quadrics in OpenGL.
        # The top disc is 'height' units away from the origin.
        with GLMatrixScope(GL.GL_MODELVIEW, False):        
            GL.glTranslate(0, 0, height);
            GLU.gluDisk(quadric, 0.0, radius, slices, loops)
        
        # The positive Z-axis is the default direction for Cylinder Quadrics in OpenGL.
        # The base disc renders at the origin, but must be rotated to face the opposite
        # along the negative z axis.
        with GLMatrixScope(GL.GL_MODELVIEW, False):        
            GL.glRotate(180, 0, 1, 0)
            GLU.gluDisk(quadric, 0.0, radius, slices, loops)
예제 #4
0
    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()
예제 #5
0
    def render(self, start, dir, length, width, color):

        if length > 0.0:
            # Compute the angle-axis rotation require to orient the vector along dir:
            up_vec = np.array([0.0, 0.0, 1.0])
            axis = np.cross(up_vec, dir)
            trip_prod = np.linalg.det(np.dstack((up_vec, dir, axis)))
            if trip_prod > 0:
                angle = np.arccos(np.dot(up_vec, dir))
            else:
                angle = 2 * np.pi - np.arccos(np.dot(up_vec, dir))

            # Draw the shaft using a cylinder:
            gl.glPushMatrix()
            gl.glColor3f(*color)
            gl.glTranslatef(*start)
            gl.glRotate((180.0 / np.pi) * angle, *axis)
            GLU.gluCylinder(self.quadric, width, width, length, 100, 10)
            gl.glPopMatrix()

            # Draw the head using a cylinder having zero width on top:
            gl.glPushMatrix()
            gl.glColor3f(*color)
            gl.glTranslatef(*start)
            gl.glRotate((180.0 / np.pi) * angle, *axis)
            gl.glTranslatef(0.0, 0.0, length)
            GLU.gluCylinder(self.quadric, 2.0 * width, 0.0, 0.1 * length, 100,
                            10)
            gl.glPopMatrix()
예제 #6
0
 def draw(self):
     y1, r1, y2, r2 = self.coords()
     if y1 > y2:
         tmp = y1
         y1 = y2
         y2 = tmp
         tmp = r1
         r1 = r2
         r2 = tmp
     GL.glPushMatrix()
     # GL creates cylinders along Z, so need to rotate
     z1 = y1
     z2 = y2
     GL.glRotatef(-90, 1, 0, 0)
     # need to translate the whole thing to z1
     GL.glTranslatef(0, 0, z1)
     # the cylinder starts out at Z=0
     GLU.gluCylinder(self.q, r1, r2, z2 - z1, 32, 1)
     # bottom cap
     GL.glRotatef(180, 1, 0, 0)
     GLU.gluDisk(self.q, 0, r1, 32, 1)
     GL.glRotatef(180, 1, 0, 0)
     # the top cap needs flipped and translated
     GL.glPushMatrix()
     GL.glTranslatef(0, 0, z2 - z1)
     GLU.gluDisk(self.q, 0, r2, 32, 1)
     GL.glPopMatrix()
     GL.glPopMatrix()
예제 #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
예제 #8
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()
예제 #9
0
 def _draw_cylinders(self, length, diffs):
     for x_translate, y_translate in diffs:
         gl.glPushMatrix()
         gl.glTranslate(x_translate, y_translate, 0)
         glu.gluCylinder(self.quad, self.bond_width, self.bond_width,
                         length, self.cylinder_resolution, 1)
         gl.glPopMatrix()
예제 #10
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
예제 #11
0
 def render_cylinder(self, pos, r, h, num_seg1=20, num_seg2=10):
     GL.glPushMatrix()
     GL.glTranslated(*pos)
     GLU.gluCylinder(self.quadric, r, r, h, num_seg1, num_seg2)
     GL.glRotatef(180, 1, 0, 0)
     GLU.gluDisk(self.quadric, 0.0, r, num_seg1, 1)
     GL.glRotatef(180, 1, 0, 0)
     GL.glTranslatef(0.0, 0.0, h)
     GLU.gluDisk(self.quadric, 0.0, r, num_seg1, 1)
     GL.glPopMatrix()
예제 #12
0
 def render_cylinder(self, pos, r, h, num_seg1=20, num_seg2=10):
     GL.glPushMatrix()
     GL.glTranslated(*pos)
     GLU.gluCylinder(self.quadric, r, r, h, num_seg1, num_seg2)
     GL.glRotatef(180, 1, 0, 0)
     GLU.gluDisk(self.quadric, 0.0, r, num_seg1, 1)
     GL.glRotatef(180, 1, 0, 0)
     GL.glTranslatef(0.0, 0.0, h)
     GLU.gluDisk(self.quadric, 0.0, r, num_seg1, 1)
     GL.glPopMatrix()
예제 #13
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()
예제 #14
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()
예제 #15
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()
예제 #16
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()
예제 #17
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()
예제 #18
0
 def draw_cylinder(self, inside, outside, height, base_thickness):
     gl.glRotate(180, 0.0, 1.0, 0.0)
     glu.gluDisk(self.quad, 0, outside, 100, 5)
     gl.glRotate(-180, 0.0, 1.0, 0.0)
     gl.glTranslatef(0.0, 0.0, height)
     glu.gluDisk(self.quad, inside, outside, 100, 5)
     gl.glTranslatef(0.0, 0.0, -height)
     gl.glTranslatef(0.0, 0.0, base_thickness)
     glu.gluQuadricOrientation(self.quad, glu.GLU_INSIDE)
     glu.gluCylinder(self.quad, inside, inside, height - base_thickness, 100, 1)
     glu.gluQuadricOrientation(self.quad, glu.GLU_OUTSIDE)
     glu.gluDisk(self.quad, 0, inside, 100, 5)
     gl.glTranslatef(0.0, 0.0, -base_thickness)
     glu.gluCylinder(self.quad, outside, outside, height, 100, 1)
예제 #19
0
 def _draw_projection(self, domain_object):
     logging.debug("Drawing Projection")
     gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE,  [0.8, 0.2, 0.2, 0.1])
     gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, [0.9, 0.5, 0.5, 0.3])
     gl.glMaterialfv(gl.GL_FRONT, gl.GL_EMISSION, [0.2, 0.1, 0.1, 0.1])
     gl.glEnable(gl.GL_BLEND)
     gl.glDepthMask(gl.GL_FALSE)
     gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
     if domain_object.projection_shape == 'Circle':
         glu.gluCylinder(self.quad, domain_object.radius_at_base, 0.0, domain_object.height_mm, 100, 1)
     else:
         self._square_pyrmid(domain_object.radius_at_base * 2.0, 0.0, domain_object.height_mm)
     gl.glDepthMask(gl.GL_TRUE)
     gl.glDisable(gl.GL_BLEND)
예제 #20
0
파일: run_gui.py 프로젝트: yangxi1209/pele
 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()
예제 #21
0
def drawCylinder(Start=np.array([0, 0, 0]),
                 End=np.array([1.0, 0.0, 0.0]),
                 Radius1=1.0,
                 Radius2=1.0,
                 Color=None):
    if type(Start) is not np.ndarray or type(End) is not np.ndarray:
        raise RuntimeError('Start and End need to be Numpy arrays.')

    Direction = End - Start
    Length = np.linalg.norm(Direction)
    if (Length <= 0.0):
        return
    Direction = Direction / Length

    # Find out the axis of rotation and angle of rotation to rotate the
    # gluCylinder (oriented along the z axis) into the desired direction
    Z = np.array([0., 0., 1.])
    Axis = np.cross(Z, Direction)
    Angle = math.acos(np.dot(Z, Direction)) * (180. / math.pi
                                               )  # Should be degrees

    gl.glPushMatrix()
    gl.glTranslate(Start[0], Start[1], Start[2])
    gl.glRotate(Angle, Axis[0], Axis[1], Axis[2])

    # Next the 6 faces
    if (Color != None):
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)  # Orig
        gl.glEnable(gl.GL_BLEND)

        gl.glColor4fv(Color)
    else:
        gl.glColor3f(0.0, 0.0, 0.0)

    # Draw cylinder
    # Bottom:
    glu.gluQuadricOrientation(QUADRIC, glu.GLU_INSIDE)
    glu.gluDisk(QUADRIC, 0, Radius1, 16, 1)

    glu.gluQuadricOrientation(QUADRIC, glu.GLU_OUTSIDE)
    glu.gluCylinder(QUADRIC, Radius1, Radius2, Length, 16, 1)

    # Top:
    gl.glTranslatef(0, 0, Length)
    glu.gluQuadricOrientation(QUADRIC, glu.GLU_OUTSIDE)
    glu.gluDisk(QUADRIC, 0, Radius2, 16, 1)

    gl.glPopMatrix()
예제 #22
0
 def draw_cylinder(self, inside, outside, height, base_thickness):
     gl.glRotate(180, 0.0, 1.0, 0.0)
     glu.gluDisk(self.quad, 0, outside, 100, 5)
     gl.glRotate(-180, 0.0, 1.0, 0.0)
     gl.glTranslatef(0.0, 0.0, height)
     glu.gluDisk(self.quad, inside, outside, 100, 5)
     gl.glTranslatef(0.0, 0.0, -height)
     gl.glTranslatef(0.0, 0.0, base_thickness)
     glu.gluQuadricOrientation(self.quad, glu.GLU_INSIDE)
     glu.gluCylinder(self.quad, inside, inside, height - base_thickness,
                     100, 1)
     glu.gluQuadricOrientation(self.quad, glu.GLU_OUTSIDE)
     glu.gluDisk(self.quad, 0, inside, 100, 5)
     gl.glTranslatef(0.0, 0.0, -base_thickness)
     glu.gluCylinder(self.quad, outside, outside, height, 100, 1)
예제 #23
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()
예제 #24
0
파일: glview.py 프로젝트: stirfoo/machtool
 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()
예제 #25
0
 def _draw_projection(self, domain_object):
     logging.debug("Drawing Projection")
     gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, [0.8, 0.2, 0.2, 0.1])
     gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, [0.9, 0.5, 0.5, 0.3])
     gl.glMaterialfv(gl.GL_FRONT, gl.GL_EMISSION, [0.2, 0.1, 0.1, 0.1])
     gl.glEnable(gl.GL_BLEND)
     gl.glDepthMask(gl.GL_FALSE)
     gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
     if domain_object.projection_shape == 'Circle':
         glu.gluCylinder(self.quad, domain_object.radius_at_base, 0.0,
                         domain_object.height_mm, 100, 1)
     else:
         self._square_pyrmid(domain_object.radius_at_base * 2.0, 0.0,
                             domain_object.height_mm)
     gl.glDepthMask(gl.GL_TRUE)
     gl.glDisable(gl.GL_BLEND)
예제 #26
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()
예제 #27
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()
예제 #28
0
    def drawPointAndDirs(self):

        xAxis = numpy.array([1, 0, 0], 'float')
        yAxis = numpy.array([0, 1, 0], 'float')
        zAxis = numpy.array([0, 0, 1], 'float')
        center = numpy.array([0, 0, 0], 'float')

        qobj = GLU.gluNewQuadric()
        sphere_radius = 0.1
        cyl_height = 1
        cyl_radius = 0.01
        z_dir = numpy.array([0., 0., 1.], dtype='float64')

        genList = GL.glGenLists(1)
        GL.glNewList(genList, GL.GL_COMPILE)

        #Cylinder along z, we want it to be allong xAxis
        #Solution: use the appropriate rotation matrix
        #We have to choose the right axis, perpendicular to both, and rotate by the appropriate angle, the angle between the 2 vectors

        self.qglColor(QtGui.QColor.fromCmykF(0., 1., 1., 0.))

        rotation_dir = numpy.cross(z_dir, xAxis)
        angle = math.acos(z_dir.dot(xAxis)) * 180 / 3.14159

        GL.glPushMatrix()
        GL.glTranslatef(center[0], center[1], center[2])
        GL.glRotatef(angle, rotation_dir[0], rotation_dir[1], rotation_dir[2])
        GLU.gluCylinder(qobj, cyl_radius, cyl_radius, cyl_height, 20, 20)
        GL.glPopMatrix()

        self.qglColor(QtGui.QColor.fromCmykF(1., 0., 1., 0.))

        rotation_dir = numpy.cross(z_dir, yAxis)
        angle = math.acos(z_dir.dot(yAxis)) * 180 / 3.14159

        GL.glPushMatrix()
        GL.glTranslatef(center[0], center[1], center[2])
        GL.glRotatef(angle, rotation_dir[0], rotation_dir[1], rotation_dir[2])
        GLU.gluCylinder(qobj, cyl_radius, cyl_radius, cyl_height, 20, 20)
        GL.glPopMatrix()

        GL.glEndList()

        return genList
예제 #29
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()
예제 #30
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()
예제 #31
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()
예제 #32
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()
예제 #33
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)
예제 #34
0
파일: lego.py 프로젝트: sulyi/LEGO-break-up
def _caped_cylinder( radius, height, segments ):
    global __quadratic, __legocaptex
    GL.glPushMatrix()
    
    GL.glRotatef(-90, 1.0, 0.0, 0.0)
    GL.glTranslatef(0.0, 0.0, -height/2.0)
    
    #GLU.gluQuadricOrientation(__quadratic, GLU.GLU_INSIDE)
    #gluDisk(__quadratic,0,radius,segments,1)
    #GLU.gluQuadricOrientation(__quadratic, GLU.GLU_OUTSIDE)
    
    GLU.gluCylinder( __quadratic, radius, radius, height, segments, 1 )
    
    GL.glTranslatef( 0.0, 0.0, height )
    GL.glBindTexture( GL.GL_TEXTURE_2D, __legocaptex )
    GLU.gluDisk( __quadratic, 0, radius, segments,1 )
    GL.glBindTexture( GL.GL_TEXTURE_2D, 0 )
    
    GL.glPopMatrix()
예제 #35
0
    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()
예제 #36
0
    def render_arrow(self, p, q, r_base=0.01, head_width=0.015, head_len=0.01):
        # glDisable(GL_LIGHTING)
        m_quadric = self.quadric
        GLU.gluQuadricNormals(m_quadric, GLU.GLU_SMOOTH)
        p = np.array(p)
        q = np.array(q)
        u = (q - p)
        u /= norm(u)
        P = q - head_len * u
        z = np.array([0, 0.0, 1.0])
        z /= norm(z)
        if norm(z - u) < 1e-8:
            axis = np.array([0, 0, 1])
            angle = 0.0
        else:
            axis = np.cross(z, u)
            axis /= norm(axis)
            angle = math.acos(u.dot(z))
        M = R_axis_angle(axis, angle)
        m = [
            M[0, 0], M[1, 0], M[2, 0], 0.0, M[0, 1], M[1, 1], M[2, 1], 0.0,
            M[0, 2], M[1, 2], M[2, 2], 0.0, P[0], P[1], P[2], 1.0
        ]
        m2 = [
            M[0, 0], M[1, 0], M[2, 0], 0.0, M[0, 1], M[1, 1], M[2, 1], 0.0,
            M[0, 2], M[1, 2], M[2, 2], 0.0, p[0], p[1], p[2], 1.0
        ]

        GL.glPushMatrix()
        GL.glMultMatrixd(m2)
        arrow_len = norm(q - p) - head_len
        # glColor(0.9, 0.2, 0.2)
        GLU.gluCylinder(m_quadric, r_base, r_base, arrow_len, 10, 10)
        GL.glPopMatrix()

        if head_width > 1e-6 and head_len > 1e-6:
            # glColor(1.0, 0.0, 0.0)
            GL.glPushMatrix()
            GL.glMultMatrixd(m)
            GLUT.glutSolidCone(head_width, head_len, 10, 3)
            GL.glPopMatrix()
예제 #37
0
파일: valslider.py 프로젝트: kttn8769/eman2
 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()
예제 #38
0
파일: valslider.py 프로젝트: cryoem/eman2
 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()
예제 #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)
예제 #40
0
    def render_arrow(self, p, q, r_base=0.01, head_width=0.015, head_len=0.01):
        # glDisable(GL_LIGHTING)
        m_quadric = self.quadric
        GLU.gluQuadricNormals(m_quadric, GLU.GLU_SMOOTH)
        p = np.array(p)
        q = np.array(q)
        u = (q - p)
        u /= norm(u)
        P = q - head_len * u
        z = np.array([0, 0.0, 1.0])
        z /= norm(z)
        if norm(z - u) < 1e-8:
            axis = np.array([0, 0, 1])
            angle = 0.0
        else:
            axis = np.cross(z, u)
            axis /= norm(axis)
            angle = math.acos(u.dot(z))
        M = R_axis_angle(axis, angle)
        m = [M[0, 0], M[1, 0], M[2, 0], 0.0, M[0, 1], M[1, 1], M[2, 1], 0.0,
             M[0, 2], M[1, 2], M[2, 2], 0.0, P[0], P[1], P[2], 1.0]
        m2 = [M[0, 0], M[1, 0], M[2, 0], 0.0, M[0, 1], M[1, 1], M[2, 1], 0.0,
              M[0, 2], M[1, 2], M[2, 2], 0.0, p[0], p[1], p[2], 1.0]

        GL.glPushMatrix()
        GL.glMultMatrixd(m2)
        arrow_len = norm(q - p) - head_len
        # glColor(0.9, 0.2, 0.2)
        GLU.gluCylinder(m_quadric, r_base, r_base, arrow_len, 10, 10)
        GL.glPopMatrix()

        if head_width > 1e-6 and head_len > 1e-6:
            # glColor(1.0, 0.0, 0.0)
            GL.glPushMatrix()
            GL.glMultMatrixd(m)
            GLUT.glutSolidCone(head_width, head_len, 10, 3)
            GL.glPopMatrix()
예제 #41
0
 def draw(self):
     z1, r1, z2, r2 = self.coords()
     if z1 > z2:
         tmp = z1
         z1 = z2
         z2 = tmp
         tmp = r1
         r1 = r2
         r2 = tmp
     # need to translate the whole thing to z1
     GL.glPushMatrix()
     GL.glTranslatef(0, 0, z1)
     # the cylinder starts out at Z=0
     GLU.gluCylinder(self.q, r1, r2, z2 - z1, 32, 1)
     # bottom cap
     GL.glRotatef(180, 1, 0, 0)
     GLU.gluDisk(self.q, 0, r1, 32, 1)
     GL.glRotatef(180, 1, 0, 0)
     # the top cap needs flipped and translated
     GL.glPushMatrix()
     GL.glTranslatef(0, 0, z2 - z1)
     GLU.gluDisk(self.q, 0, r2, 32, 1)
     GL.glPopMatrix()
     GL.glPopMatrix()
예제 #42
0
파일: tools.py 프로젝트: a1eko/lampy
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()
예제 #43
0
파일: main.py 프로젝트: jpkell05/hyperdim
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()
예제 #44
0
    def draw(self):
        """Draws one frame in the OpenGL window
        """
        blue = (.27, .388, .678)
        dark_grey = (.235, .243, .266)
        grey = (.309, .309, .309)
        light_grey = (.447, .435, .449)
        sensor_data = self.sensor_data
        print("\r%s" % sensor_data, end='')
        #FIXME: Workaround to avoid using quaternions
        quat = Quaternion(sensor_data.gyro.w, sensor_data.gyro.x,
                          sensor_data.gyro.y, sensor_data.gyro.z)#.unit
        offset = Quaternion(self.offset.gyro.w, self.offset.gyro.x,
                            self.offset.gyro.y, self.offset.gyro.z)

        if offset:
            #TODO: Change back to quaternions
            # quat = offset.inverse * sensor_data.gyro
            quat = quat - offset
            self.flex_bent = self.offset.flex - self.flex_straight + self.flex_bent
            self.flex_straight = self.offset.flex

        gyro_euler = quat_to_euler(quat)
        rotation = quat_to_axis_rotation(quat)
        flex_angle =\
            self.translate_range(self.sensor_data.flex, self.flex_straight, self.flex_bent, 0.0, 90.0) \
            if self.sensor_data.flex != 0 else 0
        flex_angle = min(170, max(-20, flex_angle))

        gl.glClearColor(.8, .8, .8, 1.0)
        gl.glClearDepth(1.0)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_LIGHTING)
        gl.glShadeModel(gl.GL_SMOOTH)
        gl.glDisable(gl.GL_COLOR_MATERIAL)
        gl.glDepthFunc(gl.GL_LEQUAL)
        gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT |
                   gl.GL_DEPTH_BUFFER_BIT | gl.GL_STENCIL_BUFFER_BIT)
        gl.glEnable(gl.GL_LIGHT0)
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, (1, 2, 3))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, (.5, .5, .5))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, (.6, .6, .6))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, (0, 0, 0))
        # gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPOT_DIRECTION, (-2, -3, -3))
        gl.glLightf(gl.GL_LIGHT0, gl.GL_SPOT_CUTOFF, 180) # omnidirectional

        gl.glLoadIdentity()
        gl.glTranslatef(0, 0.0, -7.0)

        osd_line = \
            "x: {0:<7.2f}".format(quat.x) + \
            "y: {0:<7.2f}".format(quat.y) + \
            "z: {0:<7.2f}".format(quat.z) + \
            "flex: {0:>8}".format("{0:.2f}°".format(flex_angle))

        self.drawText((-2, 1.9, 2), osd_line)

        gl.glPushMatrix()

        gl.glTranslatef(0, 2.0, 0.0)
        gl.glNormal3f(0.0, -1.0, 0.0)
        #TODO: Change back to quaternions
        # gl.glRotatef(-gyro_euler.x, 0, 1, 0)
        # gl.glRotatef(-gyro_euler.y, 1, 0, 0)
        # gl.glRotatef(gyro_euler.z*2, 0, 0, 1)
        # gl.glRotatef(quat.x, 0, 1, 0)
        gl.glRotatef(2*quat.y, 0, 0, 1)
        gl.glRotatef(quat.z, 1, 0, 0)
        gl.glRotatef(120, .5, .5, -.5)

        gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE, blue)
        glu.gluCylinder(self.quad, 0.2, 0.15, 2, 10, 1)

        gl.glTranslatef(0, 0, 2)

        # Flex sensor:
        # Pitch, rotate around x-axis
        gl.glRotatef(flex_angle, 1.0, 0.0, 0.0)

        gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE,dark_grey)
        glu.gluSphere(self.quad, 0.2, 6, 6)

        gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE,blue)
        glu.gluCylinder(self.quad, 0.15, 0.125, 1.8, 9, 1)

        gl.glTranslatef(0, 0, 1.8)

        # -------------------
        # First part of foot
        # -------------------

        if self.pose == 0:
            pass
        elif self.pose == 1:
            gl.glRotatef(60.0, 1.0, 0.0, 0.0)

        gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE,dark_grey)
        glu.gluSphere(self.quad, 0.2, 6, 6)

        gl.glBegin(gl.GL_QUADS)
        
        gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE,grey)
        # foot - back
        gl.glNormal3f(0, -1, 0)
        gl.glVertex3f(-0.2, -0.1, 0.0)
        gl.glVertex3f(0.2, -0.1, 0.0)
        gl.glVertex3f(0.2, -0.1, 0.3)
        gl.glVertex3f(-0.2, -0.1, 0.3)

        # foot - right
        gl.glNormal3f(-1, 0, 0)
        gl.glVertex3f(-0.2, -0.1, 0.3)
        gl.glVertex3f(-0.2, 0.8, 0.3)
        gl.glVertex3f(-0.2, 0.8, 0.1)
        gl.glVertex3f(-0.2, -0.1, 0.0)

        # foot - left
        gl.glNormal3f(1, 0, 0)
        gl.glVertex3f(0.2, -0.1, 0.3)
        gl.glVertex3f(0.2, 0.8, 0.3)
        gl.glVertex3f(0.2, 0.8, 0.1)
        gl.glVertex3f(0.2, -0.1, 0.0)

        # foot - top
        gl.glNormal3f(0, 0, -1)
        gl.glVertex3f(-0.2, -0.1, 0.0)
        gl.glVertex3f(-0.2, 0.8, 0.1)
        gl.glVertex3f(0.2, 0.8, 0.1)
        gl.glVertex3f(0.2, -0.1, 0.0)

        # foot - front
        gl.glNormal3f(0, 1, 0)
        gl.glVertex3f(-0.2, -0.1, 0.3)
        gl.glVertex3f(-0.2, 0.8, 0.3)
        gl.glVertex3f(0.2, 0.8, 0.3)
        gl.glVertex3f(0.2, -0.1, 0.3)

        # foot - bottom
        gl.glNormal3f(0, 0, 1)
        gl.glVertex3f(-0.2, 0.8, 0.3)
        gl.glVertex3f(-0.2, 0.8, 0.1)
        gl.glVertex3f(0.2, 0.8, 0.1)
        gl.glVertex3f(0.2, 0.8, 0.3)

        gl.glEnd()
        gl.glTranslatef(0, 0.8, 0.1)

        # -------------------
        # Second part of foot
        # -------------------

        if self.pose == 0:
            pass
        elif self.pose == 1:
            gl.glRotatef(-60.0, 1.0, 0.0, 0.0)

        gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE,dark_grey)
        glu.gluSphere(self.quad, 0.1, 6, 6)

        gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE,grey)
        
        gl.glBegin(gl.GL_QUADS)

        # foot - back
        gl.glNormal3f(0, -1, 0)
        gl.glVertex3f(-0.2, 0.02, 0.0)
        gl.glVertex3f(0.2, 0.02, 0.0)
        gl.glVertex3f(0.2, 0.02, 0.2)
        gl.glVertex3f(-0.2, 0.02, 0.2)

        # foot - right
        gl.glNormal3f(-1, 0, 0)
        gl.glVertex3f(-0.2, 0.02, 0.2)
        gl.glVertex3f(-0.2, 0.4, 0.2)
        gl.glVertex3f(-0.2, 0.4, 0.1)
        gl.glVertex3f(-0.2, 0.02, 0.0)

        # foot - left
        gl.glNormal3f(1, 0, 0)
        gl.glVertex3f(0.2, 0.02, 0.2)
        gl.glVertex3f(0.2, 0.4, 0.2)
        gl.glVertex3f(0.2, 0.4, 0.1)
        gl.glVertex3f(0.2, 0.02, 0.0)

        # foot - top
        gl.glNormal3f(0, 0, -1)
        gl.glVertex3f(-0.2, 0.02, 0.0)
        gl.glVertex3f(-0.2, 0.4, 0.1)
        gl.glVertex3f(0.2, 0.4, 0.1)
        gl.glVertex3f(0.2, 0.02, 0.0)

        # foot - front
        gl.glNormal3f(0, 1, 0)
        gl.glVertex3f(-0.2, 0.02, 0.2)
        gl.glVertex3f(-0.2, 0.4, 0.2)
        gl.glVertex3f(0.2, 0.4, 0.2)
        gl.glVertex3f(0.2, 0.02, 0.2)

        # foot - bottom
        gl.glNormal3f(0, 0, 1)
        gl.glVertex3f(-0.2, 0.4, 0.2)
        gl.glVertex3f(-0.2, 0.4, 0.1)
        gl.glVertex3f(0.2, 0.4, 0.1)
        gl.glVertex3f(0.2, 0.4, 0.2)

        gl.glEnd()
        gl.glPopMatrix()
예제 #45
0
 def arrow(self):
     glu.gluCylinder(self.quad, 0.005, 0.005, 0.7, 100, 1)
     gl.glTranslatef(0.0, 0.0, 0.7)
     glu.gluCylinder(self.quad, 0.03, 0.0, 0.1, 100, 1)
     gl.glTranslatef(0.0, 0.0, -0.7)
 def prepare(self):
     """ Build display lists """
     # for efficiency, allow skipping the TRANSPARENT render if opaque
     self._has_transparent = (self.getstyle('colour')[3] < 1)
     # consts
     v3 = glVertex3f
     r = self.getgeom('stick', 0.05)
     # feet
     dl = self.newpiece("footL")
     self.dlists["footR"] = dl  # foot is same on both legs
     glNewList(dl, GL_COMPILE)
     x = self.getgeom('footX', 0.1)
     glBegin(GL_TRIANGLES)
     v3(0, 0, 0)
     v3(x, -x / 2.0, 0)
     v3(x, x / 2.0, 0)
     glEnd()
     glEndList()
     # shins
     dl = self.newpiece("shinL")
     self.dlists["shinR"] = dl
     glNewList(dl, GL_COMPILE)
     z = self.getgeom('shinZ', 0.25)
     GLU.gluCylinder(self.quadric, r, r, z, 3, 2)
     glEndList()
     # thighs
     dl = self.newpiece("thighL")
     self.dlists["thighR"] = dl
     glNewList(dl, GL_COMPILE)
     z = self.getgeom('thighZ', 0.25)
     GLU.gluCylinder(self.quadric, r, r, z, 4, 2)
     glEndList()
     #hips
     dl = self.newpiece("hips")
     glNewList(dl, GL_COMPILE)
     w = self.getgeom('hipY', 0.1)
     glBegin(GL_LINES)  # simple line across hip joint
     v3(0, -w, 0)
     v3(0, w, 0)
     glEnd()
     glEndList()
     #torso
     dl = self.newpiece("torso")
     glNewList(dl, GL_COMPILE)
     z = self.getgeom('torsoZ', 0.5)
     w = self.getgeom('shoulderY', 0.2)
     GLU.gluCylinder(self.quadric, r, r, z, 6, 2)
     glBegin(GL_LINES)  # line across shoulders
     v3(0, -w, z)
     v3(0, w, z)
     glEnd()
     glEndList()
     # upper arms
     dl = self.newpiece("upperarmL")
     self.dlists['upperarmR'] = dl
     z = self.getgeom('upperarmZ', 0.2)
     glNewList(dl, GL_COMPILE)
     GLU.gluCylinder(self.quadric, r, r, z, 4, 2)
     glEndList()
     # forearms
     dl = self.newpiece("forearmL")
     self.dlists['forearmR'] = dl
     z = self.getgeom('forearmZ', 0.2)
     glNewList(dl, GL_COMPILE)
     GLU.gluCylinder(self.quadric, r, r, z, 3, 2)
     glEndList()
     # hands
     dl = self.newpiece("handL")
     self.dlists["handR"] = dl  # hand is same on both arms
     glNewList(dl, GL_COMPILE)
     z = self.getgeom('handZ', 0.1)
     glBegin(GL_TRIANGLES)
     v3(0, 0, 0)
     v3(0, -z / 2.0, -z)
     v3(0, z / 2.0, -z)
     glEnd()
     glEndList()
     # head
     dl = self.newpiece("head")
     z = self.getgeom('headZ', 0.2)
     glNewList(dl, GL_COMPILE)
     GLU.gluCylinder(self.quadric, r, r, z, 4, 1)  # neck
     glTranslate(0, 0, z)  # centre of head
     GLU.gluSphere(self.quadric, 2 * r, 8, 6)
     glTranslate(2 * r, 0, 0)  # to nose
     glColor(1, 0, 0, 1)  # red nose for testing
     GLU.gluSphere(self.quadric, r * 0.5, 6, 4)
     glEndList()
예제 #47
0
 def prepare(self):
     """ Build display lists """
     # for efficiency, allow skipping the TRANSPARENT render if opaque
     self._has_transparent = (self.getstyle('colour')[3] < 1)
     # consts
     v3 = glVertex3f
     r = self.getgeom('stick',0.05)
     # feet
     dl = self.newpiece("footL")
     self.dlists["footR"] = dl   # foot is same on both legs
     glNewList(dl,GL_COMPILE)
     x = self.getgeom('footX',0.1)
     glBegin(GL_TRIANGLES)
     v3(0,0,0)
     v3(x,-x/2.0,0)
     v3(x,x/2.0,0)
     glEnd()
     glEndList()
     # shins
     dl = self.newpiece("shinL")
     self.dlists["shinR"] = dl
     glNewList(dl,GL_COMPILE)
     z = self.getgeom('shinZ',0.25)
     GLU.gluCylinder(self.quadric,r,r,z,3,2)
     glEndList()
     # thighs
     dl = self.newpiece("thighL")
     self.dlists["thighR"] = dl
     glNewList(dl,GL_COMPILE)
     z = self.getgeom('thighZ',0.25)
     GLU.gluCylinder(self.quadric,r,r,z,4,2)
     glEndList()
     #hips
     dl = self.newpiece("hips")
     glNewList(dl,GL_COMPILE)
     w = self.getgeom('hipY',0.1)
     glBegin(GL_LINES)   # simple line across hip joint
     v3(0,-w,0)
     v3(0,w,0)
     glEnd()
     glEndList()
     #torso
     dl = self.newpiece("torso")
     glNewList(dl,GL_COMPILE)
     z = self.getgeom('torsoZ',0.5)
     w = self.getgeom('shoulderY',0.2)
     GLU.gluCylinder(self.quadric,r,r,z,6,2)
     glBegin(GL_LINES)   # line across shoulders
     v3(0,-w,z)
     v3(0,w,z)
     glEnd()
     glEndList()
     # upper arms
     dl = self.newpiece("upperarmL")
     self.dlists['upperarmR'] = dl
     z = self.getgeom('upperarmZ',0.2)
     glNewList(dl,GL_COMPILE)
     GLU.gluCylinder(self.quadric,r,r,z,4,2)
     glEndList()
     # forearms
     dl = self.newpiece("forearmL")
     self.dlists['forearmR'] = dl
     z = self.getgeom('forearmZ',0.2)
     glNewList(dl,GL_COMPILE)
     GLU.gluCylinder(self.quadric,r,r,z,3,2)
     glEndList()
     # hands
     dl = self.newpiece("handL")
     self.dlists["handR"] = dl   # hand is same on both arms
     glNewList(dl,GL_COMPILE)
     z = self.getgeom('handZ',0.1)
     glBegin(GL_TRIANGLES)
     v3(0,0,0)
     v3(0,-z/2.0,-z)
     v3(0,z/2.0,-z)
     glEnd()
     glEndList()
     # head
     dl = self.newpiece("head")
     z = self.getgeom('headZ',0.2)
     glNewList(dl,GL_COMPILE)
     GLU.gluCylinder(self.quadric,r,r,z,4,1) # neck
     glTranslate(0,0,z)  # centre of head
     GLU.gluSphere(self.quadric,2*r,8,6)
     glTranslate(2*r,0,0) # to nose
     glColor(1,0,0,1)    # red nose for testing
     GLU.gluSphere(self.quadric,r*0.5,6,4)
     glEndList()
예제 #48
0
 def arrow(self):
     glu.gluCylinder(self.quad, 0.005, 0.005, 0.7, 100, 1)
     gl.glTranslatef(0.0, 0.0, 0.7)
     glu.gluCylinder(self.quad, 0.03, 0.0, 0.1, 100, 1)
     gl.glTranslatef(0.0, 0.0, -0.7)
예제 #49
0
파일: nx_opengl.py 프로젝트: caosuomo/rads
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)
예제 #50
0
    def drawPointAndDirs(self, matrix, color=GREEN):
        try:

            xAxis = numpy.array([matrix[0][0], matrix[1][0], matrix[2][0]],
                                'float')
            yAxis = numpy.array([matrix[0][1], matrix[1][1], matrix[2][1]],
                                'float')
            zAxis = numpy.array([matrix[0][2], matrix[1][2], matrix[2][2]],
                                'float')
            center = numpy.array([matrix[0][3], matrix[1][3], matrix[2][3]],
                                 'float')
        except:
            print('invalid matrix!')
            return None

        qobj = GLU.gluNewQuadric()
        sphere_radius = 3
        cyl_height = 20
        cyl_radius = 0.7
        z_dir = numpy.array([0., 0., 1.], dtype='float64')

        genList = GL.glGenLists(1)
        GL.glNewList(genList, GL.GL_COMPILE)

        self.qglColor(color)
        GL.glPushMatrix()
        GL.glTranslatef(center[0], center[1], center[2])
        GLU.gluSphere(qobj, sphere_radius, 20, 20)
        GL.glPopMatrix()

        #Cylinder along z, we want it to be allong xAxis
        #Solution: use the appropriate rotation matrix
        #We have to choose the right axis, perpendicular to both, and rotate by the appropriate angle, the angle between the 2 vectors

        self.qglColor(RED)

        rotation_dir = numpy.cross(z_dir, xAxis)
        angle = math.acos(z_dir.dot(xAxis)) * 180 / 3.14159

        GL.glPushMatrix()
        GL.glTranslatef(center[0], center[1], center[2])
        GL.glRotatef(angle, rotation_dir[0], rotation_dir[1], rotation_dir[2])
        GLU.gluCylinder(qobj, cyl_radius, cyl_radius, cyl_height, 20, 20)
        GL.glPopMatrix()

        self.qglColor(GREEN)

        rotation_dir = numpy.cross(z_dir, yAxis)
        angle = math.acos(z_dir.dot(yAxis)) * 180 / 3.14159

        GL.glPushMatrix()
        GL.glTranslatef(center[0], center[1], center[2])
        GL.glRotatef(angle, rotation_dir[0], rotation_dir[1], rotation_dir[2])
        GLU.gluCylinder(qobj, cyl_radius, cyl_radius, cyl_height, 20, 20)
        GL.glPopMatrix()

        self.qglColor(BLUE)

        rotation_dir = numpy.cross(z_dir, zAxis)
        angle = math.acos(z_dir.dot(zAxis)) * 180 / 3.14159
        z_axis_center = center - zAxis * 10

        GL.glPushMatrix()
        GL.glTranslatef(z_axis_center[0], z_axis_center[1], z_axis_center[2])
        GL.glRotatef(angle, rotation_dir[0], rotation_dir[1], rotation_dir[2])
        GLU.gluCylinder(qobj, cyl_radius, cyl_radius, cyl_height * 2, 20, 20)
        GL.glPopMatrix()

        GL.glEndList()

        return genList
예제 #51
0
 def __drawCone(self, zMin, zMax, r1, r2, nbSub):
     quadric = glu.gluNewQuadric()
     ogl.glTranslatef(0.0, 0.0, zMin)
     glu.gluCylinder(quadric, r1, r2, zMax - zMin, nbSub, 1)
     ogl.glTranslatef(0.0, 0.0, -zMin)