Java Reference
In-Depth Information
The default constructor creates a sphere of radius 1. The one-parameter constructor creates a sphere with the
specified radius. The two-parameter constructor creates a sphere with the specified radius and the number of division
points to use along the equator of the sphere to approximate the sphere shape with a set of triangles. The greater the
division, the smoother the resulting sphere is. The division number defaults to 64. The center of newly constructed
Sphere
s is always at the origin of the three-dimensional space (0, 0, 0).
The
radius
of the sphere is available as a read-write double property. The
divisions
can only be set at
construction time, and can be gotten using
getDivisions()
.
The
Cylinder
class has the following constructors:
•
Cylinder()
•
Cylinder(double radius, double height)
Cylinder(double radius, double height, int divisions)
The default constructor creates a cylinder with base radius of 1 and height of 2. The two-parameter constructor
creates a cylinder with the specified base radius and height. The three-parameter constructor creates a cylinder with
the specified base radius and height and the number of division points to use along the circumference of the base to
approximate the cylinder shape with a set of triangles. The greater the division number, the smoother the resulting
cylinder is. The division number defaults to 64. The base of a newly constructed
Cylinder
is parallel to the
xz
plane,
and the height is parallel to the
y
axis. The center of newly constructed
Cylinder
s is always at the origin of the
three-dimensional space (0, 0, 0).
The
radius
and
height
of the cylinder are available as read-write double properties. The divisions can only be set
at construction time, and can be gotten using
getDivisions()
.
The Box class has the following constructors:
•
Box()
•
Box(double width, double height, double depth)
•
The default constructor creates a box with a size of 2 in all three directions. The three-parameter constructor
creates a box with the specified width, height, and depth. The width is parallel to the
x
axis, the height is parallel to the
y
axis, and the depth is parallel to the
z
axis. The center of newly constructed
Box
es is always at the origin of the three-
dimensional space (0, 0, 0).
The
width
,
height
, and
depth
of the box are available as read-write double properties.
The program in Listing 10-3 illustrates the three predefined 3D shapes in JavaFX.
Listing 10-3.
Predefined3DShapesExample.java
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.geometry.Point3D;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
Search WWH ::
Custom Search