// lab2.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include "Lego.h" static const GLdouble zToModel = 15 * Lego::lengthUnit; static GLfloat animTime = 5.0; // modified by glutTimerFunc, used by glutDisplayFunc static const unsigned int fps = 60; // used by timer and to start timer off GLfloat xAngle = 0; GLfloat yAngle = 0; GLfloat zAngle = 0; 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(h); GLdouble zNear = zToModel - 100, zFar = zToModel + 100; //assert (zNear > 0); gluPerspective(fovy, aspect, zNear, zFar); glMatrixMode(GL_MODELVIEW); } } 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(xAngle, 1, 0, 0); glRotatef(yAngle, 0, 1, 0); glRotatef(zAngle, 0, 0, 1); myLego.brick("yellow"); glPopMatrix(); glutSwapBuffers(); } 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) { xAngle = xAngle + xAngle*0.10; } else if (button == GLUT_LEFT_BUTTON) { } else if (button == GLUT_MIDDLE_BUTTON) { } } 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; }