Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 17 ■ i3D Game Square SeleCtion: uSinG the piCkreSult ClaSS with 3D moDelS


The first two constructor methods in the PickResult class create PickResult objects that handle 2D
and 2.5D Scene picking scenario results. The first constructor creates a PickResult object for a 2D scenario
using an EventTarget object and (double) sceneX and sceneY properties. This constructor method uses the
following Java statement syntax:


PickResult(EventTarget target, double sceneX, double sceneY);


The second constructor creates a PickResult object for a “non-Shape3D” target. Since it uses the
Point3D object and distance, I call this the 2.5D PickResult scenario because it does not support 3D
primitives based on the Shape3D class. However, it does support the Point3D object and the concept of
distance into the Scene object. This constructor method uses the following Java statement syntax:


PickResult(Node node, Point3D point, double distance)


The third constructor creates a PickResult object for a Shape3D target, which is what we are using to
create our i3D games. The Java syntax for creating this constructor method should look like the following
Java statement:


PickResult(Node node, Point3D point, double dist, int face, Point2D texCoord);


The fourth constructor creates a PickResult object for an imported 3D object target that contains
Normals. This would be utilized if you imported an advanced 3D model from an external 3D modeling
software package such as Blender. The Java syntax for creating this advanced constructor method should
look like the following Java statement:


PickResult(Node node, Point3D point, double distance, int face, Point3D normal, Point2D
texCoor)


The PickResult class supports six .get() method calls, which return an intersected distance, an
intersected face, an intersected Node, an intersected Normal, an intersected Point, or an intersected
texture coordinate (texCoord). A .getIntersectedDistance() method call will return, as a double value, the
intersected distance between your current camera position and an intersected point.
The .getIntersectedFace() method call will return an integer representing the intersected face of
the picked Node. If the node doesn’t have user-specified faces, such as one of the Shape3D primitives, or
was picked on bounds, this method will return a FACE_UNDEFINED constant. A .getIntersectedNode()
method call will return an intersected node as a Node object and is the method call we’ll be using to select
the spinner UI and gameBoard Node elements.
The .getIntersectedNormal() method call will return an intersected Normal of the picked
Shape3D object or imported 3D geometry. The .getIntersectedPoint() method call will return an
intersected point (Point3D object) using the local coordinate system for your picked Node object. The
.getIntersectedTexCoord() method call will return the intersected texture coordinates of the picked 3D
shape in Point2D object format.
Next, let’s take a look at another important event-handling class, MouseEvent. This is a subclass of
InputEvent and used to attach mouse event handling to the 3D primitives we have utilized to create your i3D
BoardGame simulation.

Free download pdf