7void drawTorus(
float rc,
int numc,
float rt,
int numt)
14 pi = 3.14159265358979323846;
17 for (i = 0; i < numc; i++) {
19 for (j = 0; j <= numt; j++) {
20 for (k = 1; k >= 0; k--) {
21 s = (i + k) % numc + 0.5;
24 x = cos(t*twopi/numt) * cos(s*twopi/numc);
25 y = sin(t*twopi/numt) * cos(s*twopi/numc);
26 z = sin(s*twopi/numc);
29 x = (rt + rc * cos(s*twopi/numc)) * cos(t*twopi/numt);
30 y = (rt + rc * cos(s*twopi/numc)) * sin(t*twopi/numt);
31 z = rc * sin(s*twopi/numc);
43 mag = sqrt( x*x + y*y + z*z );
57 ymax = zNear * tan( fovy *
M_PI / 360.0 );
63 glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
88 da = 2.0*
M_PI / slices;
89 dr = (topRadius-baseRadius) / stacks;
91 nz = (baseRadius-topRadius) / height;
93 for (i=0;i<slices;i++) {
102 for (j=0;j<=stacks;j++) {
104 normal3f(
x1*nsign, y1*nsign, nz*nsign );
107 normal3f(
x2*nsign, y2*nsign, nz*nsign );
112 normal3f(
x2*nsign, y2*nsign, nz*nsign );
115 normal3f(
x1*nsign, y1*nsign, nz*nsign );
143 da = 2.0*
M_PI / slices;
144 dr = (outerRadius-innerRadius) / (
GLfloat) loops;
148 dtc = 2.0f * outerRadius;
151 for (l=0;l<loops;l++) {
154 for (s=0;s<=slices;s++) {
155 if (s==slices)
a = 0.0;
157 sa = sin(
a); ca = cos(
a);
174 float radius,
int slices,
int stacks)
176 float rho, drho, theta, dtheta;
179 int i, j, imin, imax;
186 drho =
M_PI / (float) stacks;
187 dtheta = 2.0 *
M_PI / (float) slices;
194 for (j=0;j<=slices;j++) {
195 theta = (j==slices) ? 0.0 : j * dtheta;
196 x = -sin(theta) * sin(drho);
197 y = cos(theta) * sin(drho);
198 z = nsign * cos(drho);
199 if (normals)
glNormal3f( x*nsign, y*nsign, z*nsign );
218 for (i=imin;i<imax;i++) {
222 for (j=0;j<=slices;j++) {
223 theta = (j==slices) ? 0.0 : j * dtheta;
224 x = -sin(theta) * sin(rho);
225 y = cos(theta) * sin(rho);
226 z = nsign * cos(rho);
227 if (normals)
glNormal3f( x*nsign, y*nsign, z*nsign );
230 x = -sin(theta) * sin(rho+drho);
231 y = cos(theta) * sin(rho+drho);
232 z = nsign * cos(rho+drho);
233 if (normals)
glNormal3f( x*nsign, y*nsign, z*nsign );
250 for (j=slices;j>=0;j--) {
251 theta = (j==slices) ? 0.0 : j * dtheta;
252 x = -sin(theta) * sin(rho);
253 y = cos(theta) * sin(rho);
254 z = nsign * cos(rho);
255 if (normals)
glNormal3f( x*nsign, y*nsign, z*nsign );
void glVertex2f(float x, float y)
void glVertex3f(float x, float y, float z)
void glNormal3f(float x, float y, float z)
void glTexCoord2f(float s, float t)
void glFrustum(double left, double right, double bottom, double top, double near, double far)
void gluQuadricDrawStyle(GLUquadricObj *obj, int style)
void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
void drawTorus(float rc, int numc, float rt, int numt)
void gluDisk(GLUquadricObj *qobj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint loops)
void gluSphere(GLUquadricObj *qobj, float radius, int slices, int stacks)
void gluCylinder(GLUquadricObj *qobj, GLdouble baseRadius, GLdouble topRadius, GLdouble height, GLint slices, GLint stacks)
GLUquadricObj * gluNewQuadric(void)