/*--------------*/ /* Ex31.java */ /*--------------*/ import java.applet.Applet; import java.awt.*; //BorderLayout,GraphicsConfiguration,event import javax.media.j3d.*; //Java3d import com.sun.j3d.utils.applet.MainFrame; //MainFrame import com.sun.j3d.utils.universe.*; //SimpleUniverse import com.sun.j3d.utils.geometry.*; //Primitive import javax.vecmath.*; //Point3f,Color3f public class Ex31 extends Applet{ private SimpleUniverse simpleU; private BoundingSphere bounds = new BoundingSphere(new Point3d(), 10.0); public void init(){ //アプレットの中央にCanvas3Dを追加 setLayout(new BorderLayout()); Canvas3D canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); add(canvas, BorderLayout.CENTER); //シーングラフの生成 simpleU = new SimpleUniverse(canvas); simpleU.getViewingPlatform().setNominalViewingTransform(); //シーングラフの作成 simpleU.addBranchGraph(createSceneGraph()); } private BranchGroup createSceneGraph(){ BranchGroup branchG0 = new BranchGroup(); //背景色の設定(設定が無い場合は黒) Background background = new Background(new Color3f(0.3f, 0.3f, 0.3f)); background.setApplicationBounds(bounds); branchG0.addChild(background); //Appearanceを作成 Appearance ap = new Appearance(); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(new Color3f( 0.0f, 1.0f, 1.0f)); //@chg 水色 ap.setColoringAttributes(ca); PolygonAttributes pa = new PolygonAttributes(); //@add ポリゴン属性 pa.setPolygonMode(PolygonAttributes.POLYGON_LINE); //@add ワイヤー ap.setPolygonAttributes(pa); //@add //原点に物体を作成 Sphere sphere = new Sphere(0.5f, ap); branchG0.addChild(sphere); //@chg 球 branchG0.compile(); return branchG0; } public void destroy(){ simpleU.cleanup(); } public static void main(String[] args){ //Application MainFrame frame = new MainFrame(new Ex31(), 512, 512); } }