/* plot_tri_basis2.c and test */ /* triangle points: 1 is 0,0 2 is 0,4 3 is 4,4 * mid points: 4 is 0,2 5 is 2,4 6 is 2,2 * 0,4 * * / \ * 0,3 *---* 1,4 * / \ / \ inside points * 0,2 *---*---* 2,4 1,3 * / \ / \ / \ * 0,1 *---*---*---* 3,4 1,2 2,3 * / \ / \ / \ / \ * 0,0 *---*---*---*---* 4,4 * 1,1 2,2 3,3 * * base is blue dots * function is green lines with red dots */ #include #include #include #include #include "tri_basis.h" /* geometry in tri_basis.c */ static int width=600; static int height=600; static double T[6] = {1.0,1.0, 3.0,2.0, 3.5,0.5}; /* irregular */ /* static double T[6] = {0.0,0.0, 0.0,3.0, 3.0,0.0}; regular */ static double xp[5][5], yp[5][5], zp[5][5]; static int np = 5; static double xmin = 0.0; static double xmax = 4.0; static double ymin = 0.0; static double ymax = 4.0; static double zmin = -1.5; static double zmax = 4.0; static float offset = 0.0; static GLfloat theta[] = {-60.0,0.0,30.0}; static GLint axis = 2; static int stop = 0; static int next = 0; void compute_phi1() { int i, j, k, ip, jp; double x, y; double z; for(i=0; i 360.0) theta[axis] = theta[axis] - 360.0; /* display(); */ glutPostRedisplay(); } /* end spinCube */ void mouse(int btn, int state, int x, int y) { /* mouse callback, selects an axis about which to rotate */ if(btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN) axis = 0; if(btn==GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) axis = 1; if(btn==GLUT_RIGHT_BUTTON && state == GLUT_DOWN) axis = 2; } /* end mouse */ static void keyboard(unsigned char key, int x, int y) { if(key=='s' || key=='S') stop = 1; if(key=='g' || key=='G') stop = 0; if(key=='n' || key=='N') { next++; if(next>6) next = 0; } glutPostRedisplay(); } /* end keyboard */ static void special(int k, int x, int y) { switch(k) { case GLUT_KEY_LEFT: axis = 1; break; case GLUT_KEY_RIGHT: axis = 2; break; case GLUT_KEY_DOWN: axis = 0; break; } glutPostRedisplay(); } void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-xmax, xmax, -ymax, ymax, -zmax, zmax); glMatrixMode(GL_MODELVIEW); } /* end myReshape */ void init() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-xmax, xmax, -ymax, ymax, -zmax, zmax); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(1.0, 1.0, 1.0, 1.0); xp[0][0] = T[0]; yp[0][0] = T[1]; xp[0][4] = T[2]; yp[0][4] = T[3]; xp[4][4] = T[4]; yp[4][4] = T[5]; xp[0][2] = (xp[0][0]+xp[0][4])/2.0; yp[0][2] = (yp[0][0]+yp[0][4])/2.0; xp[0][1] = (xp[0][0]+xp[0][2])/2.0; yp[0][1] = (yp[0][0]+yp[0][2])/2.0; xp[0][3] = (xp[0][4]+xp[0][2])/2.0; yp[0][3] = (yp[0][4]+yp[0][2])/2.0; xp[2][2] = (xp[4][4]+xp[0][0])/2.0; yp[2][2] = (yp[4][4]+yp[0][0])/2.0; xp[1][1] = (xp[0][0]+xp[2][2])/2.0; yp[1][1] = (yp[0][0]+yp[2][2])/2.0; xp[1][2] = (xp[0][2]+xp[2][2])/2.0; yp[1][2] = (yp[0][2]+yp[2][2])/2.0; xp[2][4] = (xp[0][4]+xp[4][4])/2.0; yp[2][4] = (yp[0][4]+yp[4][4])/2.0; xp[2][3] = (xp[2][2]+xp[2][4])/2.0; yp[2][3] = (yp[2][2]+yp[2][4])/2.0; xp[1][3] = (xp[0][3]+xp[2][3])/2.0; yp[1][3] = (yp[0][3]+yp[2][3])/2.0; xp[1][4] = (xp[0][4]+xp[2][4])/2.0; yp[1][4] = (yp[0][4]+yp[2][4])/2.0; xp[3][3] = (xp[2][2]+xp[4][4])/2.0; yp[3][3] = (yp[2][2]+yp[4][4])/2.0; xp[3][4] = (xp[2][4]+xp[4][4])/2.0; yp[3][4] = (yp[2][4]+yp[4][4])/2.0; } /* end init */ int main(int argc, char *argv[]) { glutInit(&argc, argv); /* need both double buffering and z buffer */ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(width, height); glutCreateWindow(argv[0]); glutReshapeFunc(myReshape); init(); glutDisplayFunc(display); glutIdleFunc(spinCube); /* "spinCube" setup */ glutMouseFunc(mouse); /* "mouse" setup */ glutKeyboardFunc(keyboard); /* enable keyboard */ glutSpecialFunc(special); /* enable arrow keys */ glutMainLoop(); return 0; }