Java Reference
In-Depth Information
In this code,
anchorX
and
anchorY
are double fields of the class, and
angleX
and
angleY
are double properties
that are bound to the degrees of rotations of the parent node that contains the sphere around the
x
and
y
axis. Here
we capture the screen coordinates of the mouse pointer as
anchorX
and
anchorY
when the mouse is pressed on the
screen. We also query for the degree of rotation about the
x
and
y
axes of the parent node that contains the sphere.
When the mouse is dragged, we alter the degree of rotation of the parent node that contains the sphere about the
y
axis by adding the difference between
anchorX
and the screen
x
coordinate of the new mouse location. Therefore, if
you click on the screen and drag the mouse to the right,
anchorX - event.getScreenX()
is a negative number, hence
we decrease the angle of rotation about the
y
axis. Because in this program, the
y
axis is pointing down, a decrease of
the rotation about the
y
axis actually makes the sphere to appear to be rotating to the right, matching the direction of
the mouse drag.
Understanding the PickResult Class
The JavaFX 3D runtime provides enhanced information about the interplay of the mouse pointer with the 3D scene.
This information is provided in terms of an object of class
PickResult
in the relevant event objects. It is contained in
the
javafx.scene.input
package. The following event objects provide a
getPickResult()
method that allows you to
retrieve this
PickResult
object:
•
ContextMenuEvent
DragEvent
•
GestureEvent
•
RotateEvent
•
ScrollEvent
•
SwipeEvent
•
ZoomEvent
•
MouseEvent
•
MouseDragEvent
•
TouchPoint
The
PickResult
class provides the following public constructors:
•
PickResult(EventTarget, double, double)
•
PickResult(Node, Point3D, double)
•
PickResult(Node, Point3D, double, int, Point2D)
The first two constructors are used to create
PickResult
s to work with 2D scenes, and the third constructor
creates a
PickResult
that contains 3D information. The
PickResult
s are usually created by the JavaFX 3D runtime.
JavaFX application code usually obtains
PickResult
s by calling the accessor method on the event object.
The
PickResult
class provides the following public methods:
•
Node getIntersectedNode()
•
Point3D getIntersectedPoint()
•
double getIntersectedDistance()
•
int getIntersectedFace()
•
Point2D getIntersectedTexCoord()
•
Search WWH ::
Custom Search