j3d.org Code

org.j3d.geom
Class BoxGenerator

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

public class BoxGenerator
extends GeometryGenerator

Generator of box coordinates, normals and texture coordinates.

The width of the box is the X axis. The height of the box is along the Y axis and the depth of the box is along the Z axis. The box is always centered about the origin such that the effective coordinates are 1/2 the values provided here.

For the strip and fan arrays, we always use one fan/strip per face. While it is possible to reduce it to one big strip array and then two small ones for top and bottom. the effect is lighting normals that point out at angles from each corner, which is not realistic. So for this generator, there is no real difference between using indexed and unindexed forms as they use the same number of coordinates.

2D texture coordinates follow the classic OpenGL style. 0,0 is in the bottom left corner of each face and 1, 1 is on the top right. For the top, the texture appears the right way up looking down the -Y axis, with the -Z axis as up. For the bottom face, looking along the Y axis, with the +Z axis as up it is the right way up.

3D Texture coordinates look just like the cube. 0, 0, 0 is at the lower left corner of the front face, while 1, 1, 1 is at the top right, rear corner.

Version:
$Revision: 1.5 $
Author:
Justin Couch

Constructor Summary
BoxGenerator()
          Construct a box with the default size of 2, 2, 2.
BoxGenerator(float width, float height, float depth)
          Construct a box with the given dimensions.
 
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 box.
 int getVertexCount(GeometryData data)
          Get the number of vertices that this generator will create for the shape given in the definition.
 void setDimensions(float width, float height, float depth)
          Set the dimensions of the output box to the new values.
 
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

BoxGenerator

public BoxGenerator()
Construct a box with the default size of 2, 2, 2.


BoxGenerator

public BoxGenerator(float width,
                    float height,
                    float depth)
Construct a box with the given dimensions.

Parameters:
width - The width of the box in units
height - The height of the box in units
depth - The depth of the box in units
Method Detail

getDimensions

public float[] getDimensions()
Get the dimensions of the box. These are returned as 3 value of width, height and depth 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 box

setDimensions

public void setDimensions(float width,
                          float height,
                          float depth)
Set the dimensions of the output box to the new values. Calling this will make the points be re-calculated again.

Parameters:
width - The width of the box in units
height - The height of the box in units
depth - The depth of the box in units

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