|
I want to create a polyhedron and that is the code.
But the shape that generates isn;t as good as i expected.
---------------------------------
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*; import javax.media.j3d.BranchGroup; import com.sun.j3d.utils.applet.MainFrame; import javax.media.j3d.*; import java.awt.*; import javax.vecmath.*; import java.awt.BorderLayout; import javax.media.j3d.GeometryArray; public class ThePolyhedron extends
javax.media.j3d.Shape3D {
private Point3d a1= new Point3d(0.333333, 0.942809,
0.57735);
private Point3d a2= new Point3d(-1., 0, 0.57735); private Point3d a3= new Point3d(-0.333333, -0.942809, 0.57735); private Point3d a4= new Point3d(1., 0, -0.57735); private Point3d a5= new Point3d(0.666667, -0.942809, 0); private Point3d a6= new Point3d(-0.666667, 0.942809, 0); private Point3d a7= new Point3d(0.333333, 0.942809, -0.57735); private Point3d a8= new Point3d(-1., 0, -0.57735); private Point3d a9= new Point3d(-0.333333, -0.942809, -0.57735); private Point3d a10= new Point3d(0, 0, -1.1547); private Point3d a11= new Point3d(0, 0, 1.1547); private Point3d a12= new Point3d(1., 0, 0.57735); public ThePolyhedron()
{
Point3d[] points=new Point3d[12]; points[0]=a1; points[1]=a2; points[2]=a3; points[3]=a4; points[4]=a5; points[5]=a6; points[6]=a7; points[7]=a8; points[8]=a9; points[9]=a10; points[10]=a11; points[11]=a12; int[] stripCounts=new int[1]; stripCounts[0]=12; int[] contourCount=new
int[1];
contourCount[0]=1; GeometryInfo gInf = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); gInf.setCoordinates(points);
gInf.setStripCounts(stripCounts); gInf.setContourCounts(contourCount); NormalGenerator ng= new NormalGenerator(); ng.setCreaseAngle ((float) Math.toRadians(30)); ng.generateNormals(gInf); this.setGeometry(gInf.getGeometryArray()); SimpleUniverse universe = new
SimpleUniverse();
GraphicsConfiguration config = universe.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); BranchGroup group = new
BranchGroup();
group.addChild(this); Color3f light1Color = new Color3f(0.0f, 1.0f, 0.0f); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, 12.0f); DirectionalLight dl = new DirectionalLight(light1Color,light1Direction); BoundingSphere bounds = new BoundingSphere(); bounds.setRadius(Double.POSITIVE_INFINITY); dl.setInfluencingBounds(bounds); group.addChild(dl); universe.getViewingPlatform().setNominalViewingTransform(); universe.addBranchGraph(group);
}
} // end of class
-------------------------
Does this work for
you? |
- Re: [JAVA3D] polyhedron ... Γιάννης
- Re: [JAVA3D] polyhe... Alessandro Borges
- Re: [JAVA3D] po... Γιάννης
