This page was last updated: September 12, 2022
The goal of this project is to create an animated scene of Catmull-Rom curves.
'f' | Freeze/un-freeze the animation |
Use the Teach system to turn in your:
struct Point { float x0, y0, z0; // initial coordinates float x, y, z; // animated coordinates }; struct Curve { float r, g, b; Point p0, p1, p2, p3; }; Curve Curves[NUMCURVES]; // if you are creating a pattern of curves Curve Stem; // if you are not
P = 0.5 * [ 2.*P_{1} + t*(-P_{0}+P_{2}) + t^{2}*(2.*P_{0}-5.*P_{1}+4.*P_{2}-P_{3}) + t^{3}*(-P_{0}+3.*P_{1}-3.*P_{2}+P_{3}) ]
0. ≤ t ≤ 1.
void RotateX( Point *p, float deg, float xc, float yc, float zc ) { float rad = deg * (M_PI/180.f); // radians float x = p->x0 - xc; float y = p->y0 - yc; float z = p->z0 - zc; float xp = x; float yp = y*cos(rad) - z*sin(rad); float zp = y*sin(rad) + z*cos(rad); p->x = xp + xc; p->y = yp + yc; p->z = zp + zc; }
void RotateY( Point *p, float deg, float xc, float yc, float zc ) { float rad = deg * (M_PI/180.f); // radians float x = p->x0 - xc; float y = p->y0 - yc; float z = p->z0 - zc; float xp = x*cos(rad) + z*sin(rad); float yp = y; float zp = -x*sin(rad) + z*cos(rad); p->x = xp + xc; p->y = yp + yc; p->z = zp + zc; }
void RotateZ( Point *p, float deg, float xc, float yc, float zc ) { float rad = deg * (M_PI/180.f); // radians float x = p->x0 - xc; float y = p->y0 - yc; float z = p->z0 - zc; float xp = x*cos(rad) - y*sin(rad); float yp = x*sin(rad) + y*cos(rad); float zp = z; p->x = xp + xc; p->y = yp + yc; p->z = zp + zc; }
glLineWidth( 3. ); glColor3f( r, g, b ); glBegin( GL_LINE_STRIP ); for( int it = 0; it <= NUMPOINTS; it++ ) { float t = (float)it / (float)NUMPOINTS; float x = . . . float y = . . . float z = . . . glVertex3f( x, y, z ); } glEnd( ); glLineWidth( 1. );
She used the hue-saturation-value color scale and the HsvRgb( ) function that is included in your sample code. As long as you are using angles to locate points, you can use that same angle to assign a hue and then turn it into an RGB. See the HSV slide of the Getting Started notes.
Item | Points |
At least 1 stationary 3D curve | 10 |
At least 5 animated 3D curves | 40 |
Turn the control points on and off | 20 |
Turn the control lines on and off | 20 |
Make the scene look somewhat recognizeable | 10 |
Potential Total | 100 |