Java examples for javax.media.opengl:Draw
opengl draw Hoop
import java.awt.Color; import javax.media.opengl.GL; import javax.vecmath.Point3d; public class Main{ public static void drawHoop(GL gl, double hoopRadius, double tubeRadius) { int segmentsA = 100; int segmentsB = 100; for (int i = 50; i <= segmentsA; i++) { double angleA1 = 2 * Math.PI * (-0.5 + (double) (i - 1) / segmentsA); double x0 = Math.sin(angleA1) * hoopRadius; double y0 = Math.cos(angleA1) * hoopRadius; double angleA2 = 2 * Math.PI * (-0.5 + (double) i / segmentsA); double x1 = Math.sin(angleA2) * hoopRadius; double y1 = Math.cos(angleA2) * hoopRadius; gl.glBegin(GL.GL_QUAD_STRIP); for (int j = 0; j <= segmentsB; j++) { double angleB = 2 * Math.PI * (double) (j - 1) / segmentsB; double x = Math.cos(angleB) * tubeRadius; double y = Math.sin(angleB) * tubeRadius; gl.glNormal3d(x0 + x, y0, y0 * y); gl.glVertex3d(x0 + x, y0, y0 * y); gl.glNormal3d(x1 + x, y1, y1 * y); gl.glVertex3d(x1 + x, y1, y1 * y); }/*from ww w . j a v a2 s . c o m*/ gl.glEnd(); } } }