#include #include #include #include #include #include "model.h" #include "camera.h" using namespace std; float Light[4]={0,0,500,1}; bool perspective; bool keyboardState[256]; bool mouseState[3]; model *Model; list point; int X,Y,X1,Y1; int W,H; camera *Perspective; float jaw=0.0f; void makeProj(){ glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (45.0, (GLfloat) W/(GLfloat) H, 1.0, 1000.0); //Set projection Perspective->getCamera(); //Set view } void display(){ glPushMatrix(); glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); makeProj(); glMatrixMode (GL_MODELVIEW); glEnable(GL_LIGHT0); Model->drawModel(keyboardState['t']); glutSwapBuffers(); glutPostRedisplay(); } void motion(int x, int y){ if(mouseState[0]){ //left mouse button if(keyboardState['a']) Model->rotateX(x-X); if(keyboardState['b']) Model->rotateY(x-X); if(keyboardState['c']) Model->rotateZ(x-X); if(keyboardState['e']){ Model->lookRight(x-X); Model->lookUp(y-Y); } if(keyboardState['m']){ Model->openMouth(y-Y); } if(keyboardState['n']){ Model->openJaw(y-Y); } Model->applyMouthFFD(); } if(mouseState[2]){ //right mouse button if(keyboardState['x']) Model->translate(x-X,0.0,0.0); if(keyboardState['y']) Model->translate(0.0,x-X,0.0); if(keyboardState['z']) Model->translate(0.0,0.0,x-X); if(keyboardState['i']){ if(keyboardState['l']) Model->lowerLeftBrowI((float)(Y-y)); if(keyboardState['k']) Model->lowerRightBrowI((float)(Y-y)); } if(keyboardState['o']){ if(keyboardState['l']) Model->lowerLeftBrowO((float)(Y-y)); if(keyboardState['k']) Model->lowerRightBrowO((float)(Y-y)); } Model->applyBrowFFD(); } X=x; Y=y; } void mouse(int button, int state, int x, int y){ mouseState[button]=!state; X=x; Y=y; } void keyboard(unsigned char key, int x, int y){ keyboardState[key]=true; if(key=='r') Model->reset(); if(key=='u'){ Model->Oface(-0.5); Model->applyMouthFFD(); } if(key=='j'){ Model->Oface(0.5); Model->applyMouthFFD(); } if(key=='q'){ Model->curlLip(-0.5); Model->applyMouthFFD(); } if(key=='w'){ Model->curlLip(0.5); Model->applyMouthFFD(); } if(key=='-'){ Model->raiseRight(0.5); Model->raiseLeft(0.5); Model->applyMouthFFD(); } if(key=='='){ Model->raiseRight(-0.5); Model->raiseLeft(-0.5); Model->applyMouthFFD(); } } void keyboardUp(unsigned char key, int x, int y){ keyboardState[key]=false; } void reshape (int w, int h) { W=w; H=h; glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (45.0, (GLfloat) W/(GLfloat) H, 1.0, 600.0); Perspective->getCamera(); glMatrixMode (GL_MODELVIEW); glLoadIdentity(); } void glInit () { glClearColor (0.0, 0.0, 0.0, 0.0); GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 0.1 }; GLfloat light_diffuse[] = { 0.8, 0.8, 0.8, 0.1 }; GLfloat light_specular[] = { 0.5, 0.5, 0.5, 0.1 }; glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_POSITION, Light); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnableClientState (GL_VERTEX_ARRAY); glEnableClientState (GL_NORMAL_ARRAY); glEnable(GL_NORMALIZE); glEnable(GL_DEPTH_TEST); glDepthMask(1); glDepthFunc(GL_LEQUAL); } void init(){ Perspective=new camera(); Model=new model("head"); } int main(int argc, char** argv){ glutInit(&argc, argv); glutInitDisplayMode (GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH|GLUT_STENCIL); glutInitWindowSize (900, 900); glutCreateWindow ("Final Project"); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutKeyboardUpFunc(keyboardUp); glutMouseFunc(mouse); glutMotionFunc(motion); glutReshapeFunc(reshape); glInit (); init(); glutMainLoop(); return 0; }