Tải bản đầy đủ (.pdf) (711 trang)

essential mathematics for games & interactive applications

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (10.51 MB, 711 trang )


This excellent volume is unique in that it covers not only the basic techniques of com-
puter graphics and game development, but also provides a thorough and rigorous—yet
very readable—treatment of the underlying mathematics. Fledgling graphics and
games developers will find it a valuable introduction; experienced developers will find
it an invaluable reference. Everything is here, from the detailed numeric issues of
IEEE floating point notation, to the correct way to use quaternions and spherical lin-
ear interpolation to represent orientation, to the mathematics of collision detection
and rigid-body dynamics.
—David Luebke, University of Virginia,
co-author of Level of Detail for 3D Graphics
When it comes to software development for games or virtual reality, you cannot
escape the mathematics. The best performance comes not from superfast proces-
sors and terabytes of memory, but from well-chosen algorithms. With this in mind,
the techniques most useful for developing production-quality computer graphics for
Hollywood blockbusters are not the best choice for interactive applications. When
rendering times are measured in milliseconds rather than hours, you need an entirely
different perspective.
Essential Mathematics for Games and Interactive Applications provides this per-
spective. While the mathematics are rigorous and perhaps challenging at times, Van
Verth and Bishop provide the context for understanding the algorithms and data struc-
tures needed to bring games and VR applications to life. This may not be the only book
you will ever need for games and VR software development, but it will certainly provide
an excellent framework for developing robust and fast applications.
—Ian Ashdown, President, ByHeart Consultants Limited
With Essential Mathematics for Games and Interactive Applications, Van Verth and
Bishop have provided invaluable assistance for professional game developers looking
to shore up weaknesses in their mathematical training. Even if you never intend to
write a renderer or tune a physics engine, this book provides the mathematical and
conceptual grounding needed to understand many of the key concepts in rendering,


simulation, and animation.
—Dave Weinstein, Microsoft, Red Storm Entertainment
Geometry, trigonometry, linear algebra, and calculus are all essential tools for
3D graphics. Mathematics courses in these subjects cover too much ground, while at
the same time glossing over the bread-and-butter essentials for 3D graphics program-
mers. In Essential Mathematics for Games and Interactive Applications, Van Verth and
Bishop bring just the right level of mathematics out of the trenches of professional
game development. This book provides an accessible and solid mathematical founda-
tion for interactive graphics programmers. If you are working in the area of 3D games,
this book is a “must have.”
—Jonathan Cohen, Department of Computer Science,
Johns Hopkins University,
co-author of Level of Detail for 3D Graphics
Essential Mathematics
for Games and
Interactive Applications
A Programmer’s Guide
The Morgan Kaufmann Series in
Interactive 3D Technology
Series Editor: David H. Eberly, Magic Software, Inc.
The game industry is a powerful and driving force in the evolution of computer
technology. As the capabilities of personal computers, peripheral hardware,
and game consoles have grown, so has the demand for quality information
about the algorithms, tools, and descriptions needed to take advantage of this
new technology. We plan to satisfy this demand and establish a new level
of professional reference for the game developer with the Morgan Kaufmann
Series in Interactive 3D Technology. Books in the series are written for devel-
opers by leading industry professionals and academic researchers, and cover
the state of the art in real-time 3D. The series emphasizes practical, work-
ing solutions and solid software-engineering principles. The goal is for the

developer to be able to implement real systems from the fundamental ideas,
whether it be for games or for other applications.
Essential Mathematics for Games and Interactive Applications:
A Programmer’s Guide
James M. Van Verth and Lars M. Bishop
Game Physics
David H. Eberly
Collision Detection in Interactive 3D Environments
Gino van den Bergen
3D Game Engine Design:
A Practical Approach to Real-Time Computer Graphics
David H. Eberly
Forthcoming
Physically Based Rendering
Matt Pharr and Greg Humphreys
Real-Time Collision Detection
Christer Ericson
Essential Mathematics
for Games and
Interactive Applications
A Programmer’s Guide
James M. Van Verth
Red Storm Entertainment
Lars M. Bishop
Numerical Design Limited
Amsterdam Boston Heidelberg
London New York Oxford
Paris San Diego San Francisco
Singapore Sydney Tokyo
Morgan Kaufmann Publishers is an imprint of Elsevier

