/********************************************************************* Simple b-spline curve algorithm Copyright 1994 by Keith Vertanen (vertankd@cda.mrs.umn.edu) Released to the public domain (your mileage may vary) **********************************************************************/ #include #include struct point { double x; double y; double z; }; int set_graph(void); void compute_intervals(int *u, int n, int t); double blend(int k, int t, int *u, double v); void compute_point(int *u, int n, int t, double v, point *control, point *output); void bspline(int n, int t, point *control, point *output, int num_output) /********************************************************************* Parameters: n - the number of control points minus 1 t - the degree of the polynomial plus 1 control - control point array made up of point stucture output - array in which the calculate spline points are to be put num_output - how many points on the spline are to be calculated Pre-conditions: n+2>t (no curve results if n+2<=t) control array contains the number of points specified by n output array is the proper size to hold num_output point structures **********************************************************************/ { int *u; double increment,interval; point calcxyz; int output_index; u=new int[n+t+1]; compute_intervals(u, n, t); if (num_output>1) increment=(double) (n-t+2)/(num_output-1); // how much parameter goes up each time else increment=0; // stupid user wants only one frame interval=0; for (output_index=0; output_indexn) u[j]=n-t+2; // if n-t=-2 then we're screwed, everything goes to 0 } } void compute_point(int *u, int n, int t, double v, point *control, point *output) { int k; double temp; // initialize the variables that will hold our outputted point output->x=0; output->y=0; output->z=0; for (k=0; k<=n; k++) { temp = blend(k,t,u,v); // same blend is used for each dimension coordinate output->x = output->x + (control[k]).x * temp; output->y = output->y + (control[k]).y * temp; output->z = output->z + (control[k]).z * temp; } } int set_graph(void) { int graphdriver = DETECT, graphmode, error_code; //Initialize graphics system; must be EGA or VGA if (registerbgidriver(EGAVGA_driver)>=0) { initgraph(&graphdriver, &graphmode, ""); error_code = graphresult(); if (error_code != grOk) return(-1); // No graphics hardware found if ((graphdriver != EGA) && (graphdriver != VGA)) { closegraph(); return 0; } return(1); // Graphics OK, so return "true" } else return 0; }