org.proteinshader.graphics
Class Cylinder

java.lang.Object
  extended by org.proteinshader.graphics.Shape
      extended by org.proteinshader.graphics.Cylinder

public class Cylinder
extends Shape

Knows how to draw a simple cylinder useful for representing the bonds between atoms. The cylinder can be capped with a small sphere at one or both ends. To speed up rendering, methods are provided for creating and using OpenGL display lists.


Field Summary
static int MIN_CAP_TILING
          The minumum tiling (number of slices and stacks) for a capping sphere is 3.
static int MIN_SLICES
          The minimum number of slices for a cylinder is 3.
static int MIN_STACKS
          The minimum number of stacks for a cylinder is 1.
 
Fields inherited from class org.proteinshader.graphics.Shape
HALF_PI, PI, SPECULAR_COLOR, TWO_PI
 
Constructor Summary
Cylinder()
          Constructs a Cylinder.
 
Method Summary
 CylinderListInfo createDisplayList(GL gl, CylinderListInfo info)
          Creates an OpenGL display list for drawing a cylinder with the radii, slices, stacks, and end caps specified in the CylinderListInfo object given as an argument.
 int createDisplayList(GL gl, double baseRadius, double topRadius, double height, int slices, int stacks, boolean capBase, boolean capTop, int capSlices, int capStacks)
          Stores the OpenGL commands for drawing a cylinder as an OpenGL display list.
 void draw(GL gl, double baseRadius, double topRadius, double height, int slices, int stacks, boolean capBase, boolean capTop, int capSlices, int capStacks)
          Draws a cylinder oriented along the z-axis, with the base of the cylinder at the origin and the top of the cylinder at xyz = (0, 0, height).
 
Methods inherited from class org.proteinshader.graphics.Shape
deleteDisplayList, executeDisplayList, executeDisplayList, setMaterial
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_SLICES

public static final int MIN_SLICES
The minimum number of slices for a cylinder is 3.

See Also:
Constant Field Values

MIN_STACKS

public static final int MIN_STACKS
The minimum number of stacks for a cylinder is 1.

See Also:
Constant Field Values

MIN_CAP_TILING

public static final int MIN_CAP_TILING
The minumum tiling (number of slices and stacks) for a capping sphere is 3.

See Also:
Constant Field Values
Constructor Detail

Cylinder

public Cylinder()
Constructs a Cylinder. A GLU quadrics object to be used for drawing cylinders is created here. The quadrics object is set to use GLU_FILL for a drawing style, GLU_OUTSIDE for orientation, and GLU_SMOOTH for the surface normals.

Method Detail

createDisplayList

public CylinderListInfo createDisplayList(GL gl,
                                          CylinderListInfo info)
Creates an OpenGL display list for drawing a cylinder with the radii, slices, stacks, and end caps specified in the CylinderListInfo object given as an argument.

The name of the display list (an integer) will be stored in the CylinderListInfo object given as an argument, and this same object is the return value of this method.

If the CylinderListInfo object given as an argument already has a valid reference to an OpenGL display list, that old display list will be deleted before the new display list is created. If the number of slices or stacks is less than MIN_SLICES or MIN_STACKS, respectively, the number will be reset to the minimum. If a cap at either end is requested, then the number of slices and stacks for the cap will also be checked and reset to the minimum if necessary.

Parameters:
gl - the current GL object.
info - a CylinderListInfo object with values for radius, slices, and stacks.
Returns:
The same CylinderListInfo object given as an argument, but now it has the name of the newly created OpenGL display list.

createDisplayList

public int createDisplayList(GL gl,
                             double baseRadius,
                             double topRadius,
                             double height,
                             int slices,
                             int stacks,
                             boolean capBase,
                             boolean capTop,
                             int capSlices,
                             int capStacks)
Stores the OpenGL commands for drawing a cylinder as an OpenGL display list.

Parameters:
gl - the current GL object.
baseRadius - the radius of the base of the cylinder.
topRadius - the radius at the top of the cylinder.
height - the height of the cylinder.
slices - number of slices in the cylinder (at least 3).
stacks - number of stacks in the cylinder (at least 1).
capBase - determines if base is capped by a sphere.
capTop - determines if top is capped by a sphere.
capSlices - number of slices for cap sphere (at least 3).
capStacks - number of stacks for cap sphere (at least 3).
Returns:
The name (an integer) of the OpenGL display list.

draw

public void draw(GL gl,
                 double baseRadius,
                 double topRadius,
                 double height,
                 int slices,
                 int stacks,
                 boolean capBase,
                 boolean capTop,
                 int capSlices,
                 int capStacks)
Draws a cylinder oriented along the z-axis, with the base of the cylinder at the origin and the top of the cylinder at xyz = (0, 0, height). The cylinder is open at both the base and the top, unless a cap (a small sphere) is requested at one or both ends.

Parameters:
gl - the current GL object.
baseRadius - radius of the base of the cylinder (usually 1).
topRadius - radius at the top of the cylinder (usually 1).
height - the height of the cylinder.
slices - the number of slices in the cylinder.
stacks - the number of stacks in the cylinder.
capBase - determines if base is capped by a sphere.
capTop - determines if top is capped by a sphere.
capSlices - number of slices for cap sphere (no less than 3).
capStacks - number of stacks for cap sphere (no less than 3).


Copyright © 2007-2008