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 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 DrawGLScene(): # Clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glPushMatrix() frameCamera.ApplyCameraTransform() # Move the camera about # Sky Box is manually textured glActiveTexture(GL_TEXTURE0) glDisable(GL_TEXTURE_2D) glActiveTexture(GL_TEXTURE1) glEnable(GL_TEXTURE_CUBE_MAP) glDisable(GL_TEXTURE_GEN_S) glDisable(GL_TEXTURE_GEN_T) glDisable(GL_TEXTURE_GEN_R) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) DrawSkyBox() # Use texgen to apply cube map glEnable(GL_TEXTURE_GEN_S) glEnable(GL_TEXTURE_GEN_T) glEnable(GL_TEXTURE_GEN_R) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) glActiveTexture(GL_TEXTURE0) glEnable(GL_TEXTURE_2D) glPushMatrix() glTranslatef(0.0, 0.0, -3.0) glActiveTexture(GL_TEXTURE1) glMatrixMode(GL_TEXTURE) glPushMatrix() # Invert camera matrix (rotation only) and apply to # texture coordinates invert = M3DMatrix44f() m = frameCamera.GetCameraOrientation() m3dInvertMatrix44(invert, m) glMultMatrixf(invert) glColor3f(1.0, 1.0, 1.0) gltDrawSphere(0.75, 41, 41) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix() glPopMatrix() glutSwapBuffers()
def on_draw(self): # Clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glPushMatrix() frameCamera.ApplyCameraTransform() # Move the camera about # Sky Box is manually textured glActiveTexture(GL_TEXTURE0) glDisable(GL_TEXTURE_2D) glActiveTexture(GL_TEXTURE1) glEnable(GL_TEXTURE_CUBE_MAP) glDisable(GL_TEXTURE_GEN_S) glDisable(GL_TEXTURE_GEN_T) glDisable(GL_TEXTURE_GEN_R) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) # DrawSkyBox() # Use texgen to apply cube map glEnable(GL_TEXTURE_GEN_S) glEnable(GL_TEXTURE_GEN_T) glEnable(GL_TEXTURE_GEN_R) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) glActiveTexture(GL_TEXTURE0) glEnable(GL_TEXTURE_2D) glPushMatrix() glTranslatef(0.0, 0.0, -3.0) glActiveTexture(GL_TEXTURE1) glMatrixMode(GL_TEXTURE) glPushMatrix() # Invert camera matrix (rotation only) and apply to # texture coordinates invert = M3DMatrix44f() m = frameCamera.GetCameraOrientation() m3dInvertMatrix44(invert, m) glMultMatrixf(invert) glColor3f(1.0, 1.0, 1.0) gltDrawSphere(0.75, 41, 41) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix() glPopMatrix()
def on_draw(self): # Clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glPushMatrix() frameCamera.ApplyCameraTransform() # Move the camera about # Sky Box is manually textured glDisable(GL_TEXTURE_GEN_S) glDisable(GL_TEXTURE_GEN_T) glDisable(GL_TEXTURE_GEN_R) DrawSkyBox() # Use texgen to apply cube map glEnable(GL_TEXTURE_GEN_S) glEnable(GL_TEXTURE_GEN_T) glEnable(GL_TEXTURE_GEN_R) glPushMatrix() glTranslatef(0.0, 0.0, -3.0) glMatrixMode(GL_TEXTURE) glPushMatrix() # Invert camera matrix (rotation only) and apply to # texture coordinates m = M3DMatrix44f() invert = M3DMatrix44f() m = frameCamera.GetCameraOrientation() m3dInvertMatrix44(invert, m) glMultMatrixf(invert) gltDrawSphere(0.75, 41, 41) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix() glPopMatrix()