import javax.media.j3d.*;
import javax.vecmath.*;
public class model0915 extends Shape3D{
public model0915(int n){
super(createGeometry(n));
}
private static IndexedQuadArray createGeometry(int n){
Point3f[] vertices = new Point3f[2*n];
float a = (float)(2.0* Math.PI / n);
float b = (float) Math.PI / n;
Matrix3f Ry = new Matrix3f();
Matrix3f Rz = new Matrix3f();
for(int i=0; i<2*n; i++){
Point3f p0 = new Point3f(10,0,0);
Vector3f v0 = new Vector3f(0,0,1);
Ry.rotY(b*i);
Rz.rotZ(a*i);
Ry.transform(v0);
p0.add(v0);
Rz.transform(p0);
vertices[i] = p0;
}
Color3f[] colors = new Color3f[2*n];
for(int i=0; i<2*n; i++){
colors[i]=new Color3f(1.0f, 0,0);
}
IndexedQuadArray geometry =
new IndexedQuadArray(
2*n,
GeometryArray.COORDINATES | GeometryArray.COLOR_3,
4*n);
geometry.setCoordinates(0, vertices);
geometry.setColors(0, colors);
int[] coordInds = new int[4*n];
for(int i=0; i<n-1; i++){
coordInds[4*i]=i;
coordInds[4*i+1]=i+n;
coordInds[4*i+2]=i+n+1;
coordInds[4*i+3]=i+1;
}
coordInds[4*(n-1)]=(n-1);
coordInds[4*(n-1)+1]=(n-1)+n;
coordInds[4*(n-1)+2]=0;
coordInds[4*(n-1)+3]=(n-1)+1;
geometry.setCoordinateIndices(0, coordInds);
return geometry;
}
}
最終更新:2011年03月03日 23:25