The library also includes a set of utility routines for drawing some of the more common extruded shapes: a polycylinder, a polycone, a gneralized torus (circle swept along a helical path), a "helix" (arbitrary contour swept along a helical path) and a "lathe" (arbitrary contour swept along a helical path, with torsion used to keept the contour aligned).
The most general extrusion supported by this library allows an arbitrary 2D contour to be swept around an arbitrary 3D path. A set of normal vectors can be specified to go along with the contour; the normal vectors determine the appearence of the contour when lighting is turned on. A set of colors and affine matrices can be specified to go along with the 3D path. The colors are used to color along the path. The affine matrices are used to operate on the contour as it is swept along. If no affine matrices are specified, the contour is extruded using the mathematical concept of "parrallel translation" or "gaussian translation". If there are affine matrices, they effictively introduce a local coordinate system that makes the local space non-euclidean. (In the terms of general relativity, the affines are the local metric. I'm not fooling or showing off here -- a simplified verion of the conecpts of general relativity, as in "Einstein", really are operational here. However, since there is no time, maybe non-euclidean geometry is a better term. Also, apologies to math-heads, I made the affines 2x3 instead of 3x4 because the swept contours are 2D not 3D. This makes it easier to understand/explain for the purposes of computer graphics. The 3D version would have made the explanation harder, while bringing very little extra function/feature to any common computer graphics usage. Maybe next time ...).
#define gleDouble double typedef gleDouble gleAffine[2][3];
Note that when two segments meet at a shallow angle, the cut join style will potentially shave off a whole lot of the contour, leading to "surprising" results...
int getjoinstyle (void);
void setjoinstyle (int style); /* bitwise OR of flags */
void polycylinder (int npoints, /* num points in polyline */ gleDouble point_array[][3], /* polyline vertces */ float color_array[][3], /* colors at polyline verts */ gleDouble radius); /* radius of polycylinder */
Note that neither the very first segment, nor the very last segment are drawn. The first and last segments serve only to define the angle of the join at the very ends of the polyline. Thus, to draw one segment, three must be specified. To draw two segments, four must be specified, etc.
The color array may be NULL. If NULL, the current color is used. If not NULL, the glColor3f() routine is used to set the color; therefore, specifying the glColorMatrial() subroutine beore this primitive can be used to set diffuse, specular, ambient, etc. colors.
void polycone (int npoints, /* numpoints in poly-line */ gleDouble point_array[][3], /* polyline vertices */ float color_array[][3], /* colors at polyline verts */ gleDouble radius_array[]); /* cone radii at polyline verts */
Note that neither the very first segment, nor the very last segment are drawn. The first and last segments serve only to define the angle of the join at the very ends of the polyline. Thus, to draw one segment, three must be specified. To draw two segments, four must be specified, etc.
The color array may be NULL. If NULL, the current color is used. If not NULL, the glColor3f() routine is used to set the color; therefore, specifying the glColorMatrial() subroutine beore this primitive can be used to set diffuse, specular, ambient, etc. colors.
void extrusion (int ncp, /* number of contour points */ gleDouble contour[][2], /* 2D contour */ gleDouble cont_normal[][2], /* 2D contour normals */ gleDouble up[3], /* up vector for contour */ int npoints, /* numpoints in poly-line */ gleDouble point_array[][3], /* polyline vertices */ float color_array[][3]); /* colors at polyline verts */
Note that neither the very first segment, nor the very last segment are drawn. The first and last segments serve only to define the angle of the join at the very ends of the polyline. Thus, to draw one segment, three must be specified. To draw two segments, four must be specified, etc.
The normal array may be NULL. If it is, normal vectors will NOT be automatically generated, and the object will look terrible when lit.
The color array may be NULL. If NULL, the current color is used. If not NULL, the glColor3f() routine is used to set the color; therefore, specifying the glColorMatrial() subroutine beore this primitive can be used to set diffuse, specular, ambient, etc. colors.
void twist_extrusion (int ncp, /* number of contour points */ gleDouble contour[][2], /* 2D contour */ gleDouble cont_normal[][2], /* 2D contour normals */ gleDouble up[3], /* up vector for contour */ int npoints, /* numpoints in poly-line */ gleDouble point_array[][3], /* polyline vertices */ float color_array[][3], /* color at polyline verts */ gleDouble twist_array[]); /* countour twists (in degrees) */
The argument "contour" specifies the 2D contour to be extruded, while the argument "point_array" specifies the path alomng which to extrude. The vector "up" defines the orientation of the contour y-axis in real 3D space.
Note that neither the very first segment, nor the very last segment are drawn. The first and last segments serve only to define the angle of the join at the very ends of the polyline. Thus, to draw one segment, three must be specified. To draw two segments, four must be specified, etc.
The normal array may be NULL. If it is, normal vectors will NOT be automatically generated, and the object will look terrible when lit.
The color array may be NULL. If NULL, the current color is used. If not NULL, the glColor3f() routine is used to set the color; therefore, specifying the glColorMatrial() subroutine beore this primitive can be used to set diffuse, specular, ambient, etc. colors.
void super_extrusion (int ncp, /* number of contour points */ gleDouble contour[][2], /* 2D contour */ gleDouble cont_normal[][2], /* 2D contour normals */ gleDouble up[3], /* up vector for contour */ int npoints, /* numpoints in poly-line */ gleDouble point_array[][3], /* polyline vertices */ float color_array[][3], /* color at polyline verts */ gleDouble xform_array[][2][3]); /* 2D contour xforms */
The argument "contour" specifies the 2D contour to be extruded, while the argument "point_array" specifies the path alomng which to extrude. The vector "up" defines the orientation of the contour y-axis in real 3D space.
Note that neither the very first segment, nor the very last segment are drawn. The first and last segments serve only to define the angle of the join at the very ends of the polyline. Thus, to draw one segment, three must be specified. To draw two segments, four must be specified, etc.
The normal array may be NULL. If it is, normal vectors will NOT be automatically generated, and the object will look terrible when lit.
The color array may be NULL. If NULL, the current color is used. If not NULL, the glColor3f() routine is used to set the color; therefore, specifying the glColorMatrial() subroutine beore this primitive can be used to set diffuse, specular, ambient, etc. colors.
void spiral (int ncp, /* number of contour points */ gleDouble contour[][2], /* 2D contour */ gleDouble cont_normal[][2], /* 2D contour normals */ gleDouble up[3], /* up vector for contour */ gleDouble startRadius, /* spiral starts in x-y plane */ gleDouble drdTheta, /* change in radius per revolution */ gleDouble startZ, /* starting z value */ gleDouble dzdTheta, /* change in Z per revolution */ gleDouble startXform[2][3], /* starting contour affine xform */ gleDouble dXformdTheta[2][3], /* tangent change xform per revoln */ gleDouble startTheta, /* start angle in x-y plane */ gleDouble sweepTheta); /* degrees to spiral around */
The axis of the helix lies along the modeling coordinate z-axis.
An affine transform can be applied as the contour is swept. For most ordinary usage, the affines should be given as NULL.
void lathe (int ncp, /* number of contour points */ gleDouble contour[][2], /* 2D contour */ gleDouble cont_normal[][2], /* 2D contour normals */ gleDouble up[3], /* up vector for contour */ gleDouble startRadius, /* spiral starts in x-y plane */ gleDouble drdTheta, /* change in radius per revolution */ gleDouble startZ, /* starting z value */ gleDouble dzdTheta, /* change in Z per revolution */ gleDouble startXform[2][3], /* starting contour affine xform */ gleDouble dXformdTheta[2][3], /* tangent change xform per revoln */ gleDouble startTheta, /* start angle in x-y plane */ gleDouble sweepTheta); /* degrees to spiral around */
The axis of the helix lies along the modeling coordinate z-axis.
An affine transform can be applied as the contour is swept. For most ordinary usage, the affines should be given as NULL.
void helicoid (gleDouble rToroid, /* circle contour (torus) radius */ gleDouble startRadius, /* spiral starts in x-y plane */ gleDouble drdTheta, /* change in radius per revolution */ gleDouble startZ, /* starting z value */ gleDouble dzdTheta, /* change in Z per revolution */ gleDouble startXform[2][3], /* starting contour affine xform */ gleDouble dXformdTheta[2][3], /* tangent change xform per revoln */ gleDouble startTheta, /* start angle in x-y plane */ gleDouble sweepTheta); /* degrees to spiral around */