|
j3d.org Code | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.j3d.geom.GeometryGenerator org.j3d.geom.SphereGenerator
public class SphereGenerator
A customisable sphere where you can specify the radius, center and the number of segments to use around the radius.
The sphere is located around the origin. Each face of the sphere is generated as a flat four-sided polygon suitable for use in an unindexed quad array.
Due to a focus on the generation speed, we require that the facet count is always a multiple of 2. The code generates half a sphere and then mirrors it to generate the other half. Having an odd number of facets makes this impossbile to do and we must do a lot more generation. Although it is simple enough to change the algorithm to allow odd numbers of facets, the trade-off is that we loose the ability to nicely generate hemispheres. The result is the same number of facets around the base as over the top half part and that looks like crap as it does not look exactly like half a full generated sphere of the same setup.
The sphere surface is always using smooth normals and every point is such that the normal points directly away from the origin.
Constructor Summary | |
---|---|
SphereGenerator()
Constructs a default sphere of radius 1 and uses 16 segments on the radius. |
|
SphereGenerator(float r)
Constructs a sphere of the given radius and uses 16 segments on the radius. |
|
SphereGenerator(float r,
boolean useHalf)
Constructs a sphere or hemi-sphere of the given radius and uses 16 segments on the radius. |
|
SphereGenerator(float r,
int facets)
Constructs a sphere of the given radius and controllable number of segments on the radius. |
|
SphereGenerator(float r,
int facets,
boolean half)
Constructs a sphere or hemi-sphere of the given radius and controllable number of segments on the radius. |
Method Summary | |
---|---|
void |
generate(GeometryData data)
Generate a new set of geometry items based on the passed data. |
float |
getDimension()
Get the dimensions of the sphere. |
int |
getVertexCount(GeometryData data)
Get the number of vertices that this generator will create for the shape given in the definition. |
boolean |
isHalf()
Check to see that this sphere is a half sphere or not |
void |
setDimensions(float r,
boolean half)
Change the dimensions of the sphere 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 |
---|
public SphereGenerator()
public SphereGenerator(float r)
r
- The radius of the spherepublic SphereGenerator(float r, boolean useHalf)
r
- The radius of the sphereuseHalf
- True to generate a hemi-sphere, false for full spherpublic SphereGenerator(float r, int facets)
r
- The radius of the spherefacets
- The number of facets to use
java.lang.IllegalArgumentException
- The number of facets is less than 3public SphereGenerator(float r, int facets, boolean half)
r
- The radius of the spherefacets
- The number of facets to usehalf
- True to generate a hemi-sphere, false for full sphere
java.lang.IllegalArgumentException
- The number of facets is less than 4
or not divisible by 2.Method Detail |
---|
public boolean isHalf()
public float getDimension()
public void setDimensions(float r, boolean half)
r
- The radius of the spherehalf
- True to generate a hemi-sphere, false for full spherpublic void setFacetCount(int facets) throws java.lang.IllegalArgumentException
facets
- The number of facets on the side of the cone
java.lang.IllegalArgumentException
- The number of facets is less than 4
or not divisible by 2.public int getVertexCount(GeometryData data) throws UnsupportedTypeException
getVertexCount
in class GeometryGenerator
data
- The data to base the calculations on
UnsupportedTypeException
- The generator cannot handle the type
of geometry you have requested.public void generate(GeometryData data) throws UnsupportedTypeException, InvalidArraySizeException
generate
in class GeometryGenerator
data
- The data to base the calculations on
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 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |