?? mycube1.java
字號:
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.mouse.*;
public class MyCube1 extends Applet{
public BranchGroup createSceneGraph(){
BranchGroup objRoot=new BranchGroup();
BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
Color3f bgColor=new Color3f(0.0f,0.0f,0.0f);
Background bg=new Background(bgColor);
bg.setApplicationBounds(bounds);
objRoot.addChild(bg);
TransformGroup trans=new TransformGroup();
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objRoot.addChild(trans);
TransformGroup g1=new TransformGroup();
g1.addChild(new ColorCube(0.2));
Transform3D t=new Transform3D();
t=new Transform3D();
t.setScale(0.5);
t.setTranslation(new Vector3f(0.0f,0.6f,0.0f));
t.setRotation(new Quat4f(0.78f,0.78f,0.78f,0.0f));
TransformGroup g2=new TransformGroup(t);
g2.addChild(new ColorCube(0.2));
trans.addChild(g1);
trans.addChild(g2);
MouseRotate behavior=new MouseRotate();
behavior.setTransformGroup(trans);
objRoot.addChild(behavior);
behavior.setSchedulingBounds(bounds);
MouseZoom behavior2=new MouseZoom();
behavior2.setTransformGroup(trans);
objRoot.addChild(behavior2);
behavior2.setSchedulingBounds(bounds);
MouseTranslate behavior3=new MouseTranslate();
behavior3.setTransformGroup(trans);
objRoot.addChild(behavior3);
behavior3.setSchedulingBounds(bounds);
objRoot.compile();
return objRoot;
}
public MyCube1(){
setLayout(new BorderLayout());
Canvas3D c=new Canvas3D(null);
add("Center",c);
BranchGroup scene=createSceneGraph();
SimpleUniverse u=new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
public static void main(String[] args){
new MainFrame(new MyCube1(),400,300);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -