import javax.media.j3d.*;
import javax.vecmath.*;
public class Plate extends Shape3D{
public Plate(){
Point3f[] vertices = new Point3f[6];
// defines six vertices with their coordinates
vertices[0] = new Point3f(1.0f,-1.0f, 0.5f);
vertices[1] = new Point3f(1.0f, 0, 0.5f);
vertices[2] = new Point3f(1.0f, 1.0f, 0.5f);
vertices[3] = new Point3f(1.0f,-1.0f,-0.5f);
vertices[4] = new Point3f(1.0f, 0,-0.5f);
vertices[5] = new Point3f(1.0f, 1.0f,-0.5f);
// gives slightly different colors to the six vertices
Color3f[] colors = new Color3f[6];
for(int i=0; i<6; i++){
colors[i]=new Color3f(1.0f-i*(1.0f/6.0f), i*(1.0f/6.0f),0);
}
// defines a new geometry
IndexedQuadArray geometry =
new IndexedQuadArray(
6,
GeometryArray.COORDINATES | GeometryArray.COLOR_3,
8);
geometry.setCoordinates(0, vertices);
geometry.setColors(0, colors);
// defines a cell structure
int[] coordInds = new int[8];
// a square
coordInds[0]=0;
coordInds[1]=3;
coordInds[2]=4;
coordInds[3]=1;
// another square
coordInds[4]=1;
coordInds[5]=4;
coordInds[6]=5;
coordInds[7]=2;
// provides the geometry with a cell structure
geometry.setCoordinateIndices(0, coordInds);
// registers the geometry to this shape3d
setGeometry(geometry);
}
}
最終更新:2011年03月03日 23:09