Senior Editor Tim Cox
Publishing Services Manager Simon Crump
Production Editor Troy Lilly
Editorial Assistant Richard Camp
Cover Design Chen Design Associates
Text Design Julio Esperas
Composition Cepha Imaging Pvt. Ltd.
Technical Illustration Dartmouth Publishing, Inc.
Copyeditor Yonie Overton
Proofreader John Bregoli
Indexer Northwind Editorial Services
Interior printer The Maple-Vail Book Manufacturing Group
Cover printer Phoenix Color Corp.
Morgan Kaufmann Publishers is an imprint of Elsevier.
500 Sansome Street, Suite 400, San Francisco, CA 94111
This book is printed on acid-free paper.
© 2004 by Elsevier Inc. All rights reserved.
Designations used by companies to distinguish their products are often claimed as trade-
marks or registered trademarks. In all instances in which Morgan Kaufmann Publishers is
aware of a claim, the product names appear in initial capital or all capital letters. Readers,
however, should contact the appropriate companies for more complete information regard-
ing trademarks and registration.
No part of this publication may be reproduced, stored in a retrieval system, or transmit-
ted in any form or by any means—electronic, mechanical, photocopying, scanning, or
otherwise—without prior written permission of the publisher.
Permissions may be sought directly from Elsevier’s Science & Technology Rights
Department in Oxford, UK: phone: (+44) 1865 843830, fax: (+44) 1865 853333,
e-mail: You may also complete your request on-line via the
Elsevier homepage () by selecting “Customer Support” and then “Obtain-
ing Permissions.”

Library of Congress Cataloging-in-Publication Data
Van Verth, James M.
Essential mathematics for games and interactive applications : a programmer’s guide /
James M. Van Verth and Lars M. Bishop.
p. cm. – (The Morgan Kaufmann series in interactive 3D technology)
Includes bibliographical references and index.
ISBN-13: 978-1-55860-863-4 ISBN-10: 1-55860-863-X (hardcover : alk. paper)
1. Computer games–Programming. 2. Three-dimensional display systems–Mathematics.
I. Bishop, Lars M. II. Title. III. Series.
QA76.76.C672V47 2004
794.8

1711–dc22
2003028267
ISBN-13: 978-1-55860-863-4
ISBN-10: 1-55860-863-X
For information on all Morgan Kaufmann publications,
visit our Web site at www.mkp.com.
Printed in the United States of America
05060708 5432
Dedications
To Harry, Mur, and Fiona: my past, present, and future. —Jim
To Dad and Mom (Steve and Helene Bishop); your love and support have
always been by my side. Thank you. —Lars

About the Authors
James M. Van Verth is a founding member of Red Storm Entertainment, a
division of Ubisoft, where he has been a lead engineer for six years. For the
past five years he also has been a regular speaker at the Game Developers
Conference, teaching the all-day tutorial, “Essential Math for Programmers,”

on which this book is based. He began his game industry career at Virtus
Corporation, working as a sound and graphics engineer for the title Tom
Clancy: SSN. His first position at Red Storm was as project lead and designer
of Tom Clancy’s Politika, the first commercial Java game. This was followed
by the land warfare game Force 21 where he acted as lead engineer, focusing
on 3D graphics, vehicle physics, and pathfinding. His latest role at Red Storm
is as rendering technology lead for a well-known squad combat franchise.
His background includes a B.A. in mathematics and computer science from
Dartmouth College, an M.S. in computer science from the State University of
New York at Buffalo, and an M.S. in computer science from the University of
North Carolina at Chapel Hill. This is his first book.
Lars M. Bishop is the Chief Technology Officer for Numerical Design Limited
(NDL). Since 1996, he has specialized in real-time 3D game rendering tech-
nologies at NDL. He was a founding member of the team that created NDL’s
popular NetImmerse and Gamebryo 3D game engines, which are used in over
50 games, such as Bethesda Softworks’ Morrowind and Mythic Entertain-
ment’s Dark Age of Camelot. Lars is currently working on the development of
next-generation NDL products, specifically 3D engines and tools for handheld
devices. He holds a B.S. in mathematics and computer science from Brown
University and an M.S. in computer science from the University of North
Carolina at Chapel Hill.
vii

