?? mysphere.java
字號:
package com.java3d.test;
import java.applet.Applet;
import java.awt.BorderLayout;
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.Point3d;
public class mySphere extends Applet {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @param args
*/
//public mySphere() {
//}
public void init() {
Canvas3D canvas = new Canvas3D(SimpleUniverse
.getPreferredConfiguration());
setLayout(new BorderLayout());
add("Center", canvas);
SimpleUniverse u = new SimpleUniverse(canvas);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(getBranchGroup4());
}
public BranchGroup getBranchGroup(){
BranchGroup objRoot = new BranchGroup();
Transform3D rotate = new Transform3D();
rotate.rotY(Math.PI/4.0d);
TransformGroup objRotate = new TransformGroup(rotate);
objRotate.addChild(new ColorCube(0.4));
objRoot.addChild(objRotate);
return objRoot;
}
public BranchGroup getBranchGroup2(){
BranchGroup objRoot = new BranchGroup();
Transform3D rotate = new Transform3D();
Transform3D tempRotate = new Transform3D();
rotate.rotX(Math.PI/4.0d);
tempRotate.rotY(Math.PI/4.0d);
rotate.mul(tempRotate);
TransformGroup objRotate = new TransformGroup(rotate);
objRotate.addChild(new ColorCube(0.4));
objRoot.addChild(objRotate);
return objRoot;
}
public BranchGroup getBranchGroup3(){
BranchGroup objRoot = new BranchGroup();
// 創建變換組,并用單位矩陣來初始化。
// 并加其作為子圖的孩子結點加到子圖中。
TransformGroup objSpin = new TransformGroup();
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// 創建一個簡單的形狀葉子結點.并把加其入子圖中。
// ColorCube是一個方便的工具類
objSpin.addChild(new ColorCube(0.4));
// create time varying function to drive the animation
Alpha rotationAlpha = new Alpha(-1, 4000);
//創建一個新的Behavior對象來實現預期的操作。
// 并指定其形變對象,把其作為孩子結點加入到
// 場景圖中。
RotationInterpolator rotator =
new RotationInterpolator(rotationAlpha, objSpin);
// 一個范圍球體是行為活躍區域。
BoundingSphere bounds = new BoundingSphere();
rotator.setSchedulingBounds(bounds);
objSpin.addChild(rotator);
objRoot.addChild(objSpin);
return objRoot;
}
public BranchGroup getBranchGroup4(){
BranchGroup objRoot = new BranchGroup();
// 創建變換組,并用單位矩陣來初始化。
// 并加其作為子圖的孩子結點加到子圖中。
Transform3D tf3d = new Transform3D();
Transform3D tf3d2 = new Transform3D();
tf3d.rotX(Math.PI/4.0d);
tf3d2.rotY(Math.PI/4.0d);
tf3d.mul(tf3d2);
TransformGroup objRotate = new TransformGroup(tf3d);
TransformGroup objSpin = new TransformGroup();
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// 創建一個簡單的形狀葉子結點.并把加其入子圖中。
// ColorCube是一個方便的工具類
objSpin.addChild(new ColorCube(0.4));
// create time varying function to drive the animation
Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 4000, 0, 0, 4000, 0, 0);
//創建一個新的Behavior對象來實現預期的操作。
// 并指定其形變對象,把其作為孩子結點加入到
// 場景圖中。
RotationInterpolator rotator =
new RotationInterpolator(rotationAlpha, objSpin);
// 一個范圍球體是行為活躍區域。
BoundingSphere bounds = new BoundingSphere(new Point3d(3.0, 0.0, 0.0), 1.0);
rotator.setSchedulingBounds(bounds);
objSpin.addChild(rotator);
objRotate.addChild(objSpin);
objRoot.addChild(objRotate);
return objRoot;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new MainFrame(new mySphere(), 256, 256);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -