1. Trang chủ
  2. » Tất cả

3D Math Primer for Graphics and Game Development

449 4 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 449
Dung lượng 22,15 MB

Nội dung

TE AM FL Y 3D Math Primer for Graphics and Game Development Fletcher Dunn and Ian Parberry Wordware Publishing, Inc Library of Congress Cataloging-in-Publication Data Dunn, Fletcher 3D math primer for graphics and game development / by Fletcher Dunn and Ian Parberry p cm ISBN 1-55622-911-9 Computer graphics Computer games Programming Computer science Mathematics I Parberry, Ian II Title T385 D875 2002 006.6 dc21 2002004615 CIP © 2002, Wordware Publishing, Inc All Rights Reserved 2320 Los Rios Boulevard Plano, Texas 75074 No part of this book may be reproduced in any form or by any means without permission in writing from Wordware Publishing, Inc Printed in the United States of America ISBN 1-55622-911-9 10 0205 Product 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 addressed to Wordware Publishing, Inc., at the above address Telephone inquiries may be made by calling: (972) 423-0090 Contents Acknowledgments xi Chapter Introduction 1.1 What is 3D Math? 1.2 Why You Should Read This Book 1.3 What You Should Know Before Reading This Book 1.4 Overview 1 3 Chapter The Cartesian Coordinate System 2.1 1D Mathematics 2.2 2D Cartesian Mathematics 2.2.1 An Example: The Hypothetical City of Cartesia 2.2.2 Arbitrary 2D Coordinate Spaces 10 2.2.3 Specifying Locations in 2D Using Cartesian Coordinates 13 2.3 From 2D to 3D 14 2.3.1 Extra Dimension, Extra Axis 15 2.3.2 Specifying Locations in 3D 15 2.3.3 Left-handed vs Right-handed Coordinate Spaces 16 2.3.4 Some Important Conventions Used in This Book 19 2.4 Exercises 20 Chapter Multiple Coordinate Spaces 3.1 Why Multiple Coordinate Spaces? 3.2 Some Useful Coordinate Spaces 3.2.1 World Space 3.2.2 Object Space 3.2.3 Camera Space 3.2.4 Inertial Space 3.3 Nested Coordinate Spaces 3.4 Specifying Coordinate Spaces 3.5 Coordinate Space Transformations 3.6 Exercises 23 24 25 25 26 27 28 30 31 31 34 Chapter Vectors 4.1 Vector — A Mathematical Definition 4.1.1 Vectors vs Scalars 4.1.2 Vector Dimension 4.1.3 Notation 4.2 Vector — A Geometric Definition 35 36 36 36 36 37 iii Contents 4.2.1 What Does a Vector Look Like? 4.2.2 Position vs Displacement 4.2.3 Specifying Vectors 4.2.4 Vectors as a Sequence of Displacements 4.3 Vectors vs Points 4.3.1 Relative Position 4.3.2 The Relationship Between Points and Vectors 4.4 Exercises iv 37 38 38 39 40 41 41 42 Chapter Operations on Vectors 5.1 Linear Algebra vs What We Need 5.2 Typeface Conventions 5.3 The Zero Vector 5.4 Negating a Vector 5.4.1 Official Linear Algebra Rules 5.4.2 Geometric Interpretation 5.5 Vector Magnitude (Length) 5.5.1 Official Linear Algebra Rules 5.5.2 Geometric Interpretation 5.6 Vector Multiplication by a Scalar 5.6.1 Official Linear Algebra Rules 5.6.2 Geometric Interpretation 5.7 Normalized Vectors 5.7.1 Official Linear Algebra Rules 5.7.2 Geometric Interpretation 5.8 Vector Addition and Subtraction 5.8.1 Official Linear Algebra Rules 5.8.2 Geometric Interpretation 5.8.3 Vector from One Point to Another 5.9 The Distance Formula 5.10 Vector Dot Product 5.10.1 Official Linear Algebra Rules 5.10.2 Geometric Interpretation 5.10.3 Projecting One Vector onto Another 5.11 Vector Cross Product 5.11.1 Official Linear Algebra Rules 5.11.2 Geometric Interpretation 5.12 Linear Algebra Identities 5.13 Exercises 45 46 46 47 48 48 48 49 49 50 51 51 52 53 53 53 54 54 55 57 57 58 58 59 61 62 62 62 65 67 Chapter A Simple 3D Vector 6.1 Class Interface 6.2 Class Vector3 Definition 6.3 Design Decisions 6.3.1 Floats vs Doubles 6.3.2 Operator Overloading 69 69 70 73 73 73 Class Contents 6.3.3 Provide Only the Most Important Operations 6.3.4 Don’t Overload Too Many Operators 6.3.5 Use Const Member Functions 6.3.6 Use Const & Arguments 6.3.7 Member vs Nonmember Functions 6.3.8 No Default Initialization 6.3.9 Don’t Use Virtual Functions 6.3.10 Don’t Use Information Hiding 6.3.11 Global Zero Vector Constant 6.3.12 No “point3” Class 6.3.13 A Word on Optimization Chapter Introduction to Matrices 7.1 Matrix — A Mathematical Definition 7.1.1 Matrix Dimensions and Notation 7.1.2 Square Matrices 7.1.3 Vectors as Matrices 7.1.4 Transposition 7.1.5 Multiplying a Matrix with a Scalar 7.1.6 Multiplying Two Matrices 7.1.7 Multiplying a Vector and a Matrix 7.1.8 Row vs Column Vectors 7.2 Matrix — A Geometric Interpretation 7.2.1 How Does a Matrix Transform Vectors? 7.2.2 What Does a Matrix Look Like? 7.2.3 Summary 7.3 Exercises 83 83 83 84 85 85 86 86 89 90 91 92 93 97 98 Chapter Matrices and Linear Transformations 8.1 Transforming an Object vs Transforming the Coordinate Space 8.2 Rotation 8.2.1 Rotation in 2D 8.2.2 3D Rotation about Cardinal Axes 8.2.3 3D Rotation about an Arbitrary Axis 8.3 Scale 8.3.1 Scaling along Cardinal Axes 8.3.2 Scale in an Arbitrary Direction 8.4 Orthographic Projection 8.4.1 Projecting onto a Cardinal Axis or Plane 8.4.2 Projecting onto an Arbitrary Line or Plane 8.5 Reflection 8.6 Shearing 8.7 Combining Transformations 8.8 Classes of Transformations 8.8.1 Linear Transformations 8.8.2 Affine Transformations 74 74 75 75 75 77 77 77 78 78 78 101 102 105 105 106 109 112 112 113 115 116 117 117 118 119 120 121 122 v Contents 8.8.3 Invertible Transformations 8.8.4 Angle-preserving Transformations 8.8.5 Orthogonal Transformations 8.8.6 Rigid Body Transformations 8.8.7 Summary of Types of Transformations 8.9 Exercises Chapter More on Matrices 9.1 Determinant of a Matrix 9.1.1 Official Linear Algebra Rules 9.1.2 Geometric Interpretation 9.2 Inverse of a Matrix 9.2.1 Official Linear Algebra Rules 9.2.2 Geometric Interpretation 9.3 Orthogonal Matrices 9.3.1 Official Linear Algebra Rules 9.3.2 Geometric Interpretation 9.3.3 Orthogonalizing a Matrix 9.4 4×4 Homogenous Matrices 9.4.1 4D Homogenous Space 9.4.2 4×4 Translation Matrices 9.4.3 General Affine Transformations 9.4.4 Perspective Projection 9.4.5 A Pinhole Camera 9.4.6 Perspective Projection Using 4×4 Matrices 9.5 Exercises 125 125 125 129 130 130 132 132 132 133 134 135 136 137 140 141 142 145 146 3D 147 148 149 150 150 151 152 153 153 155 156 156 159 159 160 160 162 163 163 Chapter 10 Orientation and Angular Displacement in 10.1 What is Orientation? 10.2 Matrix Form 10.2.1 Which Matrix? 10.2.2 Advantages of Matrix Form 10.2.3 Disadvantages of Matrix Form 10.2.4 Summary 10.3 Euler Angles 10.3.1 What are Euler Angles? 10.3.2 Other Euler Angle Conventions 10.3.3 Advantages of Euler Angles 10.3.4 Disadvantages of Euler Angles 10.3.5 Summary 10.4 Quaternions 10.4.1 Quaternion Notation 10.4.2 Quaternions as Complex Numbers 10.4.3 Quaternions as an Axis-Angle Pair 10.4.4 Quaternion Negation 10.4.5 Identity Quaternion(s) vi 122 122 122 123 123 124 Contents 10.4.6 Quaternion Magnitude 10.4.7 Quaternion Conjugate and Inverse 10.4.8 Quaternion Multiplication (Cross Product) 10.4.9 Quaternion “Difference” 10.4.10 Quaternion Dot Product 10.4.11 Quaternion Log, Exp, and Multiplication by a Scalar 10.4.12 Quaternion Exponentiation 10.4.13 Quaternion Interpolation — aka “Slerp” 10.4.14 Quaternion Splines — aka “Squad” 10.4.15 Advantages/Disadvantages of Quaternions 10.5 Comparison of Methods 10.6 Converting between Representations 10.6.1 Converting Euler Angles to a Matrix 10.6.2 Converting a Matrix to Euler Angles 10.6.3 Converting a Quaternion to a Matrix 10.6.4 Converting a Matrix to a Quaternion 10.6.5 Converting Euler Angles to a Quaternion 10.6.6 Converting a Quaternion to Euler Angles 10.7 Exercises Chapter 11 Transformations in C++ 11.1 Overview 11.2 Class EulerAngles 11.3 Class Quaternion 11.4 Class RotationMatrix 11.5 Class Matrix4×3 163 164 165 168 169 169 171 173 177 178 179 180 180 182 185 187 190 191 193 195 196 198 205 215 220 Chapter 12 Geometric Primitives 12.1 Representation Techniques 12.1.1 Implicit Form 12.1.2 Parametric Form 12.1.3 “Straightforward” Forms 12.1.4 Degrees of Freedom 12.2 Lines and Rays 12.2.1 Two Points Representation 12.2.2 Parametric Representation of Rays 12.2.3 Special 2D Representations of Lines 12.2.4 Converting between Representations 12.3 Spheres and Circles 12.4 Bounding Boxes 12.4.1 Representing AABBs 12.4.2 Computing AABBs 12.4.3 AABBs vs Bounding Spheres 12.4.4 Transforming AABBs 12.5 Planes 12.5.1 Implicit Definition — The Plane Equation 239 239 239 240 240 241 241 242 242 243 245 246 247 248 249 250 251 252 252 vii Contents 12.5.2 Definition Using Three Points 12.5.3 “Best-fit” Plane for More Than Three Points 12.5.4 Distance from Point to Plane 12.6 Triangles 12.6.1 Basic Properties of a Triangle 12.6.2 Area of a Triangle 12.6.3 Barycentric Space 12.6.4 Special Points 12.7 Polygons 12.7.1 Simple vs Complex Polygons 12.7.2 Self-intersecting Polygons 12.7.3 Convex vs Concave Polygons 12.7.4 Triangulation and Fanning 12.8 Exercises Chapter 13 Geometric Tests 13.1 Closest Point on 2D Implicit Line 13.2 Closest Point on Parametric Ray 13.3 Closest Point on Plane 13.4 Closest Point on Circle/Sphere 13.5 Closest Point in AABB 13.6 Intersection Tests 13.7 Intersection of Two Implicit Lines in 2D 13.8 Intersection of Two Rays in 3D 13.9 Intersection of Ray and Plane 13.10 Intersection of AABB and Plane 13.11 Intersection of Three Planes 13.12 Intersection of Ray and Circle/Sphere 13.13 Intersection of Two Circles/Spheres 13.14 Intersection of Sphere and AABB 13.15 Intersection of Sphere and Plane 13.16 Intersection of Ray and Triangle 13.17 Intersection of Ray and AABB 13.18 Intersection of Two AABBs 13.19 Other Tests 13.20 Class AABB3 13.21 Exercises viii 253 254 256 257 257 258 260 267 269 269 270 271 274 275 277 277 278 279 280 280 281 282 283 284 285 286 286 288 291 291 293 297 297 299 300 316 Chapter 14 Triangle Meshes 14.1 Representing Meshes 14.1.1 Indexed Triangle Mesh 14.1.2 Advanced Techniques 14.1.3 Specialized Representations for Rendering 14.1.4 Vertex Caching 14.1.5 Triangle Strips 14.1.6 Triangle Fans 319 320 320 322 322 323 323 327 Contents 14.2 Additional Mesh Information 14.2.1 Texture Mapping Coordinates 14.2.2 Surface Normals 14.2.3 Lighting Values 14.3 Topology and Consistency 14.4 Triangle Mesh Operations 14.4.1 Piecewise Operations 14.4.2 Welding Vertices 14.4.3 Detaching Faces 14.4.4 Edge Collapse 14.4.5 Mesh Decimation 14.5 A C++ Triangle Mesh Class 328 328 328 330 330 331 331 331 334 335 335 336 Chapter 15 3D Math for Graphics 15.1 Graphics Pipeline Overview 15.2 Setting the View Parameters 15.2.1 Specifying the Output Window 15.2.2 Pixel Aspect Ratio 15.2.3 The View Frustum 15.2.4 Field of View and Zoom 15.3 Coordinate Spaces 15.3.1 Modeling and World Space 15.3.2 Camera Space 15.3.3 Clip Space 15.3.4 Screen Space 15.4 Lighting and Fog 15.4.1 Math on Colors 15.4.2 Light Sources 15.4.3 The Standard Lighting Equation — Overview 15.4.4 The Specular Component 15.4.5 The Diffuse Component 15.4.6 The Ambient Component 15.4.7 Light Attenuation 15.4.8 The Lighting Equation — Putting It All Together 15.4.9 Fog 15.4.10 Flat Shading and Gouraud Shading 15.5 Buffers 15.6 Texture Mapping 15.7 Geometry Generation/Delivery 15.7.1 LOD Selection and Procedural Modeling 15.7.2 Delivery of Geometry to the API 15.8 Transformation and Lighting 15.8.1 Transformation to Clip Space 15.8.2 Vertex Lighting 15.9 Backface Culling and Clipping 345 346 349 349 350 351 351 354 354 354 355 357 358 359 360 361 362 365 366 366 367 368 370 372 373 374 375 375 377 378 378 380 ix .. .3D Math Primer for Graphics and Game Development Fletcher Dunn and Ian Parberry Wordware Publishing, Inc Library of Congress Cataloging-in-Publication Data Dunn, Fletcher 3D math primer for. .. it was inconvenient for them to so xi Chapter Introduction 1.1 What is 3D Math? This book is about 3D math, the study of the mathematics behind the geometry of a 3D world 3D math is related to... 3D math primer for graphics and game development / by Fletcher Dunn and Ian Parberry p cm ISBN 1-55622-911-9 Computer graphics Computer games Programming Computer science Mathematics I Parberry,

Ngày đăng: 15/04/2017, 12:17

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN