/** Functions for drawing characters from star wars in OpenGL. Probably breaks 1/2 dozen different laws. */ import javax.media.opengl.*; import javax.media.opengl.glu.*; import com.sun.opengl.util.*; public class StarWars { public static void xwing(GL gl, int slices){ GLU glu = new GLU(); GLUquadric qobj = glu.gluNewQuadric(); glu.gluQuadricDrawStyle(qobj, GLU.GLU_FILL); glu.gluQuadricTexture(qobj, true); gl.glTranslatef(0,0,-1.5f); gl.glPushMatrix(); gl.glScaled(1, 1, 4); glu.gluCylinder(qobj, 0.7, 0.3, 1.0, slices, 5); gl.glPopMatrix(); gl.glPushMatrix(); gl.glRotatef(25, 0, 0, 1); wing(gl); gl.glRotatef(-50, 0, 0, 1); // <-- Could replace this line with glPushMatrix, glRotate(-30) wing(gl); gl.glRotatef(-150, 0, 0, 1); wing(gl); gl.glRotatef(-30, 0, 0, 1); wing(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(0, 0, 4); glu.gluCylinder(qobj, 0.3, 0, 0.4, slices, 5); gl.glPopMatrix(); } static void wing(GL gl){ // Body of the wing. gl.glPushMatrix(); gl.glScaled(2.5, 0.1, 1); gl.glTranslated(0.5, 0, 0.5); Shapes.cube(gl,1); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslated(2.5, 0, 0); cannon(gl); gl.glPopMatrix(); } static void cannon(GL gl){ GLU glu = new GLU(); GLUquadric qobj = glu.gluNewQuadric(); glu.gluQuadricTexture(qobj, true); gl.glPushMatrix(); glu.gluQuadricDrawStyle(qobj, GLU.GLU_FILL); glu.gluCylinder(qobj, 0.1, 0.1, 1.2, 10, 5); glu.gluCylinder(qobj, 0.05, 0.05, 2.4, 10, 5); gl.glPopMatrix(); } }