/** Draw a surface of revolution */ import javax.media.opengl.*; public class SurfaceOfRevolution{ //default profile -- a wine glass static double[][] profile = {{0.26,0},{0.26,0},{0.09,0.02},{0.07,0.02},{0.04,0.05},{0.02,0.05},{0.02,0.38},{0.05,0.46},{0.14,0.56},{0.41,0.98},{0.4,0.99},{0.11,0.57},{0.04,0.51},{0,0.5}}; public static void surface(GL gl, int level){ surface(gl,level,profile); } //surface of revolution given array containing points of the profile // profile[0][0] is x coord of first point, // profile[0][1] is y coord of first point, public static void surface(GL gl, int level, double[][] profile){ double h = 1.0f/level; for (int i = 1; i < profile.length; i++){ double s = i/(double)profile.length; gl.glBegin(GL.GL_TRIANGLE_STRIP); for (int j = 0; j <= level; j++){ double t = j*h; double angle = t*2.0*Math.PI; double cos = Math.cos(angle); double sin = Math.sin(angle); gl.glNormal3d(cos,0.0,sin); //normal to a circle is radius gl.glTexCoord2d(s-h,t); gl.glVertex3d(profile[i-1][0]*cos,profile[i-1][1],profile[i-1][0]*sin); gl.glTexCoord2d(s,t); gl.glVertex3d(profile[i][0]*cos,profile[i][1],profile[i][0]*sin); } gl.glEnd(); } } }