示例#1
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()
示例#2
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()
示例#3
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)
示例#4
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)
示例#5
0
    def paint_enter(self):
        """
        Implements the GLNodeAdapter's paint_enter method for an OpenGL Render operation.
        """
        GL.glPushAttrib(GL.GL_ENABLE_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_LINE_BIT | GL.GL_CURRENT_BIT)
        GL.glPushClientAttrib(GL.GL_CLIENT_VERTEX_ARRAY_BIT)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        GL.glMultMatrixf(self._node.matrix().data())
        GL.glColor(self._node.color.getRgbF())
        
        # The positive Z-axis is the default direction for Cylinder Quadrics in OpenGL.
        # If our vector is not parallel to the z-axis, e.g. (0, 0, Z), then rotate it.
        #   1) Get a normal from the z-v plane
        #   2) Get the angle inbetween z-v on the plane (see vector dot product)
        #   3) Rotate the normal by that angle.
        v = self._node.axis
        m = Matrix4x4.identity()
        if v.x != 0 or v.y != 0:
            zaxis  = Vector3D(0,0,1)
            angle  = zaxis.angle(v)
            normal = zaxis.crossproduct(v, True)
            m *= Matrix4x4.rotation(angle, normal)

        # The positive Z-axis is the default direction fo Cylinder Quadrics in OpenGL.
        # If our z is negative, we need to flip the cylinder
        if v.z < 0:
            yaxis  = Vector3D(1,0,0)
            m *= Matrix4x4.rotation(math.radians(180), yaxis)       
        GL.glMultMatrixf(m.data())

        q = self.__quadric
        r = self._node.radius
        h = self._node.length
        sl = self._node.slices
        st = self._node.stacks
        lp = self._node.loops
        GLU.gluQuadricDrawStyle (q, GLU.GLU_FILL)
        GLU.gluQuadricNormals (q, GLU.GLU_SMOOTH)
        GLU.gluQuadricOrientation(q, GLU.GLU_OUTSIDE)
        self._glcylinder(q, r, h, sl, st, lp)
示例#6
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()