Create strange lands filled with mysterious objects (cows frozen in blocks of ice, chirping penguins, golden globes with wavering eyes) and throw away your keyboard and mouse, to go exploring armed only with a gamepad, power glove, or just your bare hands!\ Java gaming expert Andrew Davison will show you how to develop and program 3D games in Java technology on a PC, with an emphasis on the construction of 3D landscapes. It's assumed you have a reasonable knowledge of Java—the sort of thing...
Create strange lands filled with mysterious objects (cows frozen in blocks of ice, chirping penguins, golden globes with wavering eyes) and throw away your keyboard and mouse, to go exploring armed only with a gamepad, power glove, or just your bare hands�Java gaming expert Andrew Davison will show you how to develop and program 3D games in Java technology on a PC, with an emphasis on the construction of 3D landscapes. It's assumed you have a reasonable knowledge of Java - the sort of thing picked up in a first Java course at school.Topics are split into three sections: Java 3D API, non-standard input devices for game playing, and JOGL. Java 3D is a high-level 3D graphics API, and JOGL is a lower-level Java wrapper around the popular OpenGL graphics API.Youll look at three non-standard input devices: the webcam, the game pad, and the P5 data glove. Along the way, youll utilize several other games-related libraries including: JInput, JOAL, JMF, and Odejava.Learn all the latest Java SE 6 features relevant to gaming, including: splash screens, JavaScript scripting as well as the desktop and system tray interfaces.Unique coverage of Java game development using both the Java 3D API and Java for OpenGL, as well as invaluable experience from a recognized Java gaming guru, will provide you with a distinct advantage after reading this book.
About the Author xixAbout the Technical Reviewers xxiAcknowledgments xxiiiIntroduction xxvJava 3DIntroducing Java 3D 3Overview of Java 3D 3Overview of the Scene Graph 4Some Java 3D Scene Graph Nodes 5The HelloUniverse Scene Graph 5Java 3D Strengths 7The Scene Graph 7Performance 7Unique Features 8Java Integration 8Documentation and Examples 8Criticisms of Java 3D for Games Programming 9Java 3D's Level of Abstraction 9Java 3D Games 10Java 3D Support 12Alternatives to Java 3D 13Summary 14Get a Life (in 3D) 15The Game of Life 15Running Life3D 16Configuring Life3D 16A Life3D Screensaver 17An Overview of the Life3D Classes 18Deciding How to Start 19Displaying the 3D Game 20Integrating Java 3D and Swing 20WindowSizing 21Processing Key Presses 21Scene Graph Creation 22Lighting the Scene 24The Scene's Background 24Building the Cells Grid and Making It Behave 25Viewer Positioning 25Viewer Movement 27Behaviors in Java 3D 27A Time-Based Behavior 29Managing the Grid 29Accessing Properties 30Creating the Grid Scene Graph 31Updating the Cells States 33Will the Cell Live or Die? 34Rotating the Grid 36The Cell 37Building the Cell's Scene Graph 39Coloring the Cells 41Setting the Cell's Visibility 42Changing a Cell's Life State 43Visual Changes to a Cell 44Time for Screensavers 45Changing Life3D into a Screensaver 46Problems with Screensavers 47The SaverBeans SDK 47More Life Required? 47Summary 48Get a Life (the Java 6 Way) 49Life3D Basics 49An Overview of the Life3D Classes 50Making a Splash 52Animating a Clock 53Drawing onto a Splash 54Drawing the Clocks 54JAR Packaging 55Adding ClockAnimation to Life3D 55The Desktop API 56Using the Desktop Browser 56What Other Browser Capabilities Are There? 57The System Tray 57Creating Life3D's Popup Menu 58The Menu Contents 58Creating the Traylcon 59Building the Popup Menu 60Listening for Actions 62Using a Text Editor 64Launching an E-mail Client 65Listening for the Check Boxes 66Scripting in Java SE 6 67Executing a Script 68Communicating with a Script 69Speeding Things Up 72Calling Script Functions 73Letting a Script Use Java 74More Scripting Information 74Scripting in Life3D 74Initializing the Grid 75Changing the Grid's State 76Executing the Script Rules 78The Rules Script 80Summary 81The Colliding Grabbers 83Building Articulated Arms 83Class Diagrams for Arms3D 84Creating the Application Window 85Drawing the 3D Scene 86Processing the Keys 88Monitoring Grabber Joints 89Managing the Grabbers 90Adding the Grabbers to the Scene Graph 90Processing Keyboard Commands 93Translating the Grabbers 94Rotating a Grabber Joint 95Collecting the Collision Joints 96Collision Detection and Recovery 97Why Bother with JointsBehavior? 97Touching the Floor 98The Grabber 98Making the Grabber's Appearance 98The Grabber Shape 100Local and Global Coordinate Systems 105Making the Fingers 106Handling Rotation Commands 108Collision Detection 110Implementing Collision Detection 111Initializing the Bounding Spheres 114Positioning the Bounding Spheres 114Touching the Ground 115The Floor 116The Colored Tiles 118The Floor's Axes Labels 119Summary 120When Worlds Collide 121Odejava and ODE 121Installing Odejava 123Documentation, Examples, and Online Help 123Bouncing a Ball 124Three-Stage Simulation 125Initializing the Engines 126Initializing Static Objects 126Initializing Dynamic Objects 127Executing the Simulation 127Performing a Simulation Step 128Examining the Contact Points 129Cleaning Up 129Visualizing Balls in a Box 129Creating the Scene 131The Box 133Managing the Spheres 137A Sphere 139I'm Steppin' Out 142A Note of Application Development 143Summary 144A Multitextured Landscape 145Surveying the Landscape 145Building the Scene 147Creating the Floor 149Start the Balls Moving 150Moving Around the Scene 150The Multitextured Floor 150Heights Map Generation 153The Floor's Geometry 155The Floor's Appearance 158The Splash Shape 162The Splash Shape's Geometry 163The Splash Shape's Appearance 166Moving Balls 170Positioning the Ball 173Moving About 174Driving the Balls 176More Multitexturing 176Bump Mapping 176Shaders 177Summary 177Walking Around the Models 179Populating a Scene 179Class Diagrams for ObjView3D 180A Spherical Background 181A Skybox Background 182A Skybox Built with Quads 183Terragen and NConvert 184From Images to Textures 185Making the Skybox 186Texturing a Plane 187The Size of the Skybox 188Loading Models 189Loading OBJ Models 189The OBJ Model Loader 190Positioning a Model 193Ground Cover 195Manipulating the User's Viewpoint 197Positioning the User's Viewpoint 198Moving the Viewpoint at Runtime 198Setting Up the Key Behavior 199Processing a Key 199Summary 201More Backgrounds and Overlays 203Retained, Immediate, and Mixed Modes 203The Earth, Moon, and Mars 204Building the Scene 206The Background 209Some Variations on a Theme 209Spinning the Background 212Building the Scene and Terminating 213Rotating the Image 214Manipulating the Image 215Rotation and Clipping 215Avoiding Gaps in the Rotated Image 216Terminating the Thread 218Drawing the Background Image 218The Model Viewer with a Shifting Background and Overlays 219Setting Up the Canvas 221Modifying the Key Behavior 222A Canvas with a Background and Overlays 223Drawing the Background 225The Deep Blue Sea 227Adding Overlays 228Summary 229Nonstandard Input DevicesWebcam Snaps 233Webcam Snaps with TWAIN 233Displaying Pictures Using TWAIN 234Snapping a Picture Again and Again and... 235The TWAIN Capture Device 237TWAIN Timing Tests 240Webcam Snaps with JMF 241Again Taking Pictures Again and Again 242The Capture Device with JMF 243Comparing TWAIN and JMF Capture 247QTJ 247Other Uses for Webcam Snaps 248Summary 249Navigating a 3D Scene by Waving Your Arm 251Using the Wrist Strap 251Image Processing 253Image Processing Issues 254Dealing with the Issues 254Finding the Bands 255FindBands Class Diagrams 256Image Processing Overview 257The Bands Analyzer 257The Band Manager 263Representing a Blob 265Arm Navigation 266Creating the 3D Scene 267Moving the User's Viewpoint 268From Analysis to Action 269Other Approaches 270JAI 270ImageJ 271Image Processing Books 271Summary 271Building a Gamepad Controller with JInput 273JInput 273The Gamepad and Windows 274Installing and Testing JInput 276Examining the Input Devices 277The Other JInput Test Applications 279Three JInput Applications 280Listing the Controllers 281Viewing Controller Details 281Testing a Controller 286A Gamepad Controller 287Initializing the Controller 289Checking the Components 290Finding the Rumblers 292Polling the Device 292Reading the Stick Axes 293Reading the POV Hat 294Reading the Buttons 295Using the Rumbler 296Other Approaches 296Swing and JInput 297Constructing the Application 298Polling the Gamepad 299Alternatives to JInput 300Summary 301Gamepad Grabbers 303Example Overview 303Playing Sounds 305Background Music with SoundsPlayer 307Obstacle Noises with SoundsPlayer 307Managing Obstacles 308Making an Obstacle 309Making the Boxes 310Collision Detection 311Sending Input to the Grabbers 312Processing Keyboard Input 313Building a Grabber Operation for a Key Press 314Processing Gamepad Input 316Building a Grabber Operation for the Gamepad 318The Grabbers 319Connecting the Grabbers to the Camera 319Constructing the Grabbers 320Processing an Operation 321The Grabber Arms 326Summary 3263D Sound with JOAL 327Why JOAL and Java 3D? 327Background on OpenAL and JOAL 328What About JOAL? 328Installing JOAL 329Managing JOAL Sounds 330Initializing JOAL 330Initializing the Listener 331JOAL Clean Up 333Loading a Sound 333Positioning a Source 336Playing, Stopping, and Pausing a Source 337Moving the Listener 337Turning the Listener 338Using JOALSoundMan 340Moving a Source 340Moving the Listener 341Moving the Listener Between Sources 342Turning the Listener 343JOAL and Swing 344Other Source Types 346Ambient Sounds 346Cone Sounds 346Summary 347The P5 Glove 349Introducing the P5 Glove 349Using Kenner's Java API 351Examining the Glove's Data 352What ShowGlove Displays 353ShowGlove Overview 355Initializing and Terminating the Glove 356Polling the Glove 356The Glove 357Updating and Accessing the Glove 358Closing Down 359A Specialized Glove Class 359Initializing the Glove 360Updating and Closing 360Getting the Position 360On a Roll 361Clenching My Fist 362Pressing the A Button 362A Test Rig for FPSGlove 363Visiting the Musical Cow 365The Glove Behavior 366Adding a Musical Cow 370Initializing the Viewpoint 371Cleaning Up 371The P5 Glove and JInput 372Summary 373JOGLTwo JOGL Programming Frameworks 377What Is JOGL? 377Installing JOGL 378The Callback Framework 379Using GLCanvas 379Using GLJPanel 380Rotating a GLCanvas Cube with Callbacks 381Building the Top-Level Window 382Connecting the Canvas 383Building the Listener 383Measuring FPS Accuracy 388Rotating a GLJPanel Cube with Callbacks 389Building the Panels 391The Background Panel 391Making the 3D Background Transparent 392Timing the GLJPanel 393More Visual Effects with GLJPanel 393Callback Summary 393The Active Rendering Framework 393Rotating a Cube with Active Rendering 395Building the Application 396Dealing with Window Events 397Preparing the Canvas 397Thread Rendering 398The Game Life Cycle Methods 404Statistics Reporting 405Java 3D and JOGL 405More Information on JOGL and OpenGL 406Summary 407Touring the World 409Application Details 409Constructing the Canvas 411The Camera Position 412Responding to Key Presses 413Let the Rendering Commence 416Rendering Initialization 417Loading Textures 418Lighting the Scene 419Creating the Ground Shapes 420The Rendering Loop 421Updating the Game 421Rendering the Scene 423Drawing the Tree Billboard 423Drawing the Ground Shapes 426The Planet Earth 428The Skybox 430Adding a 2D Overlay 433Drawing the Floor 435Drawing the Tiles 435Drawing the Axes 437Summary 438Loading Models 439Overviews of the Examples 439The OBJ File Format 442Shape Statements 442Grouping Statements 443Material Use Statements 443The MTL File Format 443The OBJ File Loader 444Reading in the OBJ File 446Reading a Face 447Reading in an MTL File 449Recording Material Use 450Centering and Resizing a Model 451Creating a Display List for the Model 452Finding a Material 452Rendering with a Material 453Rendering a Face 455Drawing a Model 457When to Create the Display List 457Viewing a Model 457Loading the Model 458Drawing the Model 459Other JOGL Model Loaders 459The TourModelsGL Appiication 460Adding Models 461Let's Be Picky 463Gleem: A Different Way of Picking 469A Singing Penguin 470The Fog Descends 471Summary 473Index 475