Mercurial > hg > FederatedLinda
view tools/java3d-test/src/two_obj.java @ 122:ad73eacf560a default tip
remove warning
author | e095732 |
---|---|
date | Thu, 07 Feb 2013 22:32:26 +0900 |
parents | cb13a91175ad |
children |
line wrap: on
line source
import java.applet.Applet; import com.sun.j3d.utils.applet.MainFrame; //import com.sun.j3d.utils.behaviors.mouse.*; //import com.sun.j3d.utils.behaviors.keyboard.*; import javax.media.j3d.*; import java.awt.BorderLayout; import java.awt.GraphicsConfiguration; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.geometry.*; import javax.vecmath.*; import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import javax.swing.*; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; import java.io.IOException; public class two_obj extends Applet { public SimpleUniverse universe = null; public Canvas3D canvas = null; public BranchGroup createObjects(){ BranchGroup root = new BranchGroup(); root.addChild(createLight()); Appearance ap = new Appearance(); Material ma = new Material(); ma.setDiffuseColor(0.0f, 0.0f, 1.0f); ap.setMaterial(ma); //TransformGroup transRoot = new TransformGroup(); //Transform3D transform = new Transform3D(); TransformGroup td3Root = addobj(new Vector3d(1.0, 0.0, 0.0)); root.addChild(td3Root); TransformGroup td3Root1 = addobj(new Vector3d(0.0, 0.0, 0.0)); root.addChild(td3Root1); TransformGroup td3Root2 = addobj(new Vector3d(-1.0, 1.0, 0.0)); root.addChild(td3Root2); // //View用TransfromGroup // //全体を見渡す巨大で透明なSphireを作る // TransformGroup viewSphire = new TransformGroup(); // viewSphire.addChild(new Sphere(50.f)); // // viewSphire.setCapability( TransformGroup.ALLOW_TRANSFORM_READ ); // viewSphire.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE ); // // MouseRotate rotat = new MouseRotate( viewSphire ); // MouseTranslate trans = new MouseTranslate( viewSphire ); // MouseZoom zoom = new MouseZoom( viewSphire ); // // BoundingSphere bounds = new BoundingSphere(); // // bounds.setRadius( 10.0 ); // rotat.setSchedulingBounds( bounds ); // trans.setSchedulingBounds( bounds ); // zoom.setSchedulingBounds( bounds ); // // td3Root.addChild(rotat); // td3Root.addChild(trans); // td3Root.addChild(zoom); //transform.set(new Vector3d(1.0, 0.0, 0.0)); //transRoot.setTransform(transform); //transRoot.addChild(new ColorCube(0.4)); //root.addChild(transRoot); // root.addChild(new ColorCube(0.4)); root.compile(); return root; } private Light createLight(){ DirectionalLight light = new DirectionalLight( true, new Color3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f)); light.setInfluencingBounds(new BoundingSphere(new Point3d(), 100.0)); return light; } private TransformGroup addobj(Vector3d vec3d) { TransformGroup td3Root = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(vec3d); td3Root.setTransform(t3d); td3Root.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 50)); return td3Root; } // public void setOrbitBehavior() { // // // マウスでぐりぐりするための処理 // OrbitBehavior orbit = new OrbitBehavior(canvas, OrbitBehavior.REVERSE_ALL); // orbit.setSchedulingBounds( // new BoundingSphere(new Point3d(0, 0, 0), 100.0)); // universe.getViewingPlatform().setViewPlatformBehavior(orbit); // } public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D canvas = new Canvas3D(config); add("Center", canvas); universe = new SimpleUniverse(canvas); universe.getViewingPlatform().setNominalViewingTransform(); // マウスでぐりぐり動かすための処理 // setOrbitBehavior(); universe.addBranchGraph(createObjects()); } public static void main(String[] args) { new MainFrame(new two_obj(), 600, 600); } }