雖然工作在進行Android開發,但是在項目業餘的時間裡,我都在進行Unity3d的學習。也製作了一個聯機的坦克對戰遊戲。而在晚上有時間的時候,也只是在Mac mini上學習IOS的開發,所以沒怎麼寫部落格。
JavaFX,之前還是對它高度興趣,不過後來發現JavaFX還是只適合開發小遊戲,對於大一點的遊戲來說,效率不夠。所以有一段時間沒有研究JavaFX了。
不過JavaFX也有一個好訊息,在JDK 8中,JavaFX即將支援3D了。包括3d mesh,Camera和燈光等。
JDK 8的:http://jdk8.java.net/download.html
下面是一個小樣本:
import javafx.application.Application;import javafx.scene.*;import javafx.scene.paint.Color;import javafx.scene.paint.PhongMaterial;import javafx.scene.shape.*;import javafx.stage.Stage; public class Shapes3DViewer extends Application { @Override public void start(Stage stage) { PhongMaterial material = new PhongMaterial(); material.setDiffuseColor(Color.LIGHTGRAY); material.setSpecularColor(Color.rgb(30, 30, 30)); Shape3D[] meshView = new Shape3D[] { new Box(200, 200, 200), new Sphere(100), new Cylinder(100, 200), }; for (int i=0; i!=3; ++i) { meshView[i].setMaterial(material); meshView[i].setTranslateX((i + 1) * 220); meshView[i].setTranslateY(500); meshView[i].setTranslateZ(20); meshView[i].setDrawMode(DrawMode.FILL); meshView[i].setCullFace(CullFace.BACK); }; PointLight pointLight = new PointLight(Color.ANTIQUEWHITE); pointLight.setTranslateX(800); pointLight.setTranslateY(-100); pointLight.setTranslateZ(-1000); Group root = new Group(meshView); root.getChildren().add(pointLight); Scene scene = new Scene(root, 800, 800, true); scene.setFill(Color.rgb(10, 10, 40)); scene.setCamera(new PerspectiveCamera(false)); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); }}
不過目前,只支援Windows平台,可以在其他平台使用的OpenGL的版本正在開發中。
有興趣的可以下載JDK 8嘗試一下效果。
補充一個網址 計劃在JDK 8中添加的JavaFX 3D的相關內容:
https://wikis.oracle.com/display/OpenJDK/3D+Features
可以看到包括攝像機,3D幾何元素,燈光,材質,3D拾取和3D模型載入等內容。