#include #include #include #include #include #define MAXPTS 20 #define EPS 0.000001 #define EQUIDISTANT_WIREFRAME 1 #define INTERPOLATE_WIREFRAME 2 #define EQUIDISTANT_ANALYTIC 3 #define INTERPOLATE_ANALYTIC 4 #define EQUIDISTANT_DEBOER 5 #define INTERPOLATE_DEBOER 6 int mousex, mousey; int sirka=800, vyska=600; int N,M,D1,D2; double V[MAXPTS][MAXPTS][3],w[MAXPTS][MAXPTS]; int sel_pt_i=0,sel_pt_j=0,color=0,mode=0; int is_ctrl,is_alt,is_shift; double ZOOM=2.0,XOFFSET=-1.0,YOFFSET=0.0,ROTATEX=15.0,ROTATEY=0.0,STEP=0.05; GLuint wlist,slist1,slist2; int SHOW_PTS=1; double s[100],t[100],N1[50][50],N2[50][50]; void PisVektorovyText(GLfloat x, GLfloat y, char *format,...) { va_list args; char buffer[200], *p; va_start(args, format); vsprintf(buffer, format, args); va_end(args); glPushMatrix(); glLoadIdentity(); glTranslatef(-1.0,0.0,-6.0f); // glRotatef(10,1.0,0.0,0.0); glRotatef(0,0.0,1.0,0.0); glScalef(2,2,-2); glTranslatef(x, y, 0); glScalef(0.0007,0.0007,0.0007); for (p = buffer; *p; p++) glutStrokeCharacter(GLUT_STROKE_ROMAN, *p); glPopMatrix(); } void SetVertexColor(double u, double v) { glColor3d(u,v,1.0-u-v); } int ComputeAnalyticPoint(double u, double v, double *x, double *y, double *z){ int i,j; double ss,tt,cit,men; if (u>=1.0) u=0.9999; if (v>=1.0) v=0.9999; ss=s[D1]+u*(s[N+1]-s[D1]); tt=t[D2]+v*(t[M+1]-t[D2]); for (i=0;i<=N+D1;i++) if ((ss>=s[i])&&(ssEPS) N1[i][j] += N1[i][j-1] * ( (ss-s[i]) / (s[i+j]-s[i]) ); if (s[i+j+1]-s[i+1]>EPS) N1[i][j] += N1[i+1][j-1] * ( (s[i+j+1]-ss) / (s[i+j+1]-s[i+1]) ); } for (i=0;i<=M+D2;i++) if ((tt>=t[i])&&(ttEPS) N2[i][j] += N2[i][j-1] * ( (tt-t[i]) / (t[i+j]-t[i]) ); if (t[i+j+1]-t[i+1]>EPS) N2[i][j] += N2[i+1][j-1] * ( (t[i+j+1]-tt) / (t[i+j+1]-t[i+1]) ); } cit=men=0.0; for (i=0;i<=N;i++) for (j=0;j<=M;j++) men+=w[i][j]*N1[i][D1]*N2[j][D2]; if (fabs(men)0.01) STEP-=0.01; if ((mode==1)||(mode==2)) GenerateNURBWireframe(); if ((mode==3)||(mode==4)) GenerateNURBSolidAnalytic(); if ((mode==5)||(mode==6)) GenerateNURBSolidDeBoer(); break; case 'p': SHOW_PTS^=1; break; } glutPostRedisplay(); } void keypressed_special(int key, int x, int y) { is_ctrl=glutGetModifiers(); is_alt=is_ctrl&GLUT_ACTIVE_ALT; is_shift=is_ctrl&GLUT_ACTIVE_SHIFT; is_ctrl=is_ctrl&GLUT_ACTIVE_CTRL; if (is_alt) { switch (key) { case GLUT_KEY_UP: ROTATEX+=2; break; case GLUT_KEY_DOWN: ROTATEX-=2; break; case GLUT_KEY_LEFT: ROTATEY+=2; break; case GLUT_KEY_RIGHT: ROTATEY-=2; break; } } if (is_ctrl) { switch (key) { case GLUT_KEY_UP: YOFFSET-=STEP; break; case GLUT_KEY_DOWN: YOFFSET+=STEP; break; case GLUT_KEY_LEFT: XOFFSET+=STEP; break; case GLUT_KEY_RIGHT: XOFFSET-=STEP; break; } } if (is_shift) { switch (key) { case GLUT_KEY_PAGE_UP: V[sel_pt_i][sel_pt_j][1]+=0.025; break; case GLUT_KEY_PAGE_DOWN: V[sel_pt_i][sel_pt_j][1]-=0.025; break; case GLUT_KEY_UP: V[sel_pt_i][sel_pt_j][2]+=0.025; break; case GLUT_KEY_DOWN: V[sel_pt_i][sel_pt_j][2]-=0.025; break; case GLUT_KEY_LEFT: V[sel_pt_i][sel_pt_j][0]-=0.025; break; case GLUT_KEY_RIGHT: V[sel_pt_i][sel_pt_j][0]+=0.025; break; } if ((mode==1)||(mode==2)) GenerateNURBWireframe(); if ((mode==3)||(mode==4)) GenerateNURBSolidAnalytic(); if ((mode==5)||(mode==6)) GenerateNURBSolidDeBoer(); } if ((!is_alt)&&(!is_ctrl)&&(!is_shift)) { switch (key) { case GLUT_KEY_UP: if (sel_pt_j0) sel_pt_j--; break; case GLUT_KEY_LEFT: if (sel_pt_i>0) sel_pt_i--; break; case GLUT_KEY_RIGHT: if (sel_pt_i