j3d.org Code

org.j3d.geom
Class CylinderGenerator

java.lang.Object
  extended by org.j3d.geom.GeometryGenerator
      extended by org.j3d.geom.CylinderGenerator

public class CylinderGenerator
extends GeometryGenerator

A simple cylinder that can be configured to have end caps.

The generator is used to create cylinder shaped geometry for the code. Internally we use a triangle array to generate the information as a collection of single triangles. A triangle strip would be more efficient for rendering, but that's too hard for this first cut :) The height of the cone is along the Y axis with the point in the positive Y direstion. The radius is around the X-Z plane. The whole object is centered on the origin.

Version:
$Revision: 1.13 $
Author:
Justin Couch

Constructor Summary
CylinderGenerator()
          Construct a default cylinder with end caps.
CylinderGenerator(boolean ends)
          Construct a default cylinder with the option of having end caps.
CylinderGenerator(float height, float radius)
          Construct a cylinder of a given height and radius with ends.
CylinderGenerator(float height, float radius, boolean ends, boolean side)
          Construct a cylinder of a given height and radius with the option of ends.
CylinderGenerator(float height, float radius, boolean top, boolean bottom, boolean side)
          Construct a cylinder of a given height and radius with the option of ends.
CylinderGenerator(float height, float radius, int facets)
          Construct a cylinder of a given height and radius with ends and selectable number of faces around the radius.
CylinderGenerator(float height, float radius, int facets, boolean ends, boolean side)
          Construct a cylinder of a given height and radius with the option of ends and selectable number of faces around the radius.
CylinderGenerator(float height, float radius, int facets, boolean top, boolean bottom, boolean side)
          Construct a cylinder of a given height and radius with the option of ends and selectable number of faces around the radius.
CylinderGenerator(int facets)
          Construct a default cylinder with end caps and selectable number of faces around the radius.
CylinderGenerator(int facets, boolean ends)
          Construct a default cylinder with the option of having end caps and selectable number of faces around the radius.
 
Method Summary
 void generate(GeometryData data)
          Generate a new set of geometry items based on the passed data.
 float[] getDimensions()
          Get the dimensions of the cylinder.
 int getVertexCount(GeometryData data)
          Get the number of vertices that this generator will create for the shape given in the definition.
 boolean hasEnds()
          Check to see that this cylinder has ends in use or not
 void setDimensions(float height, float radius, boolean ends, boolean side)
          Change the dimensions of the cone to be generated.
 void setFacetCount(int facets)
          Change the number of facets used to create this cone.
 
Methods inherited from class org.j3d.geom.GeometryGenerator
createFaceNormal, createFaceNormal, createRadialNormal, createRadialNormal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CylinderGenerator

public CylinderGenerator()
Construct a default cylinder with end caps. The default height is 2 and radius 1. There are 16 faces on around the radius.


CylinderGenerator

public CylinderGenerator(boolean ends)
Construct a default cylinder with the option of having end caps. The default height is 2 and radius 1. There are 16 faces on around the radius.

Parameters:
ends - true to use end caps

CylinderGenerator

public CylinderGenerator(int facets)
Construct a default cylinder with end caps and selectable number of faces around the radius. The default height is 2 and radius 1. The minimum number of facets is 3.

Parameters:
facets - The number of faces to use around the radius
Throws:
java.lang.IllegalArgumentException - The number of facets is less than 3

CylinderGenerator

public CylinderGenerator(int facets,
                         boolean ends)
Construct a default cylinder with the option of having end caps and selectable number of faces around the radius. The default height is 2 and radius 1.The minimum number of facets is 3.

Parameters:
facets - The number of faces to use around the radius
ends - true to use end caps
Throws:
java.lang.IllegalArgumentException - The number of facets is less than 3

CylinderGenerator

public CylinderGenerator(float height,
                         float radius)
Construct a cylinder of a given height and radius with ends. There are 16 faces around the radius.

Parameters:
height - The height of the cylinder to generate
radius - The radis of the cylinder to generate

CylinderGenerator

public CylinderGenerator(float height,
                         float radius,
                         int facets)
Construct a cylinder of a given height and radius with ends and selectable number of faces around the radius. The minimum number of facets is 3.

