Java Reference
In-Depth Information
Figure 10-1. The First3DExample program
3D objects, lights, and cameras live in a three-dimensional space in which every point is represented by a tuple
of three floating point numbers ( x , y , z ). The three-dimensional space is right-handed, which means if you stretch out
the first three fingers of your right hand so that the thumb points to the positive x direction and the index finger points
to the positive y direction, then the third finger points to the positive z direction.
The sphere we created in the program is centered at the origin (0, 0, 0) and has a radius of 100. The camera that
the JavaFX runtime system added for us is a parallel camera located in negative z axis looking into the xy plane in
such a way that the positive x direction points to the right; consequently the positive y direction points down and
the positive z direction points into the screen. The light that the JavaFX runtime system added for us is at the same
location as the camera, and it radiates light equally in all directions.
What is shown in the First 3D Example window is a two-dimensional representation of the 3D model. Not
everything in the 3D model is shown in the window. For example, the back side of the sphere is not visible. Any part of
the 3D model that lies outside the scene's bounds is also not visible. The process of determining what is shown in the
two-dimensional representation is called rendering .
In this rendered scene, the top left corner has (0, 0) as its xy coordinates, and the bottom right corner has (640,
480) as its xy coordinates. To have the sphere appear in the middle of the screen, we translated the container root by
half the screen width in the x direction, and by half the screen height in the y direction. Notice that the sphere seems
to be illuminated from a light source located at (0, 0, z ) for some negative z .
To get a sense of how the coordinate system is oriented in this 3D scene with default camera and light, we can
animate the position of the sphere in the x direction by introducing a field:
DoubleProperty translateX = new SimpleDoubleProperty();
Bind the translateX property of the sphere to it after we create the sphere :
sphere.translateXProperty().bind(translateX);
 
Search WWH ::




Custom Search