Contents
Preface xxi
Introduction 1
The (Continued) Rise of 3D Games 1
How to Read this Book 2
Part I, Core Mathematics 2
Part II, Rendering 3

Part III, Animation 4
Part IV, Simulation 4
Appendices 4
Interactive Demo Applications 5
Support Libraries 5
Math Libraries 6
Engine and Rendering Libraries 6
References and Further Reading 7
Part I
Core Mathematics
Chapter 1
Vectors and Points 11
1.1 Introduction 11
1.2
Vectors 12
1.2.1
Vectors as Geometry 12
1.2.2
Real Vector Spaces 15
1.2.3
Linear Combinations and Basis Vectors 18
1.2.4
Basic Vector Class Implementation 22
ix
x Contents
1.2.5 Vector Length 25
1.2.6 Dot Product 28
1.2.7
Gram-Schmidt Orthogonalization 33
1.2.8 Cross Product 34

1.2.9 Triple Products 37
1.3 Points 41
1.3.1 Points as Geometry 41
1.3.2 Affine Spaces 43
1.3.3 Affine Combinations 46
1.3.4 Point Implementation 47
1.3.5 Polar and Spherical Coordinates 49
1.4 Lines 52
1.4.1 Definition 52
1.4.2 Parameterized Lines 53
1.4.3 Generalized Line Equation 55
1.4.4 Collinear Points 57
1.5 Planes 57
1.5.1 Parameterized Planes 57
1.5.2 Generalized Plane Equation 58
1.5.3
Coplanar Points 60
1.6 Polygons and Triangles 60
1.7 Chapter Summary 63
Chapter 2
Linear Transformations and Matrices 65
2.1 Introduction 65
2.2 Linear Transformations 66
2.2.1 Definitions 66
2.2.2 Null Space and Range 67
2.2.3
Linear Transformations and Basis Vectors 69
2.3
Matrices 71
2.3.1

Introduction to Matrices 71
2.3.2 Simple Operations 73
2.3.3 Vector Representation 75
2.3.4
Block Matrices 75
2.3.5 Matrix Product 77
2.3.6 Transforming Vectors 79
Contents xi
2.3.7 Combining Linear Transformations 81
2.3.8 Identity Matrix 83
2.3.9 Performing Vector Operations with Matrices 84
2.3.10 Implementation 85
2.4 Systems of Linear Equations 88
2.4.1 Definition 88
2.4.2 Solving Linear Systems 89
2.4.3 Gaussian Elimination 91
2.5 Matrix Inverse 95
2.5.1 Definition 95
2.5.2 Simple Inverses 97
2.6
The Determinant 99
2.6.1 Definition 99
2.6.2 Computing the Determinant 100
2.6.3 Determinants and Elementary Row Operations 103
2.6.4 Adjoint Matrix and Inverse 105
2.7 Chapter Summary 106
Chapter 3
Affine Transformations 107
3.1 Introduction 107
3.2 Affine Transformations 108

3.2.1 Definition 108
3.2.2 Representation 109
3.3 Standard Affine Transformations 113
3.3.1
Translation 113
3.3.2 Rotation 115
3.3.3 Scaling 124
3.3.4 Reflection 126
3.3.5
Shear 130
3.3.6 Applying an Affine Transformation Around an Arbitrary
Point 132
3.3.7 Transforming Plane Normals 134
3.4 Using Affine Transformations 135
3.4.1 Manipulation of Game Objects 135
3.4.2 Matrix Decomposition 141
3.4.3 Avoiding Matrix Decomposition 143
xii Contents
3.5 Object Hierarchies and Scene Graphs 145
3.5.1 Object Hierarchies 145
3.5.2 Scene Graphs 148
3.6 Chapter Summary 153
Chapter 4
Real-World Computer Number Representation 155
4.1 Introduction 155
4.2 Representing Integral Types on a Computer 156
4.2.1 Finiteness of Representation 156
4.2.2 Range 156
4.3
Representing Real Numbers 159

