实验一
实验目的:生成彩色立方体
实验代码://ColorCube1.java
import java.applet.Applet; //可以插入html
import java.awt.BorderLayout; //窗口采用BorderLayout方式布局import com.sun.j3d.utils.applet.MainFrame; //application
import com.sun.j3d.utils.geometry.ColorCube;//调用生成ColorCube的Utility import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.universe.*; //观测位置的设置
import javax.media.j3d.*; //核心类
import javax.vecmath.*; //矢量计算
import com.sun.j3d.utils.behaviors.mouse.*;
public class ColorCube1 extends Applet {
public BranchGroup createSceneGraph() {
BranchGroup objRoot=new BranchGroup();
//BranchGroup的一个对象objRoot(放置背景、灯光)BoundingSphere bounds=new BoundingSphere(new
Point3d(0.0,0.0,0.0),100.0);//有效范围
TransformGroup objTrans=new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objRoot.addChild(objTrans);
MouseRotate behavior = new MouseRotate();
behavior.setTransformGroup(objTrans);
objRoot.addChild(behavior);
behavior.setSchedulingBounds(bounds);
MouseZoom behavior2 = new MouseZoom();
behavior2.setTransformGroup(objTrans);
objRoot.addChild(behavior2);
behavior2.setSchedulingBounds(bounds);
MouseTranslate behavior3 = new MouseTranslate();
behavior3.setTransformGroup(objTrans);
objRoot.addChild(behavior3);
behavior3.setSchedulingBounds(bounds);