rendered paste body// lab2.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <stdlib.h>#include <GL/glut.h>#include "Lego.h"static const GLdouble zToModel = 15 * Lego::lengthUnit;static GLfloat animTime = 5.0; // modified by glutTimerFunc, used by glutDisplayFuncstatic const unsigned int fps = 60; // used by timer and to start timer offstatic GLfloat maxSpeed = 360;static bool xSpin = false;static bool ySpin = false;static bool zSpin = false;static GLfloat xSpeed = 1; //degrees per loopstatic GLfloat xAccel = 1.003;static GLfloat ySpeed = 0;static GLfloat yAccel = 1.001;static GLfloat zSpeed = 0;static GLfloat zAccel = 1.003;static GLfloat angleX(){ if (xSpin) { xSpeed += 1; return xSpeed; } else { //xSpeed -= 1; return xSpeed; }}static GLfloat angleY(){ if (ySpin) { ySpeed += 1; return ySpeed; } else { //ySpeed -= 1; return ySpeed; }}static GLfloat angleZ(){ if (zSpin) { zSpeed += 1; return zSpeed; } else { //zSpeed -= 1; return zSpeed; }}static void display(void){ static Lego myLego; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLfloat heightWhite = (animTime<=5) ? (10 + -7.0/5.0 * animTime) : (3); glPushMatrix(); glTranslatef(0, heightWhite*Lego::heightUnit, 0); glRotatef(angleX(), 1, 0, 0); glRotatef(angleY(), 0, 1, 0); glRotatef(angleZ(), 0, 0, 1); myLego.brick("yellow"); glPopMatrix(); glutSwapBuffers();}void reshape(int w, int h){ glViewport(0, 0, w, h); // use the whole window if (w > 0 && h > 0) // if not minimized... { glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLdouble fovy = 40; //degrees GLdouble aspect = w / static_cast<double>(h); GLdouble zNear = zToModel - 100, zFar = zToModel + 100; //assert (zNear > 0); gluPerspective(fovy, aspect, zNear, zFar); glMatrixMode(GL_MODELVIEW); }}void init(){ glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); const GLfloat light_position[] = {0,0,0,1}; glLightfv(GL_LIGHT0, GL_POSITION, light_position); const GLfloat lmodel_ambient[] = {0.1, 0.1, 0.1, 1.0}; // If we don't set it to something, glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); // it seems to default to a fairly bright value. // glFrontFace varies during drawing, so it is handled by the Lego class. glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt( 6*Lego::lengthUnit, 3*Lego::heightUnit, zToModel, // from 0, 3*Lego::heightUnit, 0, // to 0, 1, 0); // up}void processNormalKeys(unsigned char key, int x, int y){ if (key == 27) { exit(0); }}void mouse(int button, int state, int x, int y){ if (button == GLUT_RIGHT_BUTTON) { xSpin = !xSpin; } else if (button == GLUT_LEFT_BUTTON) { ySpin = !ySpin; } else if (button == GLUT_MIDDLE_BUTTON) { zSpin = !zSpin; }}int main(int argc, char* argv[]){ glutInitWindowPosition(100,100); glutInitWindowSize(400,400); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("Lab 2: phillijw"); init(); glutDisplayFunc(display); glutIdleFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutKeyboardFunc(processNormalKeys); glutMainLoop(); return 0;}