4.3.1 Approximations 160
4.3.2 Precision and Error 160
4.4 Fixed Point 162
4.4.1 Introduction 162
4.4.2 Basic Representation 162
4.4.3 Range and Precision 163
4.4.4 Addition and Subtraction 166
4.4.5 Multiplication 166
4.4.6
Division 168
4.4.7 Real-World Fixed Point 169
4.4.8 Intermediate Value Overflow and Underflow 170
4.4.9 Limits of Fixed Point 173
4.4.10 Fixed Point Summary 173
4.5 Floating-Point Numbers 173
4.5.1 Review: Scientific Notation 173
4.5.2
A Restricted Scientific Notation 174
4.6 Binary “Scientific Notation” 176
4.7 IEEE 754 Floating Point Standard 177
4.7.1 Basic Representation 177
4.7.2 Range and Precision 179
4.7.3
Arithmetic Operations 181
4.7.4
Special Values 184
4.7.5 Very Small Values 188
4.7.6 Catastrophic Cancellation 190
4.7.7 Double Precision 192
Contents xiii

4.8 Real-World Floating Point 193
4.8.1 Internal FPU Precision 193
4.8.2 Performance 194
4.8.3 IEEE Specification Compliance 197
4.9 Code 198
4.10 Chapter Summary 199
Part II
RENDERING
Chapter 5
Viewing and Projection 203
5.1 Introduction 203
5.2 The View Frame and View Transformation 204
5.2.1 Defining a Virtual Camera 204
5.2.2 Controlling the Camera 207
5.2.3 Constructing the View Transformation 210
5.3 Projective Transformation 211
5.3.1 Definition 211
5.3.2 The View Frustum 215
5.3.3
Normalized Device Coordinates 217
5.3.4 Homogeneous Coordinates 219
5.3.5 Perspective Projection 220
5.3.6 Oblique Perspective 227
5.3.7 Orthographic Parallel Projection 229
5.3.8 Oblique Parallel Projection 231
5.4 Culling and Clipping 233
5.4.1 Why Cull or Clip? 233
5.4.2 Culling 237
5.4.3 General Plane Clipping 238
5.4.4 Homogeneous Clipping 243

5.5 Screen Transformation 245
5.6 Picking 248
5.7
Management of Viewing Transformations 250
5.8 Chapter Summary 253
xiv Contents
Chapter 6
Geometry, Shading, and Texturing 255
6.1 Introduction 255
6.2 Color Representation 256
6.2.1 The RGB Color Model 256
6.2.2 Colors as “Vectors” 257
6.2.3 Operations on Colors 258
6.2.4 Color Range Limitation 259
6.2.5 Alpha Values 261
6.2.6
Color Storage Formats 262
6.2.7 Colors in OpenGL 263
6.3 Points and Vertices 264
6.3.1 Per-Vertex Attributes 265
6.4 Surface Representation 266
6.4.1
Vertices and Surface Ambiguity 267
6.4.2 Triangles 268
6.4.3 Triangle Attributes 269
6.4.4 Vertex Indices 272
6.4.5
OpenGL Vertex Indices 274
6.5 Coloring a Surface 276
6.6 Using Constant Colors 276

6.6.1 Per-Object Colors 277
6.6.2 Per-Triangle Colors 277
6.6.3
Per-Vertex Colors 278
6.6.4 Limitations of Basic Shading
Methods 283
6.7 Texture Mapping 284
6.7.1 Introduction 284
6.7.2
Shading via Image Lookup 285
6.7.3 Texture Images 285
6.8
Texture Coordinates 289
6.8.1 Mapping Texture Coordinates 292
6.8.2
Generating Texture Coordinates 293
6.8.3
Texture Coordinate Discontinuities 294
6.8.4 Mapping Outside the Unit Square 296
6.9 Reviewing the Steps of Texturing 301
6.10 Limitations of Texturing 303
Contents xv
6.11 Procedural Colors and Shaders 304
6.12 Chapter Summary 307
Chapter 7
Lighting 309
7.1
Introduction 309
7.2 Basics of Light Approximation 310
7.2.1 Measuring Light 310

