Importa librerie 3D e creare una " piramide " di classe :
importazione java.awt.Color ; import com.sun.j3d.utils.geometry.GeometryInfo ; com.sun.j3d.utils.geometry.NormalGenerator importazione; com.sun.j3d.utils.universe.SimpleUniverse importazione; importare javax.media.j3d * , . javax.vecmath import * , .
PyramidExample public class { }
2
Creare punti tridimensionali che rappresentano la base e la parte superiore della piramide :
public static void main ( String [] args ) { SimpleUniverse u = new SimpleUniverse ( ) ; BranchGroup g = new BranchGroup ( ) ;
Point3f e = new Point3f ( 1.0f , 0.0 f , 0.0f ) ; Point3f s = new Point3f ( 0.0f , 0.0f , 1.0f ) ; Point3f w = new Point3f ( - 1.0f , 0.0f , 0.0f ) ; Point3f n = new Point3f ( 0.0f , 0.0f , - 1.0f ) ; Point3f t = new Point3f ( 0.0f , 0.721f , 0.0f ) ;
3
creare la geometria per collegare quei punti . Questo codice disegna un triangolo separato per ogni lato per quattro lati , oltre a due creando una base quadrata :
TriangleArray piramide = new TriangleArray ( 18 , TriangleArray.COORDINATES ) ; pyramidGeometry.setCoordinate ( 0 , e); pyramidGeometry . setCoordinate ( 1 , t ) ; pyramidGeometry.setCoordinate ( 2 , s ) ;
pyramidGeometry.setCoordinate ( 3 , s ) ; pyramidGeometry.setCoordinate ( 4 , t ) ; pyramidGeometry.setCoordinate ( 5 , w ) ; < br
pyramidGeometry.setCoordinate > ( 6 , w ) ; pyramidGeometry.setCoordinate ( 7 , t ) ; pyramidGeometry.setCoordinate ( 8 , n) ;
pyramidGeometry.setCoordinate ( 9 , n) ; pyramidGeometry.setCoordinate ( 10 t ) ; pyramidGeometry.setCoordinate ( 11 , e);
pyramidGeometry.setCoordinate ( 12 , e); pyramidGeometry.setCoordinate ( 13 , s ) ; pyramidGeometry.setCoordinate ( 14 w) ; < br
pyramidGeometry.setCoordinate > ( 15 w ) ; pyramidGeometry.setCoordinate ( 16 , n) ; pyramidGeometry.setCoordinate ( 17 e);
ginfo GeometryInfo = new GeometryInfo ( piramide) ; NormalGenerator ng = new NormalGenerator (); ng.generateNormals ( ginfo ) ;
risultato GeometryArray = ginfo.getGeometryArray ();
Programmazione © www.354353.com