/* 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=9; GLUnurbsObj *myNurb; int uOrder=3; int numKnots; GLfloat x = sqrt(2)/2; GLfloat points[9][4]; GLfloat pointsWeights[9][4] = { /*{0,-0.5,0,1}, {0.5,-0.5,0,0.5}, {0.25,-0.0669873,0,1}, {0,0.3880254,0,0.5}, {-0.25,-0.0669873,0,1}, {-0.5,-0.5,0,0.5}, {0,-0.5,0,1},*/ {1,0,0,1},{1,1,0,x},{0,1,0,1},{-1,1,0,x},{-1,0,0,1},{-1,-1,0,x}, {0,-1,0,1}, {1,-1,0,x},{1,0,0,1}, /* GLfloat conicPointsWeights[7][4]= {{x,y,0,1},{x,y,x,0.5},{-x,y,x,0.5}, {-x,y,0,1},{-x,y,-x,0.5},{x,y,-x,0.5}, {x,y,0,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