view tools/java3d-test/src/two_obj.java @ 13:0652ac3c8b5f

add two_obj
author axmo
date Mon, 11 Aug 2008 22:20:03 +0900
parents
children 006015077e99
line wrap: on
line source

import java.applet.Applet;
import com.sun.j3d.utils.applet.MainFrame;
import javax.media.j3d.*;

import java.awt.BorderLayout;

import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.ColorCube;
//import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
//import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
//import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
//import com.sun.j3d.utils.behaviors.mouse.MouseZoom;
import javax.vecmath.*;


public class two_obj extends Applet {
	
	public SimpleUniverse universe = null;
	public Canvas3D canvas = null;
	
	public BranchGroup createObjects(){
		BranchGroup root = new BranchGroup();
		
		//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);
	
	    //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 TransformGroup addobj(Vector3d vec3d) {
		TransformGroup td3Root = new TransformGroup();
		Transform3D t3d = new Transform3D();
		t3d.setTranslation(vec3d);
		td3Root.setTransform(t3d);
		td3Root.addChild(new ColorCube(0.4));
		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);
    }
}