Parameters:
height - The height of the cylinder to generate
radius - The radis of the cylinder to generate
facets - The number of faces to use around the radius
Throws:
java.lang.IllegalArgumentException - The number of facets is less than 3

CylinderGenerator

public CylinderGenerator(float height,
                         float radius,
                         boolean ends,
                         boolean side)
Construct a cylinder of a given height and radius with the option of ends. There are 16 faces around the radius.

Parameters:
height - The height of the cylinder to generate
radius - The radis of the cylinder to generate
ends - true to use end caps
side - true to display the sides

CylinderGenerator

public CylinderGenerator(float height,
                         float radius,
                         boolean top,
                         boolean bottom,
                         boolean side)
Construct a cylinder of a given height and radius with the option of ends. There are 16 faces around the radius.

Parameters:
height - The height of the cylinder to generate
radius - The radis of the cylinder to generate
top - Whether to generate the top of the cylinder
bottom - Whether to generate the bottom of the cylinder
side - Whether to generate the side of the cylinder

CylinderGenerator

public CylinderGenerator(float height,
                         float radius,
                         int facets,
                         boolean ends,
                         boolean side)
Construct a cylinder of a given height and radius with the option of ends and selectable number of faces around the radius. The minimum number of facets is 3.

Parameters:
height - The height of the cylinder to generate
radius - The radis of the cylinder to generate
facets - The number of faces to use around the radius
ends - true to use end caps
side - true to display the side
Throws:
java.lang.IllegalArgumentException - The number of facets is less than 3

CylinderGenerator

public CylinderGenerator(float height,
                         float radius,
                         int facets,
                         boolean top,
                         boolean bottom,
                         boolean side)
Construct a cylinder of a given height and radius with the option of ends and selectable number of faces around the radius. The minimum number of facets is 3.

Parameters:
height - The height of the cylinder to generate
radius - The radis of the cylinder to generate
facets - The number of faces to use around the radius
top - Whether to generate the top of the cylinder
bottom - Whether to generate the bottom of the cylinder
side - Whether to generate the side of the cylinder
Throws:
java.lang.IllegalArgumentException - The number of facets is less than 3
Method Detail

hasEnds

public boolean hasEnds()
Check to see that this cylinder has ends in use or not

Returns:
true if there is are end caps in use

getDimensions

public float[] getDimensions()
Get the dimensions of the cylinder. These are returned as 2 values of height and radius respectively for the array. A new array is created each time so you can do what you like with it.

Returns:
The current size of the cone

setDimensions

public void setDimensions(float height,
                          float radius,
                          boolean ends,
                          boolean side)
Change the dimensions of the cone to be generated. Calling this will make the points be re-calculated next time you ask for geometry or normals.

Parameters:
height - The height of the cone to generate
radius - The radius of the bottom of the cone
ends - True if to generate faces for the ends
side - true if to generate faces for the sides

setFacetCount

public void setFacetCount(int facets)
Change the number of facets used to create this cone. This will cause the geometry to be regenerated next time they are asked for. The minimum number of facets is 3.

Parameters:
facets - The number of facets on the side of the cone
Throws:
java.lang.IllegalArgumentException - The number of facets is less than 3

getVertexCount

public int getVertexCount(GeometryData data)
                   throws UnsupportedTypeException
Get the number of vertices that this generator will create for the shape given in the definition.

Specified by:
getVertexCount in class GeometryGenerator
Parameters:
data - The data to base the calculations on
Returns:
The vertex count for the object
Throws:
UnsupportedTypeException - The generator cannot handle the type of geometry you have requested.

generate

public void generate(GeometryData data)
              throws UnsupportedTypeException,
                     InvalidArraySizeException
Generate a new set of geometry items based on the passed data. If the data does not contain the right minimum array lengths an exception will be generated. If the array reference is null, this will create arrays of the correct length and assign them to the return value.

Specified by:
generate in class GeometryGenerator
Parameters:
data - The data to base the calculations on
Throws:
InvalidArraySizeException - The array is not big enough to contain the requested geometry
UnsupportedTypeException - The generator cannot handle the type of geometry you have requested

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org