Introduction: The goal of this project is to create an animated scene of Bézier curves. It must be in 3D (i.e., Z cannot
Posted: Fri Jun 10, 2022 11:55 am
{ float r, g, b; Point po, p1, p2, p3; }; Curve Curves [NUMCURVES]; // if you are creating a pattern of curves Curve Stem; // if you are not Reminder: The Cubic Bézier Equation P = (1.-t)3P0+ 3t(1.-t)2P1 + 3t2(1.-t)P2 + t3P3 0.≤t≤ 1.
Rotating a Point an Angle about the X Axis Around a Center void RotateX( Point *p, float deg, float xc, float yc, float zc ) { float rad deg * (M_PI/180.f); // radians float xp->x0 XC; float y p->ye - yc; = float z = p->z - Zc; float xp = x; z* sin(rad); float yp = y*cos (rad) float zp = y*sin(rad) + z*cos(rad); p->x= xp + Xc; р->у = ур +yc; p->z = zp+zC; } Rotating a Point an Angle about the Y Axis Around a Center void RotateY( Point *p, float deg, float xc, float yc, float zc ) { float rad deg * (M_PI/180.f); // radians float xp->x0 - Xc; float y p->ye yc; float z = p->z@ - ZC; float xp = x*cos(rad) + z*sin(rad); float yp= y; float zp = -x* sin(rad) + z*cos(rad); p->x= xp + Xc; р->у = ур +yc; p->z = zp + ZC; }
Rotating a Point an Angle about the Z Axis Around a Center void Rotatez( Point *p, float deg, float xc, float yc, float zc ) { float rad = deg* (M_PI/180.f); // radians float xp->x0 XC; float y = p->ye ус; float z = p->ze 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 = ypyc; p->z = zp + zc; } Drawing a Bézier Curve glLineWidth( 3.); glColor3f(r, g, b); glBegin( GL_LINE_STRIP ); for(int it = 0; it <= NUMPOINTS; it++) { float t= (float)it/ (float) NUMPOINTS; float omt 1.f - t; float x = omt*omt*omt* p0.x + 3. f*t*omt*omt*p1.x + 3.f*t*t*omt*p2.x + t*t*t*p3.x; float y = omt*omt*omt*p.y + 3.f*t*omt*omt*p1.y + 3. f*t*t*omt*p2.y + t*t*t*p3.y;
float z = omt*omt*omt* p0.z + 3. f*t*omt*omt*p1.z + 3.f*t*t*omt*p2.z + t*t*t*p3.z; glVertex3f(x, y, z); } glEnd(); glLineWidth( 1.); How Did Joe Graphics Get That Nice Color Progression? He 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 slide # 53 of the Getting Started notes.