*Game Programming Theory* in C++ Long Table of Contents

## Chapter 0 A Math Review and C++ Class Design 1

Basic Math Review 4

Vectors 7

C++ Object Oriented Programming, an Introduction to Classes 8

Class Syntax 9

The Three Access Qualifiers 10

Constructors and Destructors 11

The Implementation File 12

Adding Member Functions 14

Creating and Using Class Instances 15

Back to Vectors and the Creation of a Vector Class 16

Additional Vector Operations 17

Adding and Subtracting Vectors 19

Multiplication and Division by a Scalar 20

The Vector Dot Product, Cross Product, and Triple Scalar Product 21

Handling Rotations in 2D and the I/O of Vectors 22

## Chapter 1 Chasing, Evading, Intercepting, and Patterned Movement 24

The Sample Programs and Model Coding 25

Chasing and Evading 26

The Screen Class 28

Implementing the Basic Chase Algorithm 31

The Line of Sight Algorithm 33

The Complexity of Line of Sight in a Continuous Environment 38

Vectors 40

Conversion from Global Coordinates to Local Coordinates 41

Line of Sight in a Continuous Environment 43

Intercepting 45

Patterned Movement 47

Patterned Movement in a Continuous Environment 54

Problems 55

## Chapter 2 Basic Physics 56

The Units of Measurement 56

Newton’s Laws of Motion 58

Dealing with Forces 67

Global Versus Local Coordinates 68

Tensors 68

Kinematics: a Study of Motions 69

Non-constant Acceleration: Drag Forces 70

Firing Guns, Rockets, and Related Projectiles in 2D Space 70

Particle Motions in 3D Space 72

Rigid Body Motions in 3D Space 74

Problems 77

## Chapter 3 Force and Kinetics 78

Gravity 79

The Effects of Friction 80

Fluid Dynamic Drag Forces 81

Pressure 82

Buoyancy 82

Springs and Dampers 83

Torque 84

Kinetics: Putting the Pieces Together 86

The Destroyer Example 87

The Complete Cannon 3D Space Example 89

Motions of Rigid Bodies 95

Problems 97

## Chapter 4 A Rigid Body 2D Simulator 98

Setting Up the Rigid Body Class 98

Integration of Equations of Motion 103

Euler’s Method 104

Implementing Euler’s Method 105

Pgm04a Illustrates Euler’s Method 108

Improvements in the Integration Method 111

Rigid Body 2D Simulators 114

Programming Problems 114

## Chapter 5 Flocking and Potential Function-Based Movement 115

Flocking 116

How are these rules combined into a whole package? 117

Implementing the Flocking Algorithm in a Continuous Environment (Pgm05a) 118

Alternate Method for Movement: Potential Function-Based Movement 127

Programming Problems 129

## Chapter 6 Pathfinding Algorithms 130

Dealing with Obstacles 131

Tracing a Path Around Obstacles 132

Picking Up and Following a Trail and Following a Road 144

Node Navigation 155

The A* Pathfinding Algorithm 156

Programming Problems 167

## Chapter 7 Scripting and Finite State Machines 168

A Scripting Ini-like File 168

Scripts Controlling Game Action 181

Finite State Machines 184

Programming Problems 195

## Chapter 8 All About Projectiles, Cars, and Boats 196

Case 1: Launching and Landing Points Are at the Same Height 198

Case 2: Launching Point Is Higher Than the Landing Point 199

Case 3: Launching Point Is Lower Than the Landing Point 200

Case 4: Projectile Is Dropped From a Plane 201

The Impact of Drag on Projectile Motion 202

Drag and Terminal Velocities 204

The Robbins Effect (Magnus Effect) 205

Self-propelled Rockets 206

All About Cars 207

Resistance to Motion 207

Power to Overcome the Total Rolling Resistance 208

Distance Required to Stop a Car 209

Banking of Curves 210

All About Boats 211

Calculating a Ship’s Resistance 212

The Virtual Mass of a Ship 213

Calculating the Volume of a Ship’s Hull 214

Problems 219

## Chapter 9 Writing an Airplane Simulator 220

Flying the Plane 223

Constructing the Plane Model 224

Matrix Algebra 229

Matrix Math Operations Summary 230

Mathematical Theorems of Determinants 232

Constructing a Matrix Class for Game Simulations 233

The Plane Classes Thus Far 239

Dealing with Rotations in 3D Space 248

Rotation Matrices 248

Quaternions 250

The Quaternion Class 251

Building the Rigid Body 3D Plane Simulator 257

Problems 267

## Chapter 10 Fuzzy Logic and Probability 268

Fuzzy Logic 269

The Fuzzification Process 270

Fuzzy Logic Rules 274

Defuzzification Rules 275

A Practical Example: Pgm10a 277

Probability Theory 289

Theory of Probability 291

A Summary of the Rules of Probability 292

Programming Problems 293

## Chapter 11 All About Collisions 294

Detecting a Collision in 3D 294

Collision Response 298

Impact 299

The Equations for Linear and Angular Impulse 301

Pgm11b Illustrates Both Linear and Angular Collision 304

Programming Problems 318

## Chapter 12 Repeatable, Random Terrain Generation 319

The Basic Algorithm 319

Smoothing by Averaging 323

Smoothing by Using the Corner Points 325

Fault Line Landscape Generation 327

Handling Location within a World 332

Putting It All Together, Pgm12b 335

Programming Problems 347