def DrawModels(drawBasePlane): if drawBasePlane: # Draw plane that the objects rest on glColor3f(0.0, 0.0, 0.90) # Blue glNormal3f(0.0, 1.0, 0.0) glBegin(GL_QUADS) glVertex3f(-100.0, -25.0, -100.0) glVertex3f(-100.0, -25.0, 100.0) glVertex3f(100.0, -25.0, 100.0) glVertex3f(100.0, -25.0, -100.0) glEnd() # Draw red cube glColor3f(1.0, 0.0, 0.0) glutSolidCube(48.0) # Draw green sphere glColor3f(0.0, 1.0, 0.0) glPushMatrix() glTranslatef(-60.0, 0.0, 0.0) glutSolidSphere(25.0, 50, 50) glPopMatrix() # Draw yellow cone glColor3f(1.0, 1.0, 0.0) glPushMatrix() glRotatef(-90.0, 1.0, 0.0, 0.0) glTranslatef(60.0, 0.0, -24.0) glutSolidCone(25.0, 50.0, 50, 50) glPopMatrix() # Draw magenta torus glColor3f(1.0, 0.0, 1.0) glPushMatrix() glTranslatef(0.0, 0.0, 60.0) glutSolidTorus(8.0, 16.0, 50, 50) glPopMatrix() # Draw cyan octahedron glColor3f(0.0, 1.0, 1.0) glPushMatrix() glTranslatef(0.0, 0.0, -60.0) glScalef(25.0, 25.0, 25.0) glutSolidOctahedron() glPopMatrix()
def on_draw(self): mCubeTransform = M3DMatrix44f() # Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glShadeModel(GL_SMOOTH) glEnable(GL_NORMALIZE) glPushMatrix() # Draw plane that the cube rests on glDisable(GL_LIGHTING) if nStep == 5: glColor3ub(255, 255, 255) glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D, textures[0]) glBegin(GL_QUADS) glTexCoord2f(0.0, 0.0) glVertex3f(-100.0, -25.3, -100.0) glTexCoord2f(0.0, 1.0) glVertex3f(-100.0, -25.3, 100.0) glTexCoord2f(1.0, 1.0) glVertex3f(100.0, -25.3, 100.0) glTexCoord2f(1.0, 0.0) glVertex3f(100.0, -25.3, -100.0) glEnd() else: glColor3f(0.0, 0.0, 0.90) # Blue glBegin(GL_QUADS) glVertex3f(-100.0, -25.3, -100.0) glVertex3f(-100.0, -25.3, 100.0) glVertex3f(100.0, -25.3, 100.0) glVertex3f(100.0, -25.3, -100.0) glEnd() # Set drawing color to Red glColor3f(1.0, 0.0, 0.0) # Enable, disable lighting if nStep > 2: glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glEnable(GL_COLOR_MATERIAL) glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse) glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glMaterialfv(GL_FRONT, GL_SPECULAR, lightSpecular) glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColor) glMateriali(GL_FRONT, GL_SHININESS, 128) # Move the cube slightly forward and to the left glTranslatef(-10.0, 0.0, 10.0) if nStep == 0: # Just draw the wire framed cube glutWireCube(50.0) # Same wire cube with hidden line removal simulated elif nStep == 1: # Front Face (before rotation) glBegin(GL_LINES) glVertex3f(25.0, 25.0, 25.0) glVertex3f(25.0, -25.0, 25.0) glVertex3f(25.0, -25.0, 25.0) glVertex3f(-25.0, -25.0, 25.0) glVertex3f(-25.0, -25.0, 25.0) glVertex3f(-25.0, 25.0, 25.0) glVertex3f(-25.0, 25.0, 25.0) glVertex3f(25.0, 25.0, 25.0) glEnd() # Top of cube glBegin(GL_LINES) # Front Face glVertex3f(25.0, 25.0, 25.0) glVertex3f(25.0, 25.0, -25.0) glVertex3f(25.0, 25.0, -25.0) glVertex3f(-25.0, 25.0, -25.0) glVertex3f(-25.0, 25.0, -25.0) glVertex3f(-25.0, 25.0, 25.0) glVertex3f(-25.0, 25.0, 25.0) glVertex3f(25.0, 25.0, 25.0) glEnd() # Last two segments for effect glBegin(GL_LINES) glVertex3f(25.0, 25.0, -25.0) glVertex3f(25.0, -25.0, -25.0) glVertex3f(25.0, -25.0, -25.0) glVertex3f(25.0, -25.0, 25.0) glEnd() # Uniform colored surface, looks 2D and goofey elif nStep == 2: glutSolidCube(50.0) elif nStep == 3: glutSolidCube(50.0) # Draw a shadow with some lighting elif nStep == 4: glGetFloatv(GL_MODELVIEW_MATRIX, mCubeTransform) glutSolidCube(50.0) glPopMatrix() # Disable lighting, we'll just draw the shadow as black glDisable(GL_LIGHTING) glPushMatrix() pPlane = m3dGetPlaneEquation(ground[0], ground[1], ground[2]) mCubeTransform = m3dMakePlanarShadowMatrix(pPlane, vLightPos) #MakeShadowMatrix(ground, lightpos, cubeXform) glMultMatrixf(mCubeTransform) glTranslatef(-10.0, 0.0, 10.0) # Set drawing color to Black glColor3f(0.0, 0.0, 0.0) glutSolidCube(50.0) elif nStep == 5: glColor3ub(255, 255, 255) glGetFloatv(GL_MODELVIEW_MATRIX, mCubeTransform) # Front Face (before rotation) glBindTexture(GL_TEXTURE_2D, textures[1]) glBegin(GL_QUADS) glTexCoord2f(1.0, 1.0) glVertex3f(25.0, 25.0, 25.0) glTexCoord2f(1.0, 0.0) glVertex3f(25.0, -25.0, 25.0) glTexCoord2f(0.0, 0.0) glVertex3f(-25.0, -25.0, 25.0) glTexCoord2f(0.0, 1.0) glVertex3f(-25.0, 25.0, 25.0) glEnd() # Top of cube glBindTexture(GL_TEXTURE_2D, textures[2]) glBegin(GL_QUADS) # Front Face glTexCoord2f(0.0, 0.0) glVertex3f(25.0, 25.0, 25.0) glTexCoord2f(1.0, 0.0) glVertex3f(25.0, 25.0, -25.0) glTexCoord2f(1.0, 1.0) glVertex3f(-25.0, 25.0, -25.0) glTexCoord2f(0.0, 1.0) glVertex3f(-25.0, 25.0, 25.0) glEnd() # Last two segments for effect glBindTexture(GL_TEXTURE_2D, textures[3]) glBegin(GL_QUADS) glTexCoord2f(1.0, 1.0) glVertex3f(25.0, 25.0, -25.0) glTexCoord2f(1.0, 0.0) glVertex3f(25.0, -25.0, -25.0) glTexCoord2f(0.0, 0.0) glVertex3f(25.0, -25.0, 25.0) glTexCoord2f(0.0, 1.0) glVertex3f(25.0, 25.0, 25.0) glEnd() glPopMatrix() # Disable lighting, we'll just draw the shadow as black glDisable(GL_LIGHTING) glDisable(GL_TEXTURE_2D) glPushMatrix() pPlane = m3dGetPlaneEquation(ground[0], ground[1], ground[2]) mCubeTransform = m3dMakePlanarShadowMatrix(pPlane, vLightPos) glMultMatrixf(mCubeTransform) glTranslatef(-10.0, 0.0, 10.0) # Set drawing color to Black glColor3f(0.0, 0.0, 0.0) glutSolidCube(50.0) glPopMatrix()
def on_draw(self): mCubeTransform = M3DMatrix44f() # Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glShadeModel(GL_SMOOTH) glEnable(GL_NORMALIZE) glPushMatrix() # Draw plane that the cube rests on glDisable(GL_LIGHTING) if nStep == 5: glColor3ub(255,255,255) glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D, textures[0]) glBegin(GL_QUADS) glTexCoord2f(0.0, 0.0) glVertex3f(-100.0, -25.3, -100.0) glTexCoord2f(0.0, 1.0) glVertex3f(-100.0, -25.3, 100.0) glTexCoord2f(1.0, 1.0) glVertex3f(100.0, -25.3, 100.0) glTexCoord2f(1.0, 0.0) glVertex3f(100.0, -25.3, -100.0) glEnd() else: glColor3f(0.0, 0.0, 0.90) # Blue glBegin(GL_QUADS) glVertex3f(-100.0, -25.3, -100.0) glVertex3f(-100.0, -25.3, 100.0) glVertex3f(100.0, -25.3, 100.0) glVertex3f(100.0, -25.3, -100.0) glEnd() # Set drawing color to Red glColor3f(1.0, 0.0, 0.0) # Enable, disable lighting if nStep > 2: glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glEnable(GL_COLOR_MATERIAL) glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse) glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glMaterialfv(GL_FRONT, GL_SPECULAR,lightSpecular) glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColor) glMateriali(GL_FRONT, GL_SHININESS,128) # Move the cube slightly forward and to the left glTranslatef(-10.0, 0.0, 10.0) if nStep == 0: # Just draw the wire framed cube glutWireCube(50.0) # Same wire cube with hidden line removal simulated elif nStep == 1: # Front Face (before rotation) glBegin(GL_LINES) glVertex3f(25.0,25.0,25.0) glVertex3f(25.0,-25.0,25.0) glVertex3f(25.0,-25.0,25.0) glVertex3f(-25.0,-25.0,25.0) glVertex3f(-25.0,-25.0,25.0) glVertex3f(-25.0,25.0,25.0) glVertex3f(-25.0,25.0,25.0) glVertex3f(25.0,25.0,25.0) glEnd() # Top of cube glBegin(GL_LINES) # Front Face glVertex3f(25.0,25.0,25.0) glVertex3f(25.0,25.0,-25.0) glVertex3f(25.0,25.0,-25.0) glVertex3f(-25.0,25.0,-25.0) glVertex3f(-25.0,25.0,-25.0) glVertex3f(-25.0,25.0,25.0) glVertex3f(-25.0,25.0,25.0) glVertex3f(25.0,25.0,25.0) glEnd() # Last two segments for effect glBegin(GL_LINES) glVertex3f(25.0,25.0,-25.0) glVertex3f(25.0,-25.0,-25.0) glVertex3f(25.0,-25.0,-25.0) glVertex3f(25.0,-25.0,25.0) glEnd() # Uniform colored surface, looks 2D and goofey elif nStep == 2: glutSolidCube(50.0) elif nStep == 3: glutSolidCube(50.0) # Draw a shadow with some lighting elif nStep == 4: glGetFloatv(GL_MODELVIEW_MATRIX, mCubeTransform) glutSolidCube(50.0) glPopMatrix() # Disable lighting, we'll just draw the shadow as black glDisable(GL_LIGHTING) glPushMatrix() pPlane = m3dGetPlaneEquation(ground[0], ground[1], ground[2]) mCubeTransform = m3dMakePlanarShadowMatrix(pPlane, vLightPos) #MakeShadowMatrix(ground, lightpos, cubeXform) glMultMatrixf(mCubeTransform) glTranslatef(-10.0, 0.0, 10.0) # Set drawing color to Black glColor3f(0.0, 0.0, 0.0) glutSolidCube(50.0) elif nStep == 5: glColor3ub(255,255,255) glGetFloatv(GL_MODELVIEW_MATRIX, mCubeTransform) # Front Face (before rotation) glBindTexture(GL_TEXTURE_2D, textures[1]) glBegin(GL_QUADS) glTexCoord2f(1.0, 1.0) glVertex3f(25.0,25.0,25.0) glTexCoord2f(1.0, 0.0) glVertex3f(25.0,-25.0,25.0) glTexCoord2f(0.0, 0.0) glVertex3f(-25.0,-25.0,25.0) glTexCoord2f(0.0, 1.0) glVertex3f(-25.0,25.0,25.0) glEnd() # Top of cube glBindTexture(GL_TEXTURE_2D, textures[2]) glBegin(GL_QUADS) # Front Face glTexCoord2f(0.0, 0.0) glVertex3f(25.0,25.0,25.0) glTexCoord2f(1.0, 0.0) glVertex3f(25.0,25.0,-25.0) glTexCoord2f(1.0, 1.0) glVertex3f(-25.0,25.0,-25.0) glTexCoord2f(0.0, 1.0) glVertex3f(-25.0,25.0,25.0) glEnd() # Last two segments for effect glBindTexture(GL_TEXTURE_2D, textures[3]) glBegin(GL_QUADS) glTexCoord2f(1.0, 1.0) glVertex3f(25.0,25.0,-25.0) glTexCoord2f(1.0, 0.0) glVertex3f(25.0,-25.0,-25.0) glTexCoord2f(0.0, 0.0) glVertex3f(25.0,-25.0,25.0) glTexCoord2f(0.0, 1.0) glVertex3f(25.0,25.0,25.0) glEnd() glPopMatrix() # Disable lighting, we'll just draw the shadow as black glDisable(GL_LIGHTING) glDisable(GL_TEXTURE_2D) glPushMatrix() pPlane = m3dGetPlaneEquation(ground[0], ground[1], ground[2]) mCubeTransform = m3dMakePlanarShadowMatrix(pPlane, vLightPos) glMultMatrixf(mCubeTransform) glTranslatef(-10.0, 0.0, 10.0) # Set drawing color to Black glColor3f(0.0, 0.0, 0.0) glutSolidCube(50.0) glPopMatrix()