package Java3D;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
import javax.media.j3d.Alpha;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Point3d;
public class SpinCube {
public SpinCube(){
SimpleUniverse uni = new SimpleUniverse();
uni.getViewingPlatform().setNominalViewingTransform();
BranchGroup group = createSceneGraph();
uni.addBranchGraph(group);
}
private BranchGroup createSceneGraph() {
BranchGroup branch = new BranchGroup();
TransformGroup trans = new TransformGroup();
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
branch.addChild(trans);
ColorCube cube = new ColorCube(0.4);
trans.addChild(cube);
Alpha spin = new Alpha(-1,1000);
RotationInterpolator rotate = new RotationInterpolator(spin,trans);
rotate.setSchedulingBounds(new BoundingSphere(new Point3d(),1000.0));
trans.addChild(rotate);
branch.compile();
return branch;
}
public static void main(String[] args){
new SpinCube();
}
}
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
import javax.media.j3d.Alpha;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Point3d;
public class SpinCube {
public SpinCube(){
SimpleUniverse uni = new SimpleUniverse();
uni.getViewingPlatform().setNominalViewingTransform();
BranchGroup group = createSceneGraph();
uni.addBranchGraph(group);
}
private BranchGroup createSceneGraph() {
BranchGroup branch = new BranchGroup();
TransformGroup trans = new TransformGroup();
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
branch.addChild(trans);
ColorCube cube = new ColorCube(0.4);
trans.addChild(cube);
Alpha spin = new Alpha(-1,1000);
RotationInterpolator rotate = new RotationInterpolator(spin,trans);
rotate.setSchedulingBounds(new BoundingSphere(new Point3d(),1000.0));
trans.addChild(rotate);
branch.compile();
return branch;
}
public static void main(String[] args){
new SpinCube();
}
}
No comments:
Post a Comment