// keep this code please! Was twLighting void twLighting2() { GLfloat lightPosition [] = {1,3,1,1}; GLfloat ambient [] = {0.8,0.8,0.8,1}; GLfloat diffuse [] = {0.8,0.8,0.8,1}; GLfloat specular [] = {0.7,0.7,0.7,1}; glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glEnable(GL_LIGHT0); } /* alternate tw lighting: reddish light from the upper right back */ void twLighting1() { GLfloat lightPosition [] = {1,1,-2,1}; GLfloat ambient [] = {1,0.2,0.2,1}; GLfloat diffuse [] = {1,0.2,0.2,1.0}; GLfloat specular [] = {1,1,1,1.0}; glLightfv(GL_LIGHT1, GL_POSITION, lightPosition); glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, specular); glEnable(GL_LIGHT1); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); } // tw light: light at the given position. Should we make the 1 a // parameter, so this function can do distant lights? void twLight1(GLint lightId, twTriple pos, GLfloat v) { GLfloat lightPosition [] = {pos[0], pos[1], pos[2], 1}; twTriple lightColor = {v,v,v}; glLightfv(lightId, GL_POSITION, lightPosition); glLightfv(lightId, GL_AMBIENT, lightColor); glLightfv(lightId, GL_DIFFUSE, lightColor); glLightfv(lightId, GL_SPECULAR, lightColor); glEnable(lightId); if( Toggles[ LIGHTS ] ) { glPushAttrib(GL_ALL_ATTRIB_BITS); glDisable(GL_LIGHTING); glColor3f(v,v,v); glPointSize(5); glBegin(GL_POINTS); glVertex3fv(pos); glEnd(); glPopAttrib(); } } void twBearMaterial() { twColor(1,0.5,0,0); /* GLfloat matAmbient [] = {1,0.5,0,1}; GLfloat matDiffuse [] = {1,0.5,0,1}; GLfloat matSpecular [] = {0,0,0,1}; GLfloat matShin = 128; glMaterialfv(GL_FRONT,GL_AMBIENT,matAmbient); glMaterialfv(GL_FRONT,GL_DIFFUSE,matDiffuse); glMaterialfv(GL_FRONT,GL_SPECULAR,matSpecular); glMaterialf(GL_FRONT,GL_SHININESS,matShin); */ } // This is really too blue to be steel. Let's do better. void twSteel() { GLfloat matAmbient [] = {0.64,0.72,1.0,1.0}; GLfloat matDiffuse [] = {0.41,0.65,0.62,1.0}; GLfloat matSpecular [] = {0,0.55,0.53,1.0}; GLfloat matShin = 100; glMaterialfv(GL_FRONT,GL_AMBIENT,matAmbient); glMaterialfv(GL_FRONT,GL_DIFFUSE,matDiffuse); glMaterialfv(GL_FRONT,GL_SPECULAR,matSpecular); glMaterialf(GL_FRONT,GL_SHININESS,matShin); } /* twTriple points3[6] = { //head {7,1,-3.5}, {7.5,1,-2.5}, {9,1,-3.8},{9,1,-3.8}, {7.5,1,-5}, {7,1,-4}, }; twTriple points4[3] = { //tongue {8.5,1,-3.8}, {8.8,1,-3.8}, {8.9,1,-4.0}, }; twTriple points5[3] = { //tongue {8.5,1,-3.8}, {8.7,1,-3.8}, {8.9,1,-3.6}, }; //nearest outer edge of snake for(v = 0; v < 15; v++) { surfPoints1[0][v][0] = points2[v][0]; surfPoints1[0][v][1] = points2[v][1]; surfPoints1[0][v][2] = points2[v][2]; } //upper middle of snake for(v = 0; v < 15; v++) { surfPoints1[1][v][0] = pointsUpper[v][0]; surfPoints1[1][v][1] = pointsUpper[v][1]; surfPoints1[1][v][2] = pointsUpper[v][2]; } //farthest outer edge of snake for(v = 0; v < 15; v++) { surfPoints1[2][v][0] = points[v][0]; surfPoints1[2][v][1] = points[v][1]; surfPoints1[2][v][2] = points[v][2]; } //specify all control points here twTriple points[15] = { {-7,1,-3}, {-6,1,-3}, {-5,1,0}, {-4,1,-5}, {-3,1,5}, {-2,1,-3}, {-1,1,3},{0,1,-16}, {1,1,0},{2,1,-3}, {3,1,-10}, {4,1,13},{5,1,-10}, {6,1,-3},{7,1,-4}, }; twTriple points2[15] = { {-7,1,-3}, {-6,1,-2.5}, {-5,1,1}, {-4,1,-4}, {-3,1,6}, {-2,1,-2}, {-1,1,4},{0,1,-15}, {1,1,1},{2,1,-2}, {3,1,-9}, {4,1,14},{5,1,-9}, {6,1,-2.5},{7,1,-3.5}, }; */ /*GLfloat angle = 20.0; int u, v; for(u = 0; u < 100; u++) { for(v = 0; v < 18; v++) { surfPoints1[u][v][0] = points[v][0]*cos(angle);//x-coords surfPoints1[u][v][1] = points[v][1]*sin(angle);//y-coords surfPoints1[u][v][2] = points[u][2]; } }*/ /* /* NURB curve (1-dimension) Written by Caroline Geiersbach and Scott D. Anderson scott.anderson@acm.org Summer 2003 */ /*#include #include #include #include #include "tw.h" //for picking int count; int p; //number of points the user wants int numPoints; GLUnurbsObj *myNurb; int uOrder; //cubic polynomial int numKnots; //specify all control points here twTriple points[15] = { {-7,-3,1}, {-6,-3,1}, {-5,0,1}, {-4,-5,1}, {-3,5,1}, {-2,-3,1}, {-1,3,1},{0,-16,1}, {1,0,1},{2,-3,1}, {3,-10,1}, {4,13,1},{5,-10,1}, {6,-3,1},{7,-4,1}, }; //adapted from Hill pg. 635 void makeKnots(int ord, int pts, GLfloat knot[]) { //pts control points and B-splines of order ord int i; if(pts < ord) { printf("too few control points entered for curve of order %i\n",uOrder); return; } for (i=0; iscreen[0]-4 && yscreen[1]-4) return i; } return 15; } void pick(int x, int y, int element) { if(p<15) { twTriple world; //new coords for element twTriple A,B,V; twTriple winA = {x,y,0}; twTriple winB = {x,y,1}; twUnProject(A,winA); twUnProject(B,winB); twVector(V,B,A); twPointOnLine(points[element],A,V,0.5); } } static int mouse_x, mouse_y; void myMouse(int button, int state, int x, int y) { y=650-y; if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN){ mouse_x=x; mouse_y=y; p = testClick(x,y); } } void myMotion(int x, int y) { y=650-y; pick(x,y,p); glutPostRedisplay(); } void printCoords(unsigned char key, int x, int y) { int i; printf("Your current control points are: \n"); for(i=0; i