Java 怎么创建三维宇宙

2019年7月29日20:06:02Java 怎么创建三维宇宙已关闭评论 320 922字阅读3分4秒

1.简介

Java 怎么创建三维宇宙?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import java.awt.Frame;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
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.*;

public class Main extends Applet { 
    SimpleUniverse simpleU; 

    public void init() {
        setLayout(new BorderLayout()); 

        Canvas3D c = new Canvas3D(
                SimpleUniverse.getPreferredConfiguration());

        add("Center", c);

        simpleU = new SimpleUniverse(c); 

        BranchGroup scene = createSceneGraph();

        simpleU.getViewingPlatform().setNominalViewingTransform();
        scene.compile();
        simpleU.addBranchGraph(scene); 
    }

    public BranchGroup createSceneGraph() {
        BranchGroup objRoot = new BranchGroup();
        ColorCube c = new ColorCube(0.5f);
        objRoot.addChild(c);
        return objRoot;
    }

    public void destroy() { 
        simpleU.removeAllLocales();
    }

    public static void main(String[] args) {
        Frame frame = new MainFrame(new Main(), 500, 500);
    }
}

 
继续阅读
编程十万个怎么办