7.2.2 Light as a Ray 312
7.3 Lighting Approximation (OpenGL) 312
7.4 Types of Light Sources 313
7.4.1 Directional Lights 314
7.4.2 Point Lights 315
7.4.3 Spotlights 318
7.4.4 Other Types of Light Sources 322
7.5 Surface Materials and Light Interaction 323
7.5.1 OpenGL Materials 323
7.6 Categories of Light 324
7.6.1 Emission 324
7.6.2 Ambient 325
7.6.3 Diffuse 327
7.6.4 Specular 330
7.7 Combined Lighting Equation 335
7.8 Lighting and Shading 338
7.8.1 Flat-Shaded Lighting 338
7.8.2 Per-Vertex Lighting 340
7.8.3 Per-Pixel Lighting (Phong Shading) 344
7.9 Merging Textures and Lighting 348
7.9.1 Specular Lighting and Textures 349
7.10 Lighting and Programmable Shaders 351
7.11 Chapter Summary 351
Chapter 8
Rasterization 353
8.1 Introduction 353
8.2 Displays and Framebuffers 355
8.2.1 Framebuffer Memory Organization 356
xvi Contents
8.2.2 Interlacing 357

8.2.3 Multiple Buffers 358
8.3 Conceptual Rasterization Pipeline 360
8.4 Determining the Pixels Contained by a Triangle 360
8.5 Determining Which Pixels are Visible 362
8.5.1 Depth Sorting 362
8.5.2 Depth Buffering 365
8.5.3
Depth Buffering in OpenGL 374
8.6 Computing Source Pixel Colors 375
8.6.1 Flat Colors 375
8.6.2 Gouraud Colors 376
8.7
Rasterizing Textures 378
8.7.1 Texture Coordinate Review 379
8.7.2
Interpolating Texture Coordinates 380
8.7.3 Mapping a Coordinate to a Texel 383
8.7.4 Mipmapping 391
8.8 Blending 401
8.8.1 Blending and Z-Buffering 403
8.8.2 Alternative Blending Modes 404
8.8.3 Blending and OpenGL 405
8.9 Antialiasing 406
8.9.1 Antialiasing in Practice 412
8.9.2
Antialiasing in OpenGL 414
8.10 Chapter Summary 416
Part III
Animation
Chapter 9

Curves 419
9.1 Introduction 419
9.2 General Definitions 421
9.3 Linear Interpolation 422
9.3.1 Definition 422
9.3.2 Piecewise Linear Interpolation 424
9.4
Lagrange Polynomials 425
Contents xvii
9.5 Hermite Curves 427
9.5.1 Definition 427
9.5.2 Automatic Generation of Hermite Curves 433
9.5.3 Natural, Cyclic, and Acyclic End Conditions 435
9.6 Catmull-Rom Splines 438
9.7 Bézier Curves 440
9.7.1 Definition 440
9.7.2 Piecewise Bézier Curves 443
9.8 B-Splines 444
9.9 Rational Curves 448
9.10 Rendering Curves 450
9.10.1 Forward Differencing 450
9.10.2 Midpoint Subdivision 453
9.10.3 Using OpenGL 456
9.11 Controlling Speed Along a Curve 459
9.11.1 Moving at Constant Speed 459
9.11.2 Computing Arc Length 462
9.11.3 Ease-In and Ease-Out 465
9.12 Camera Control 467
9.13 Chapter Summary 470
Chapter 10

