Ejemplo n.º 1
0
 static void drawTorus(float r, float R, int nsides, int rings) {
   float ringDelta = 2.0f * (float) Math.PI / rings;
   float sideDelta = 2.0f * (float) Math.PI / nsides;
   float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f;
   for (int i = rings - 1; i >= 0; i--) {
     float theta1 = theta + ringDelta;
     float cosTheta1 = (float) Math.cos(theta1);
     float sinTheta1 = (float) Math.sin(theta1);
     GL11.glBegin(GL11.GL_QUAD_STRIP);
     float phi = 0.0f;
     for (int j = nsides; j >= 0; j--) {
       phi += sideDelta;
       float cosPhi = (float) Math.cos(phi);
       float sinPhi = (float) Math.sin(phi);
       float dist = R + r * cosPhi;
       GL11.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
       GL11.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
       GL11.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
       GL11.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi);
     }
     GL11.glEnd();
     theta = theta1;
     cosTheta = cosTheta1;
     sinTheta = sinTheta1;
   }
 }