Java Reference
In-Depth Information
same size regardless of distance to the camera. This is called
orthographic projection,
and although much easier
to calculate, it does not look realistic. The
PerspectiveCamera
is more interesting for 3D modeling. When using a
PerspectiveCamera
, objects in the distance are smaller than objects in the foreground.
Understanding the PerspectiveCamera
The
PerspectiveCamera
class has the following public constructors:
•
PerspectiveCamera()
PerspectiveCamera(boolean fixedEyeAtCameraZero)
The default constructor creates a
PerspectiveCamera
with the
fixedEyeAtCameraZero
set to false. The
one-parameter constructor creates a
PerspectiveCamera
with the specified
fixedEyeAtCameraZero. Cameras
are
Node
s, and can be placed in a JavaFX scene. A newly created
PerspectiveCamera
, like a newly created
Sphere
or
Cylinder
or
Box
, has its center or eye located in the origin (0, 0, 0) of the three-dimensional space. The eye looks into
the positive
z
direction. As a
Node
, the
PerspectiveCamera
itself can be transformed by 3D transformations such as
Rotate
,
Translate
,
Scale
, or even the generic
Affine
. A
fixedEyeAtCameraZero
setting of
true
guarantees that after
such transforms, the eye of the
PerspectiveCamera
moves along with it, and remains at the camera's zero position. A
fixedEyeAtCameraZero
setting of
false
allows the eye to drift away from the camera's zero position to accommodate
what is in the scene. This is useful for rendering 2D scenes and only makes sense when the camera itself is not
transformed in any way. Therefore for use with a 3D model, you should always use the one-parameter constructor,
passing in a
fixedEyeAtCameraZero
of
true
.
The
PerspectiveCamera
class has the following public methods:
•
•
void setFieldOfView(double)
•
double getFieldOfView()
•
DoubleProperty fieldOfViewProperty()
•
void setVerticalFieldOfView(boolean)
•
boolean isVerticalFieldOfView()
•
BooleanProperty verticalFieldOfViewProperty()
boolean isFixedEyeAtCameraZero()
These methods define two properties,
fieldOfView
and
verticalFieldOfView
, for the
PerspectiveCamera
class. The
fieldOfView
is a double property and represents the field of view of the perspective camera in degrees.
The default value is 30 degrees. The
verticalFieldOfView
is a boolean property that determines if the field of view
property applies to the vertical dimension of the projection plane. The
isFixedEyeAtCameraZero()
method returns
the
fixedEyeAtCameraZero
flag the
PerspectiveCamera
is constructed with.
The
PerspectiveCamera
also inherits two double properties from the
Camera
abstract class:
nearClip
and
farClip
. Objects closer to the eye than
nearClip
and objects farther from the eye than
farClip
are not rendered in
the scene.
In the program in Listing 10-5, we create a
Box
and a
PerspectiveCamera
. Unlike in previous examples where
we transform the 3D objects themselves like the
Box
, in this program we keep the
Box
fixed and transform the
PerspectiveCamera
with a combination of rotating around the
x
axis, rotating around the
y
axis, and a translation
along the
z
axis. We animate the rotation degrees from 90 to -90 and the
z
translation from -20 to -80 in a five-second
Timeline
.
•
Search WWH ::
Custom Search