Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

© Wallace Jackson 2017 409
W. Jackson, Pro Java 9 Games Development, https://doi.org/10.1007/978-1-4842-0973-8_17


CHAPTER 17


i3D Game Square Selection:


Using the PickResult Class with


3D Models


Now that you have created the multitiered gameBoard Group Node (subclass) hierarchy, textured all of
the 3D components underneath that hierarchy, made sure the hierarchy center-rotates, created a spinner
UI to randomly rotate the gameBoard 3D model (hierarchy) to a random quadrant, and added animation
objects to your game design using your createAnimationAssets() method, it is time to make your 3D game
elements interactive. We will set up your 3D object mouse click event handling code that will be used to
trigger the 3D spinner animation and select game board squares.
During this chapter we’ll take a detailed look at the public PickResult class and public MouseEvent
class and use these for our own gameplay design in a custom createSceneProcessing() method that will be
used to process i3D game element (Box and Sphere object) event handling so that our players can interact
with the 3D game components.


Select Your 3D Assets: The PickResult Class


The public class PickResult extends Object and is kept in the javafx.scene.input package, which contains
input event handling utilities such as clipboard, GestureEvent, SwipeEvent, TouchEvent, and ZoomEvent.
The PickResult object contains the result of a pick event, in the case of this game, from a mouse or touch.
Input classes that support using a PickResult object in their constructor methods include MouseEvent,
MouseDragEvent, DragEvent, GestureEvent, ContextMenuEvent, and TouchPoint. There is a .getPickResult()
method call in each of these classes that returns the PickResult object, which contains all the pick
information that you’ll need to process for your Java game development.
A Java class hierarchy for a PickResult class shows us that this class was scratch-coded to provide 3D
object selection capabilities; it has no superclass of its own and therefore looks like the following Java 9 class
hierarchy:


java.lang.Object



javafx.scene.input.PickResult



The PickResult class contains one data field, the static int FACE_UNDEFINED data field, which
represents an undefined face. We will generally be using this class to select entire nodes (the spinner,
quadrants q1 through q4, squares Q1S1 through Q4S5, and similar 3D game elements) and not individual
polygon faces or texture map pixels, which is also possible.

Free download pdf