我对java3d
API感兴趣。我一直关注3d
的java Daniel Selman
编程。我尝试使用本书中给出的以下代码创建一个简单的3d
多维数据集:
public static void main(String[] args)
{
Cude3d cd= new Cude3d();
cd.go();
//create the Universe
}
go方法是:
private void go() {
VirtualUniverse m_Universe = new VirtualUniverse();
//create the position for the Locale
int[] xPos = { 0, 0, 0, 0, 0, 0, 0, 0 }; int[] yPos = { 0, 0, 0, 0, 0, 0, 0, 0 };
int[] zPos = { 0, 0, 0, 1, 0, 0, 0, 0 };
HiResCoord hiResCoord = new HiResCoord( xPos, yPos, zPos );
//create the Locale and attach to the VirtualUniverse
Locale locale = new Locale( m_Universe, hiResCoord );
//create the BranchGroup containing the Geometry for the scene
BranchGroup sceneBranchGroup = createSceneBranchGroup();
sceneBranchGroup.compile();
//add the scene BranchGroup to the Locale
locale.addBranchGraph( sceneBranchGroup );
场景图创建为:
BranchGroup vpBranchGroup = new BranchGroup();
//create a TransformGroup to scale the ViewPlatform //(and hence View)
TransformGroup tg = new TransformGroup();
ColorCube cc= new ColorCube(.2);
cc.setBounds(new BoundingSphere());
tg.addChild(cc);
//create the ViewPlatform
ViewPlatform vp = new ViewPlatform(); vp.setViewAttachPolicy( View.RELATIVE_TO_FIELD_OF_VIEW );
//attach the ViewPlatform to the TransformGroup
tg.addChild( vp );
//attach the TransformGroup to the BranchGroup
vpBranchGroup.addChild( tg );
Transform3D t3d = new Transform3D();
t3d.setTranslation( new Vector3d( 10.0, 10.0, 10.0 ) ); tg.setTransform( t3d );
View view = new View();
//create the PhysicalBody and PhysicalEnvironment for the View
//and attach to the View
PhysicalBody pb = new PhysicalBody();
PhysicalEnvironment pe = new PhysicalEnvironment();
view.setPhysicalEnvironment( pe );
view.setPhysicalBody( pb );
//attach the View to the ViewPlatform
view.attachViewPlatform( vp );
//set the near and far clipping planes for the View
view.setBackClipDistance( 110 );
view.setFrontClipDistance( 10 );
GraphicsConfigTemplate3D gc3D = new GraphicsConfigTemplate3D();
gc3D.setSceneAntialiasing( GraphicsConfigTemplate.PREFERRED );
GraphicsDevice gd[] = GraphicsEnvironment.
getLocalGraphicsEnvironment().getScreenDevices();
Canvas3D c3d = new Canvas3D( gd[0].getBestConfiguration( gc3D ) );
//set the size of the Canvas3D
c3d.setSize( 512, 512 );
//add the Canvas3D to the View so that it is rendered into
view.addCanvas3D( c3d );
//add the Canvas3D component to a parent AWT or Swing Panel
add( c3d );
this.setVisible(true);
this.setSize(500, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
return vpBranchGroup;
我无法知道它出了什么问题。任何帮助表示赞赏。 提前谢谢。