当前位置: 主页 > 彩票资讯 >

java 3D画图实例

发布时间:2020-02-12 | 来源:未知 | 作者:admin | 点击: 次 | 3d画
java 3D画图实例

importjava.applet.Applet;

importjava.awt.BorderLayout;

importjava.awt.Frame;

importjavax.media.j3d.BoundingSphere;

importjavax.media.j3d.BranchGroup;

importjavax.media.j3d.Canvas3D;

importjavax.media.j3d.Geometry;

importjavax.media.j3d.GeometryArray;

importjavax.media.j3d.IndexedLineArray;

importjavax.media.j3d.Shape3D;

importjavax.media.j3d.TransformGroup;

importjavax.vecmath.Point3f;

importcom.sun.j3d.utils.applet.MainFrame;

importcom.sun.j3d.utils.behaviors.mouse.MouseRotate;

importcom.sun.j3d.utils.geometry.ColorCube;

importcom.sun.j3d.utils.universe.SimpleUniverse;

//MouseRotateApprendersasingle,interactivelyrotatablecube.

publicclassMouseRotateAppextendsApplet{

publicBranchGroupcreateSceneGraph(){

//Createtherootofthebranchgraph

BranchGroupobjRoot=newBranchGroup();

TransformGroupobjRotate=newTransformGroup();

objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

objRoot.addChild(objRotate);

objRotate.addChild(newColorCube(0.4));

objRoot.addChild(newAxis());

MouseRotatemyMouseRotate=newMouseRotate();

myMouseRotate.setTransformGroup(objRotate);

myMouseRotate.setSchedulingBounds(newBoundingSphere());

objRoot.addChild(myMouseRotate);

//LetJava3Dperformoptimizationsonthisscenegraph.

objRoot.compile();

returnobjRoot;

}//endofCreateSceneGraphmethodofMouseRotateApp

//Createasimplesceneandattachittothevirtualuniverse

publicMouseRotateApp(){

setLayout(newBorderLayout());

Canvas3Dcanvas3D=newCanvas3D(null);

add("Center",canvas3D);

BranchGroupscene=createSceneGraph();

//SimpleUniverseisaConvenienceUtilityclass

SimpleUniversesimpleU=newSimpleUniverse(canvas3D);

//ThiswillmovetheViewPlatformbackabitsothe

//objectsinthescenecanbeviewed.

simpleU.getViewingPlatform().setNominalViewingTransform();

simpleU.addBranchGraph(scene);

}//endofMouseRotateApp(constructor)

//Thefollowingallowsthistoberunasanapplication

//aswellasanapplet

publicstaticvoidmain(String[]args){

System.out

.print("MouseRotateApp.java\n-ademonstrationofusingtheMouseRotate");

System.out

.println("utilitybehaviorclasstoprovideinteractioninaJava3Dscene.");

System.out

.println("Holdthemousebuttonwhilemovingthemousetomakethecuberotate.");

System.out

.println("ThisisasimpleexampleprogamfromTheJava3DAPITutorial.");

System.out.println("TheJava3DTutorialisavailableonthewebat:");

System.out.println("http://www.sun.com/desktop/java3d/collateral");

Frameframe=newMainFrame(newMouseRotateApp(),256,256);

}//endofmain(methodofMouseRotateApp)

}//endofclassMouseRotateApp

/*

*GettingStartedwiththeJava3DAPIwritteninJava3D

吉彩网彩票预测专家(整理搜集)

下一篇:没有了
Powered by http://www.jitajianpu.com © 2004-2009 DesDev Inc.
Copyright © 2002-2020 吉彩网彩票预测专家 版权所有