Chapter 12. Game Pad Grabbers
Back in chapter 4,
I developed an example involving two multi-jointed arms with fingers
(the grabbers). One drawback of the coding was the bewildering mix of
key combinations needed to translate and rotate the arms.
This chapter connects a game pad to the grabbers, making them much
easier to control, mainly because of the intuitive mapping of the grabbers
operations to the pad's analog sticks, hat, and buttons. For example,
the left stick controls the x- and y- axis rotations of the left arm,
and the right stick handles the right arm.
Another advantage of using a game pad is that it becomes simpler for
the code to process multiple inputs at the same time. For instance,
the grabbers' base can rotate and move forward while the arms are
turning. This is due to the use of polling, which collects information
from multiple game pad components at once.
Other novel features of this example are:
- Obstacles. The obstacles are rendered as semi-transparent boxes,
which can be placed anywhere on the floor. I've surrounded the scene's
3D models and ground shapes with them (as shown in the screenshot).
The grabbers can't move through obstacles.
- Collision Detection. The original grabbers example detects
collisions with the help of Java 3D wakeup criteria and a behavior.
In this chapter I use a simpler mechanism, a try-it-and-see approach,
which stops the grabber arms passing through each other, the floor, or
traveling into the obstacles. Also, when a collision is detected, the
game pad's rumbler is switched on to give the user some feedback.
- Multiple Input Sources. The grabbers are controlled via
operations sent from the game pad and the keyboard, but with the
input data converted into GrabberOp objects. This lets the grabbers
execute without having to know the source of their operations, which
makes it easy to connect other forms of input (such as a mouse).
- Sound. I develop a simple SoundsPlayer class which can
continuously play music in the background, and short sound clips
when the grabbers hit obstacles.
- Platform Geometry. The grabbers are attached to the camera
viewpoint, so the arms translate and rotate in unison with the camera.
This only requires minor adjustments to the grabber classes from
chapter 4.
Most of the changes are reductions in the dimensions of the component
cylinders and boxes because of their proximity to the viewpoint.
Downloads
- The PDF file for the chapter
(138 KB). Last updated: 25th October 2006.
- Zipped Source code (337 KB).
Last updated: 25th January 2007.
I modified the Obstacle and Grabbers classes to use single
threaded executor services to play sounds and the game pad
rumbler.
Navigation:
Dr. Andrew Davison
E-mail: ad@coe.psu.ac.th
Back to my home page