}
public void drawCylinder(float radius, float halfHeight, int upAxis) {
glPushMatrix();
Matrix4f mat = new Matrix4f();
switch (upAxis) {
case 0:
//glRotatef(-90f, 0.0f, 1.0f, 0.0f);
mat.rotY((float)Math.PI * -0.5f);
mulMatrix(mat);
glTranslatef(0.0f, 0.0f, -halfHeight);
break;
case 1:
//glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
mat.rotX((float)Math.PI * -0.5f);
mulMatrix(mat);
glTranslatef(0.0f, 0.0f, -halfHeight);
break;
case 2:
glTranslatef(0.0f, 0.0f, -halfHeight);
break;
default: {
assert (false);
}
}
// The gluCylinder subroutine draws a cylinder that is oriented along the z axis.
// The base of the cylinder is placed at z = 0; the top of the cylinder is placed at z=height.
// Like a sphere, the cylinder is subdivided around the z axis into slices and along the z axis into stacks.
disk.setDrawStyle(Quadric.GLU_FILL);
disk.setNormals(Quadric.GLU_SMOOTH);
disk.draw(gl, 0, radius, 8, 1);
cylinder.setDrawStyle(Quadric.GLU_FILL);
cylinder.setNormals(Quadric.GLU_SMOOTH);
cylinder.draw(gl, radius, radius, 2f * halfHeight, 8, 1);
glTranslatef(0f, 0f, 2f * halfHeight);
mat.rotY(-(float)Math.PI);
mulMatrix(mat);
disk.draw(gl, 0, radius, 8, 1);
glPopMatrix();
}