1、TEAMFLY Team-Fly 3D Math Primer forGraphics and GameDevelopmentFletcher Dunnand Ian ParberryWordware Publishing,Inc.Library of Congress Cataloging-in-Publication DataDunn,Fletcher.3D math primer for graphics and game development/by Fletcher Dunn and Ian Parberry.p.cm.ISBN 1-55622-911-91.Computer gra
2、phics.2.Computer games-Programming.3.Computer science-Mathematics.I.Parberry,Ian.II.Title.T385.D8752002006.6-dc212002004615CIP 2002,Wordware Publishing,Inc.All Rights Reserved2320 Los Rios BoulevardPlano,Texas 75074No part of this book may be reproduced in any form or byany means without permission
3、in writing fromWordware Publishing,Inc.Printed in the United States of AmericaISBN 1-55622-911-910 9 8 7 6 5 4 3 2 10205Product names mentioned are used for identification purposes only and may be trademarks of their respective companies.All inquiries for volume purchases of this book should be addr
4、essed to Wordware Publishing,Inc.,at the aboveaddress.Telephone inquiries may be made by calling:(972)423-0090ContentsAcknowledgments.xiChapter 1Introduction.11.1 What is 3D Math?.11.2 Why You Should Read This Book.11.3 What You Should Know Before Reading This Book.31.4 Overview.3Chapter 2The Cartes
5、ian Coordinate System.52.1 1D Mathematics.62.2 2D Cartesian Mathematics.92.2.1 An Example:The Hypothetical City of Cartesia.92.2.2 Arbitrary 2D Coordinate Spaces.102.2.3 Specifying Locations in 2D Using Cartesian Coordinates.132.3 From 2D to 3D.142.3.1 Extra Dimension,Extra Axis.152.3.2 Specifying L
6、ocations in 3D.152.3.3 Left-handed vs.Right-handed Coordinate Spaces.162.3.4 Some Important Conventions Used in This Book.192.4 Exercises.20Chapter 3Multiple Coordinate Spaces.233.1 Why Multiple Coordinate Spaces?.243.2 Some Useful Coordinate Spaces.253.2.1 World Space.253.2.2 Object Space.263.2.3 C
7、amera Space.273.2.4 Inertial Space.283.3 Nested Coordinate Spaces.303.4 Specifying Coordinate Spaces.313.5 Coordinate Space Transformations.313.6 Exercises.34Chapter 4Vectors.354.1 Vector A Mathematical Definition.364.1.1 Vectors vs.Scalars.364.1.2 Vector Dimension.364.1.3 Notation.364.2 Vector A Ge
8、ometric Definition.37iii4.2.1 What Does a Vector Look Like?.374.2.2 Position vs.Displacement.384.2.3 Specifying Vectors.384.2.4 Vectors as a Sequence of Displacements.394.3 Vectors vs.Points.404.3.1 Relative Position.414.3.2 The Relationship Between Points and Vectors.414.4 Exercises.42Chapter 5Oper
9、ations on Vectors.455.1 Linear Algebra vs.What We Need.465.2 Typeface Conventions.465.3 The Zero Vector.475.4 Negating a Vector.485.4.1 Official Linear Algebra Rules.485.4.2 Geometric Interpretation.485.5 Vector Magnitude(Length).495.5.1 Official Linear Algebra Rules.495.5.2 Geometric Interpretation
10、.505.6 Vector Multiplication by a Scalar.515.6.1 Official Linear Algebra Rules.515.6.2 Geometric Interpretation.525.7 Normalized Vectors.535.7.1 Official Linear Algebra Rules.535.7.2 Geometric Interpretation.535.8 Vector Addition and Subtraction.545.8.1 Official Linear Algebra Rules.545.8.2 Geometri
11、c Interpretation.555.8.3 Vector from One Point to Another.575.9 The Distance Formula.575.10 Vector Dot Product.585.10.1 Official Linear Algebra Rules.585.10.2 Geometric Interpretation.595.10.3 Projecting One Vector onto Another.615.11 Vector Cross Product.625.11.1 Official Linear Algebra Rules.625.1
12、1.2 Geometric Interpretation.625.12 Linear Algebra Identities.655.13 Exercises.67Chapter 6A Simple 3D Vector Class.696.1 Class Interface.696.2 Class Vector3 Definition.706.3 Design Decisions.736.3.1 Floats vs.Doubles.736.3.2 Operator Overloading.73ivContents6.3.3 Provide Only the Most Important Oper
13、ations.746.3.4 Dont Overload Too Many Operators.746.3.5 Use Const Member Functions.756.3.6 Use Const&Arguments.756.3.7 Member vs.Nonmember Functions.756.3.8 No Default Initialization.776.3.9 Dont Use Virtual Functions.776.3.10 Dont Use Information Hiding.776.3.11 Global Zero Vector Constant.786.3.12
14、 No“point3”Class.786.3.13 A Word on Optimization.78Chapter 7Introduction to Matrices.837.1 Matrix A Mathematical Definition.837.1.1 Matrix Dimensions and Notation.837.1.2 Square Matrices.847.1.3 Vectors as Matrices.857.1.4 Transposition.857.1.5 Multiplying a Matrix with a Scalar.867.1.6 Multiplying
15、Two Matrices.867.1.7 Multiplying a Vector and a Matrix.897.1.8 Row vs.Column Vectors.907.2 Matrix A Geometric Interpretation.917.2.1 How Does a Matrix Transform Vectors?.927.2.2 What Does a Matrix Look Like?.937.2.3 Summary.977.3 Exercises.98Chapter 8Matrices and Linear Transformations.1018.1 Transf
16、orming an Object vs.Transforming the Coordinate Space.1028.2 Rotation.1058.2.1 Rotation in 2D.1058.2.2 3D Rotation about Cardinal Axes.1068.2.3 3D Rotation about an Arbitrary Axis.1098.3 Scale.1128.3.1 Scaling along Cardinal Axes.1128.3.2 Scale in an Arbitrary Direction.1138.4 Orthographic Projection.1158.4.1 Projecting onto a Cardinal Axis or Plane.1168.4.2 Projecting onto an Arbitrary Line or Plane.1178.5 Reflection.1178.6 Shearing.1188.7 Combining Transformations.1198.8 Classes of Transformat