Пример #1
0
def toonDrawTorus(majorRadius, minorRadius, numMajor, numMinor, lightDir):

    mModelViewMatrix = M3DMatrix44f()
    mInvertedLight = M3DMatrix44f()
    vNewLight = M3DVector3f()
    vNormal = M3DVector3f()
    majorStep = 2.0 * M3D_PI / numMajor
    minorStep = 2.0 * M3D_PI / numMinor

    # Get the modelview matrix
    glGetFloatv(GL_MODELVIEW_MATRIX, mModelViewMatrix)

    # Instead of transforming every normal and then dotting it with
    # the light vector, we will transform the light into object
    # space by multiplying it by the inverse of the modelview matrix
    m3dInvertMatrix44(mInvertedLight, mModelViewMatrix)
    m3dTransformVector3(vNewLight, vLightDir, mInvertedLight)
    vNewLight[0] -= mInvertedLight[12]
    vNewLight[1] -= mInvertedLight[13]
    vNewLight[2] -= mInvertedLight[14]
    m3dNormalizeVector(vNewLight)

    # Draw torus as a series of triangle strips
    for i in range(0, numMajor):
        a0 = i * majorStep
        a1 = a0 + majorStep
        x0 = cos(a0)
        y0 = sin(a0)
        x1 = cos(a1)
        y1 = sin(a1)

        glBegin(GL_TRIANGLE_STRIP)
        for j in range(0, numMinor + 1):

            b = j * minorStep
            c = cos(b)
            r = minorRadius * c + majorRadius
            z = minorRadius * sin(b)

            # First point
            vNormal[0] = x0 * c
            vNormal[1] = y0 * c
            vNormal[2] = z / minorRadius
            m3dNormalizeVector(vNormal)

            # Texture coordinate is set by intensity of light
            glTexCoord1f(m3dDotProduct(vNewLight, vNormal))
            glVertex3f(x0 * r, y0 * r, z)

            # Second point
            vNormal[0] = x1 * c
            vNormal[1] = y1 * c
            vNormal[2] = z / minorRadius
            m3dNormalizeVector(vNormal)

            # Texture coordinate is set by intensity of light
            glTexCoord1f(m3dDotProduct(vNewLight, vNormal))
            glVertex3f(x1 * r, y1 * r, z)

        glEnd()
Пример #2
0
def toonDrawTorus(majorRadius, minorRadius, numMajor, numMinor, lightDir):
    
    mModelViewMatrix = M3DMatrix44f()
    mInvertedLight = M3DMatrix44f()
    vNewLight = M3DVector3f()
    vNormal = M3DVector3f()
    majorStep = 2.0*M3D_PI / numMajor
    minorStep = 2.0*M3D_PI / numMinor
    
    # Get the modelview matrix
    glGetFloatv(GL_MODELVIEW_MATRIX, mModelViewMatrix)
    
    # Instead of transforming every normal and then dotting it with
    # the light vector, we will transform the light into object 
    # space by multiplying it by the inverse of the modelview matrix
    m3dInvertMatrix44(mInvertedLight, mModelViewMatrix)
    m3dTransformVector3(vNewLight, vLightDir, mInvertedLight)
    vNewLight[0] -= mInvertedLight[12]
    vNewLight[1] -= mInvertedLight[13]
    vNewLight[2] -= mInvertedLight[14]
    m3dNormalizeVector(vNewLight)
    
    # Draw torus as a series of triangle strips
    for i in range(0, numMajor):
        a0 = i * majorStep
        a1 = a0 + majorStep
        x0 = cos(a0)
        y0 = sin(a0)
        x1 = cos(a1)
        y1 = sin(a1)

        glBegin(GL_TRIANGLE_STRIP)
        for j in range(0, numMinor + 1):

            b = j * minorStep
            c =  cos(b)
            r = minorRadius * c + majorRadius
            z = minorRadius * sin(b)

            # First point
            vNormal[0] = x0*c
            vNormal[1] = y0*c
            vNormal[2] = z/minorRadius
            m3dNormalizeVector(vNormal)
            
            # Texture coordinate is set by intensity of light
            glTexCoord1f(m3dDotProduct(vNewLight, vNormal))
            glVertex3f(x0*r, y0*r, z)

            # Second point
            vNormal[0] = x1*c
            vNormal[1] = y1*c
            vNormal[2] = z/minorRadius
            m3dNormalizeVector(vNormal)
            
            # Texture coordinate is set by intensity of light
            glTexCoord1f(m3dDotProduct(vNewLight, vNormal))
            glVertex3f(x1*r, y1*r, z)
            
        glEnd()
def DrawTorus(mTransform):
    majorRadius = 0.35
    minorRadius = 0.15
    numMajor = 40
    numMinor = 20
    objectVertex = M3DVector3f()  # Vertex in object/eye space
    transformedVertex = M3DVector3f()  # New Transformed vertex
    majorStep = 2.0
    majorStep = 2.0 * M3D_PI / float(numMajor)
    minorStep = 2.0 * M3D_PI / float(numMinor)

    i = 0
    while (i < numMajor):
        a0 = i * majorStep
        a1 = a0 + majorStep
        x0 = cos(a0)
        y0 = sin(a0)
        x1 = cos(a1)
        y1 = sin(a1)

        glBegin(GL_TRIANGLE_STRIP)
        j = 0
        # BS some sort of rounding error keeps a strip from being drawn
        while (j < numMinor + 1):
            b = j * minorStep
            c = cos(b)
            r = minorRadius * c + majorRadius
            z = minorRadius * sin(b)

            # First point
            objectVertex[0] = x0 * r
            objectVertex[1] = y0 * r
            objectVertex[2] = z
            m3dTransformVector3(transformedVertex, objectVertex, mTransform)
            glVertex3fv(transformedVertex)

            # Second point
            objectVertex[0] = x1 * r
            objectVertex[1] = y1 * r
            objectVertex[2] = z
            m3dTransformVector3(transformedVertex, objectVertex, mTransform)
            glVertex3fv(transformedVertex)
            j += 1
        glEnd()
        i += 1
Пример #4
0
def DrawTorus(mTransform):
    majorRadius = 0.35
    minorRadius = 0.15
    numMajor = 40
    numMinor = 20
    objectVertex = M3DVector3f()  # Vertex in object/eye space
    transformedVertex = M3DVector3f()  # New Transformed vertex
    majorStep = 2.0
    majorStep = 2.0 * M3D_PI / float(numMajor)
    minorStep = 2.0 * M3D_PI / float(numMinor)

    i = 0
    while i < numMajor:
        a0 = i * majorStep
        a1 = a0 + majorStep
        x0 = cos(a0)
        y0 = sin(a0)
        x1 = cos(a1)
        y1 = sin(a1)

        glBegin(GL_TRIANGLE_STRIP)
        j = 0
        # BS some sort of rounding error keeps a strip from being drawn
        while j < numMinor + 1:
            b = j * minorStep
            c = cos(b)
            r = minorRadius * c + majorRadius
            z = minorRadius * sin(b)

            # First point
            objectVertex[0] = x0 * r
            objectVertex[1] = y0 * r
            objectVertex[2] = z
            m3dTransformVector3(transformedVertex, objectVertex, mTransform)
            glVertex3fv(transformedVertex)

            # Second point
            objectVertex[0] = x1 * r
            objectVertex[1] = y1 * r
            objectVertex[2] = z
            m3dTransformVector3(transformedVertex, objectVertex, mTransform)
            glVertex3fv(transformedVertex)
            j += 1
        glEnd()
        i += 1