Orientation Representation 471
10.1 Introduction 471
10.2 Rotation Matrices 473
10.3 Fixed and Euler Angles 474
10.3.1 Definition 474
10.3.2 Format Conversion 476
10.3.3 Concatenation 478
10.3.4
Vector Rotation 478
10.3.5 Other Issues 479
10.4
Axis-Angle Representation 481
10.4.1 Definition 481
10.4.2 Format Conversion 482
10.4.3 Concatenation 484
10.4.4
Vector Rotation 484
10.4.5 Section Summary 485
xviii Contents
10.5 Quaternions 485
10.5.1 Definition 485
10.5.2 Rotation Quaternions 486
10.5.3 Format Conversion 489
10.5.4 Addition and Scalar Multiplication 493
10.5.5 Negation 493
10.5.6 Magnitude and Normalization 493
10.5.7 Dot Product 494
10.5.8 Concatenation 495
10.5.9 Identity and Inverse 497
10.5.10 Vector Rotation 498

10.5.11 Quaternions and Transformations 501
10.6 Interpolation 501
10.6.1 Linear Interpolation 503
10.6.2 Spherical Linear Interpolation 507
10.6.3 Performance Improvements 510
10.7 Chapter Summary 511
Part IV
Simulation
Chapter 11
Intersection Testing 515
11.1 Introduction 515
11.2 Closest Point and Distance Tests 516
11.2.1 Closest Point on Line to Point 516
11.2.2 Line-Point Distance 518
11.2.3 Closest Point on Line Segment to Point 519
11.2.4 Line Segment–Point Distance 520
11.2.5 Closest Points between Two Lines 522
11.2.6 Line-Line Distance 524
11.2.7
Closest Points between Two Line Segments 525
11.2.8 Line Segment–Line Segment Distance 527
11.2.9 General Linear Components 527
11.3
Object Intersection 528
11.3.1 Spheres 530
11.3.2 Axis-Aligned Bounding Boxes 538
Contents xix
11.3.3 Swept Spheres 546
11.3.4 Object-Oriented Boxes 550
11.3.5 Triangles 556

11.4 A Simple Collision System 562
11.4.1 Choosing a Base Primitive 562
11.4.2 Bounding Hierarchies 563
11.4.3 Dynamic Objects 568
11.4.4 Performance Improvements 569
11.4.5 Related Systems 572
11.4.6 Section Summary 575
11.5 Chapter Summary 575
Chapter 12
Rigid Body Dynamics 577
12.1 Introduction 577
12.2 Linear Dynamics 578
12.2.1 Moving with Constant Acceleration 578
12.2.2 Forces 581
12.2.3
Linear Momentum 582
12.2.4 Moving with Variable Acceleration 582
12.3 Initial Value Problems 585
12.3.1 Definition 585
12.3.2 Euler’s Method 587
12.3.3 Midpoint Method 590
12.3.4 Higher-Order Methods 593
12.3.5 Verlet Integration 594
12.3.6 Implicit Methods 596
12.4 Rotational Dynamics 599
12.4.1 Definitions 599
12.4.2 Orientation and Angular Velocity 599
12.4.3
Torque 600
12.4.4 Angular Momentum and Inertial Tensor 603

12.4.5 Integrating Rotational Quantities 605
12.5 Collision Response 607
12.5.1 Locating the Point of Collision 607
12.5.2
Linear Collision Response 611
12.5.3 Rotational Collision Response 616
12.5.4 Other Response Techniques 619
xx Contents
12.6 Efficiency 620
12.7 Chapter Summary 621
Appendix A
Trigonometry Review
623
A.1 Basic Definitions 623
A.1.1 Ratios on the Right Triangle 623
A.1.2 Extending to General Angles 624
A.2 Properties of Triangles 626
A.3 Trigonometric Identities 629
A.3.1 Pythagorean Identities 629
A.3.2 Complementary Angle 629
A.3.3 Even-Odd 630
A.3.4 Compound Angle 631
A.3.5 Double Angle 631
A.3.6 Half Angle 632
A.4 Inverses 633
Appendix B
Calculus Review
635
B.1 Limits and Continuity 635
B.1.1 Limits 635

