Hi everyone.

I was wondering if someone would be able to explain some or all of the following piece of code for me in as non-technical way as possible. I'd really love to know how it works.

thanks for any help.

Sharon.

 

///////////////////////////////

private void createFloor( Group bg ) {

final int LAND_WIDTH = 12;

final float LAND_HEIGHT = -1.0f;

final int LAND_LENGTH = 12;

final int nTileSize = 2;

// calculate how many vertices we need to store all the "tiles"

// that compose the QuadArray.

final int nNumTiles = ((LAND_LENGTH/nTileSize) * 2 ) * ((LAND_WIDTH/nTileSize) * 2 );

final int nVertexCount = 4 * nNumTiles;

Point3f[] coordArray = new Point3f[nVertexCount];

Point2f[] texCoordArray = new Point2f[nVertexCount];

//java.net.URL image_url = applet.getImageUrl( "cobbles.jpg" );

// create an Appearance and load a texture

Appearance app = new Appearance( );

Texture tex = new TextureLoader( "cobbles.jpg", applet ).getTexture( );

app.setTexture( tex );

int nItem = 0;

// loop over all the tiles in the environment

for( int x = -LAND_WIDTH; x <= LAND_WIDTH; x+=nTileSize )

{

for( int z = -LAND_LENGTH; z <= LAND_LENGTH; z+=nTileSize )

{

// if we are on the border of the environment create a

// TransformGroup to position a ColorCube to create a "wall"

if( x == -LAND_WIDTH || x == LAND_WIDTH || z == -LAND_LENGTH || z == LAND_LENGTH )

{

TransformGroup tg = new TransformGroup( );

Transform3D t3d = new Transform3D( );

t3d.setTranslation( new Vector3d( x, 0, z ) );

tg.setTransform( t3d );

ColorCube texturecube = new ColorCube( (nTileSize/2) );

tg.addChild( texturecube );

bg.addChild( tg );

}

// if we are not on the last row or column create a "tile"

// and add to the QuadArray. Use CCW winding and assign texture

// coordinates.

if( z < LAND_LENGTH && x < LAND_WIDTH )

{

coordArray[nItem] = new Point3f( x, LAND_HEIGHT, z );

texCoordArray[nItem++] = new Point2f( 0, 0 );

coordArray[nItem] = new Point3f( x, LAND_HEIGHT, z + nTileSize );

texCoordArray[nItem++] = new Point2f( 1, 0 );

coordArray[nItem] = new Point3f( x + nTileSize, LAND_HEIGHT, z + nTileSize );

texCoordArray[nItem++] = new Point2f( 1, 1 );

coordArray[nItem] = new Point3f( x + nTileSize, LAND_HEIGHT, z );

texCoordArray[nItem++] = new Point2f( 0, 1 );

}

}

}

// create a GeometryInfo and generate Normal vectors

// for the QuadArray that was populated.

GeometryInfo gi = new GeometryInfo( GeometryInfo.QUAD_ARRAY );

gi.setCoordinates( coordArray );

gi.setTextureCoordinates( texCoordArray );

NormalGenerator normalGenerator = new NormalGenerator( );

normalGenerator.generateNormals( gi );

// wrap the GeometryArray in a Shape3D

Shape3D shape = new Shape3D( gi.getGeometryArray( ), app );

// add the Shape3D to the parent BranchGroup

bg.addChild( shape );

}



 



Add photos to your messages with MSN 8. Get 2 months FREE*. =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to