3D Capabilities in JavaFX 1.3 Release
Join the DZone community and get the full member experience.
Join For FreeLast week on the 22nd April 2010, JavaFX 1.3 Release was released to the general public. I immediately scanned the release notes and was intrigued by the 3D capabilities. Congratulations to the SDK team for listening to criticism and improvements, mine included. I suggested in an AudioBoo that we needed a Capabilities API for the platform. It is now included there.
So if you do have accelerated GPU chip as your graphic card and you run the follow application with the JVM argument -Xtoolkit prism you will be surprised.
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.control.Slider;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.layout.Tile;
import javafx.scene.control.Label;
import javafx.scene.layout.LayoutInfo;
import javafx.scene.PerspectiveCamera;
import javafx.scene.transform.*;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
var fieldOfView = 200.0 on replace {
println("fieldOfView={fieldOfView}");
};
var rotateX: Number on replace {
println("rotateX={%5.2f rotateX}")
};
var rotateY: Number on replace {
println("rotateY={%5.2f rotateY}")
};
var rotateZ: Number on replace {
println("rotateZ={%5.2f rotateZ}")
};
var scene: Scene;
var rect: Rectangle;
/**
* Research JavaFX 3D with a basic 2D rectangle
* www.xenonique.co.uk
* 27th April 2010
* @author Peter Pilgrim
*/
Stage {
title: "Peter Pilgrim:: Research JavaFX 1.3 Release :: XeNoNiQUe :: London, UK"
scene: scene =Scene {
camera: PerspectiveCamera {
fieldOfView: bind fieldOfView
}
fill: LinearGradient {
startX: 0.0 startY: 0.0
endX: 0.0 endY : 1.0
stops: [
Stop {
color : Color.LIGHTGRAY
offset: 0.0
},
Stop {
color : Color.DARKGRAY
offset: 0.25
},
Stop {
color : Color.GRAY
offset: 1.0
},
]
}
width: 500
height: 500
content: [
Text {
layoutX: 50
layoutY: bind scene.height - 150
font : Font { size : 12 }
content:
"Rectangle rotation in X,Y and Z manipulate with Slider\n"
"No Graphics 3D Primitives in FX 1.3 release!\n"
"You can translate 2D SG object in 3D space\n"
"No yet ready for 3D graphic application then."
},
rect = Rectangle {
translateX: 200
translateY: 200
translateZ: 100
transforms: [
Rotate {
axis: Rotate.Y_AXIS
angle: bind rotateX
},
Rotate {
axis: Rotate.X_AXIS
angle: bind rotateY
},
Rotate {
axis: Rotate.Z_AXIS
angle: bind rotateZ
}
]
x: -100, y: -100
width: 200, height: 200
arcWidth: 10 arcHeight: 10
fill: Color.web("#ff9900")
strokeWidth: 2
stroke: Color.web("#FF0000")
},
Tile {
layoutX: 10
layoutY: 10
columns: 2
hgap: 3
vgap: 6
content: [
Label {
layoutInfo: LayoutInfo { width: 200 }
text: "Rotate X:"
},
Slider {
layoutInfo: LayoutInfo { width: 200 }
min: 0
max: 360
vertical: false
value: bind rotateX with inverse
},
Label {
layoutInfo: LayoutInfo { width: 200 }
text: "Rotate Y:"
},
Slider {
layoutInfo: LayoutInfo { width: 200 }
min: 0
max: 360
vertical: false
value: bind rotateY with inverse
},
Label {
layoutInfo: LayoutInfo { width: 200 }
text: "Rotate Z:"
},
Slider {
layoutInfo: LayoutInfo { width: 200 }
min: 0
max: 360
vertical: false
value: bind rotateZ with inverse
},
Label {
layoutInfo: LayoutInfo { width: 200 }
text: "Field of View:"
},
Slider {
layoutInfo: LayoutInfo { width: 200 }
min: 0
max: 360
vertical: false
value: bind fieldOfView with inverse;
},
]
}
]
}
}
- JavaFX 1.3 release has no 3D graphics primitives (yet).
- There is however javafx.geometry.Point3D and that seems to be defining rotation around an arbitary axis in 3D space
- There is no way to find out the world view transform or even the perspective transform through the API. (Pick up an educational computer graphics book, like James D. Foley's or Dr. Alan Watts to understand these concepts 4 dimensional matrix transformations. )
- There is a way to translate 2D shapes into 3D cartesian space as the code above illustrates
- The rotation of objects in the 3D world of JavaFX is a little weird at the moment. (From the example of code above, I am unsure, if I got it completely correct)
The new grahics stack is decent proof of concept and more importantly proof of delivery of the new architecture. So my worries aside of the Oracle acquisition of Sun, I know that my next great space 3D game will not be written with JavaFX 1.3, however the speed and the runtime performance are most welcome.
Peter Pilgrim. Fast tracked blog entry. Out
PS: I believe change the field-of-view dynamically does not work in the example. However I may have written it wrong? Have a pop yourself.
From http://www.jroller.com/peter_pilgrim/entry/3d_capabilities_in_javafx_1
Opinions expressed by DZone contributors are their own.
Comments