jme-神看光是好的,要有光

神看光是好的,於是,轉動地球的一面有了光亮。
1.創造一個方塊形狀的網格(Mesh);
2.加載一個能夠感光的材質(Material);
3.創造一個幾何體(Geometry),應用剛纔和網格和材質;
4.創造一束定向光(DirectionalLight),並讓它斜向下照射,好使我們能夠看清那個方塊;

5.將方塊和光源都添加到場景圖(rootNode)中。

public class HelloJME3 extends SimpleApplication {

	private Geometry geom;

	/**
	 * 初始化3D場景,顯示一個球體。
	 */
	@Override
	public void simpleInitApp() {
		
		// #1 創建一個球形的網格
		Mesh mesh = new Sphere(16, 24, 1);

        // #2 加載一個感光材質
        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");

        // #3 創建一個幾何體,應用剛纔和網格和材質。
        geom = new Geometry("Box");
        geom.setMesh(mesh);
        geom.setMaterial(mat);

        // #4 創建一束陽光,並讓它斜向下照射,好使我們能夠看清那個方塊。
        DirectionalLight sun = new DirectionalLight();
        sun.setDirection(new Vector3f(-1, -2, -3));
        
        // #5 將方塊和都添加到場景圖中
        rootNode.attachChild(geom);
        rootNode.addLight(sun);       
	}
	
	/**
	 * 主循環
	 */
	@Override
	public void simpleUpdate(float deltaTime) {
		// 旋轉速度:每秒360°
		float speed = FastMath.TWO_PI;
		// 讓方塊勻速旋轉
		geom.rotate(0, deltaTime * speed, 0);
	}

	public static void main(String[] args) {
		// 配置參數
		AppSettings settings = new AppSettings(true);
		settings.setTitle("一個方塊");
		settings.setResolution(480, 720);
		
		// 啓動jME3程序
		HelloJME3 app = new HelloJME3();
		app.setSettings(settings);// 應用參數
		app.setShowSettings(false);
		app.start();
	}
}

效果圖如下:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章