/* 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