Game Programming Gems 3 Edited by Dante Treglia CHARLES R I V E R M E D I A CHARLES RIVER MEDIA, INC. Hingham, Massachusetts
Contents Foreword... xi Preface....... xv Acknowledgments About the Cover Image.. Contributor Bios xix. xxi xxiii SECTION 1 GENERAL PROGRAMMING 1 Introduction. 3 Kim Pallister 1.1 Scheduling Game Events 5 Michael Harvey and Carl Marshall 1.2 An Object-Composition Game Framework 15 Scott Patterson 1.3 Finding Redeeming Value in C-Style Macros 26 Steve Rabin 1.4 Platform-Independent, Function-Binding Code Generator 38 Allen Pouratian 1.5 Handle-Based Smart Pointers 44 Brian Hawkins 1.6 Custom STL Allocators 49 Pete Isensee 1.7 Save Me Now! 59 Martin Brownlow 1.8 Autolists Design Pattern.64 Ben Board v
vi Contents 1.9 Floating-Point Exception Handling 69 Soren Hannibal 1.10 Programming a Game Design-Compliant Engine Using UML 73 Thomas Demachy 1.11 Using Lex and Yacc To Parse Custom Data Files 83 Paul Kelly 1.12 Developing Games for a World Market 92 Aaron Nicholls 1.13 Real-Time Input and Ul in 3D Games 109 Greg Seegert 1.14 Natural Selection: The Evolution of Pie Menus, 117 Don Hopkins 1.15 Lightweight, Policy-Based Logging 129 Brian Hawkins 1.16 Journaling Services 136 Eric Robert 1.17 Real-Time Hierarchical Profiling 146 Greg Hjelstrom and Byon Garrabrant SECTION 2 MATHEMATICS.153 Introduction 155 John Byrd 2.1 Fast Base-2 Functions for Logarithms and Random Number Generation 157 James McNeill 2.2 Using Vector Fractions for Exact Geometry 160 Thomas Young 2.3 More Approximations to Trigonometric Functions 170 Robin Green 2.4 Quaternion Compression 187 Mark Zarb-Adami 2.5 Constrained Inverse Kinematics 192 Jason Weber
Contents vii 2.6 Cellular Automata for Physical Modeling 200 Tom Forsyth 2.7 Coping with Friction in Dynamic Simulations 215 Miguel Gomez SECTION 3 ARTIFICIAL INTELLIGENCE 227 Introduction 229 Steven Woodcock 3.1 Optimized Machine Learning with GoCap 231 Thor Alexander 3.2 Area Navigation: Expanding the Path-Finding Paradigm. 240 Ben Board and Mike Ducker 3.3 Function Pointer-Based, Embedded Finite-State Machines 256 Charles Farris 3.4 Terrain Analysis in an RTS The Hidden Giant 268 Daniel Higgins 3.5 An Extensible Trigger System for Al Agents, Objects, and Quests. 285 Steve Rabin 3.6 Tactical Path-Finding with A* 294 William van der Sterren 3.7 A Fast Approach to Navigation Meshes 307 Stephen White and Christopher Christensen 3.8 Choosing a Relationship Between Path-Finding and Collision 321 Thomas Young SECTION 4 GRAPHICS 333 Introduction 335 Jeff Lander 4.1 T-Junction Elimination and Retriangulation 338 Eric Lengyel 4.2 Fast Heightfield Normal Calculation 344 Jason Shankel
viii - Contents 4.3 Fast Patch Normals 349 Martin Broumlow 4.4 Fast and Simple Occlusion Culling 353 Wagner T. Correa, James T. Klosowski, and Cldudio T Silva 4.5 Triangle Strip Creation, Optimizations, and Rendering 359 Carl S. Marshall 4.6 Computing Optimized Shadow Volumes for Complex Data Sets... 367 Alex Vlachos and Drew Card 4.7 Subdivision Surfaces for Character Animation 372 William Leeson 4.8 Improved Deformation of Bones 384 Jason Weber 4.9 A Framework for Realistic Character Locomotion 394 Thomas Young 4.10 A Programmable Vertex Shader Compiler 404 Adam Lake 4.11 Billboard Beams 413 Brian Hawkins 4.12 3D Tricks for Isometric Engines 417 Greg Snook 4.13 Curvature Simulation Using Normal Maps 424 Oscar Blasco 4.14 Methods for Dynamic, Photorealistic Terrain Lighting 433 Naty Hojfman and Kenny Mitchell 4.15 Cube Map Lighting Techniques. 444 Kenneth L. Hurley 4.16 Procedural Texturing. 452 Mike Milliger 4.17 Unique Textures 459 Tom Forsyth 4.18 Textures as Lookup Tables for Per-Pixel Lighting Computations... 467 Alex Vlachos, John Isidoro, and Chris Oat 4.19 Rendering with Handcrafted Shading Models 477 Jan Kautz
Contents ix SECTION 5 NETWORK AND MULTIPLAYER 485 Introduction 487 Andrew Kirmse 5.1 Minimizing Latency in Real-Time Strategy Games 488 Jim Greer and Zachary Booth Simpson 5.2 Real-Time Strategy Network Protocol 496 Jan Svarovsky 5.3 A Flexible Simulation Architecture for Massively Multiplayer Games 506 Thor Alexander 5.4 Scaling Multiplayer Servers 520 Justin Randall 5.5 Template-Based Object Serialization 534 Jason Beardsley 5.6 Secure Sockets. 546 Pete Isensee 5.7 A Network Monitoring and Simulation Tool 557 Andrew Kirmse 5.8 Creating Multiplayer Games with DirectPlay 3.1 561 Gabriel Rohweder 5.9 Wireless Gaming Using the Java Micro Edition 573 David Fox SECTION 6 AUDIO 583 Introduction 585 Scott Patterson 6.1 Audio Compression with Ogg Vorbis 537 Jack Moffitt 6.2 Creating a Compelling 3D Audio Environment 595 Garin Hiebert 6.3 Obstruction Using Axis-Aligned Bounding Boxes 600 Carlo Vogelsang
x Contents 6.4 Using the Biquad Resonant Filter 606 PhilBurk 6.5 Linear Predictive Coding for Voice Compression and Effects 613 Eddie Edwards 6.6 The Stochastic Synthesis of Complex Sounds 622 PhilBurk 6.7 Real-Time Modular Audio Processing for Games 630 Frank Luchs Appendix: About the CD-ROM 639