B.1.2 Continuity 637
B.2 Derivatives 638
B.2.1 Definition 638
B.2.2
Basic Derivatives 640
B.2.3 Derivatives of Transcendental Functions 641
B.2.4 Taylor’s Series 643
B.3 Integrals 645
B.3.1 Definition 645
B.3.2 Evaluating Integrals 647
B.3.3 Trapezoidal Rule 648
B.3.4 Gaussian Quadrature 649
B.4 Space Curves 651
Bibliography 655
Index 663
Trademarks 677
About the CD-ROM 678
Preface
Writing a book is an adventure. To begin with, it is a toy and an
amusement; then it becomes a mistress, and then it becomes a master,
and then a tyrant. The last phase is that just as you are about to be
reconciled to your servitude, you kill the monster, and fling him out to
the public. — Sir Winston Churchill
The Adventure Begins
As humorous as Churchill’s statement is, there is a certain amount of truth to
it; writing this book was indeed an adventure. There is something about the
process of writing, particularly a nonfiction work like this, that forces you to
test and expand the limits of your knowledge. We hope that you, the reader,
benefit from our hard work.
How does a book like this come about? Many of Churchill’s books began

with his experience — particularly his experience as a world leader in wartime.
This book had a more mundane beginning: Two engineers at Red Storm,
separately, asked Jim to teach them about vectors. These engineers were 2D
game programmers, and 3D was not new, but was starting to replace 2D
at that point. Jim’s project was in a crunch period, so he didn’t have time
to do much about it until proposals were requested for the annual Game
Developers Conference. Remembering the engineers’ request, he thought back
to the classic “Math for SIGGRAPH” course from SIGGRAPH 1989, which he
had attended and enjoyed. Jim figured that a similar course, at that time
titled “Math for Game Programmers,” could help 2D programmers become
3D programmers.
The course was accepted, and together with a co-speaker, Marcus
Nordenstam, Jim presented it at GDC 2000. The following years (2001–2002)
Jim taught the course alone, as Marcus had moved from the game indus-
try to the film industry. The subject matter changed slightly as well, adding
more advanced material such as curves, collision detection, and basic physical
simulation.
xxi
xxii Preface
It was in 2002 that the seeds of what you hold in your hand were truly
planted. At GDC 2002, another GDC speaker, whose name, alas, is lost to time,
recommended that Jim turn his course into a book. This was an interesting
idea, but how to get it published? As it happened, Jim ran into Dave Eberly at
SIGGRAPH 2002, and he was looking for someone to write just that book for
Morgan Kaufmann. At the same time, Lars was presenting some of the basics
of rendering on handheld devices as part of a SIGGRAPH course. Jim and
Lars discussed the fact that handheld 3D rendering had brought back some
of the “lost arts” of 3D programming, and that this might be included in a
book on mathematics for game programming.
Thus, a co-authorship was formed. Lars joined Jim in teaching the GDC

2003 version of what was now called “Essential Math for Game Program-
mers,” and simultaneously joined Jim to help with the book, helping to expand
the topics covered to include numerical representations. As we began to flesh
out the latter chapters of the outline, Lars was finding that the advent of
programmable shaders on consumer 3D hardware was bringing more and
more low-level lighting, shading, and texturing questions into his office at
NDL. Accordingly, the planned single chapter on “texturing and antialiasing”
became three, covering a wider selection of these rendering topics.
By early 2003, we were furiously typing the first full draft of what is
now before you. The experience was fascinating, sometimes frustrating, but
ultimately deeply rewarding. Hopefully, this fascination and respect for the
material will be conveyed to you, the reader. The topics in this book can each
take a lifetime to study to a truly great depth; we hope you will be convinced
to try just that, nonetheless!
Enjoy as you do so, as one of the few things more rewarding than pro-
gramming and seeing a correctly animated, simulated, and rendered scene on
a screen is the confidence of understanding how and why everything worked.
When something in a 3D system goes wrong (and it always does), the best pro-
grammers are never satisfied with “I fixed it, but I’m not sure how”; without
understanding, there can be no confidence in the solution, and nothing new
is learned. Such programmers are driven by the desire to understand what
went wrong, how to fix it, and learning from the experience. No other tool in
3D programming is quite as important to this process than the mathematical
bases
1
behind it.
Those Who Helped Us Along the Road
In a traditional adventure the protagonists are assisted by various characters
that pass in and out of the pages. Similarly, while this book bears the names
1. Vector or otherwise.

×