ebook img

Game Physics Engine Development: How to Build a Robust Commercial-Grade Physics Engine for your Game (Second Edition) PDF

553 Pages·2010·6.3 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Game Physics Engine Development: How to Build a Robust Commercial-Grade Physics Engine for your Game (Second Edition)

GAME PHYSICS ENGINE DEVELOPMENT Thispageintentionallyleftblank GAME PHYSICS ENGINE DEVELOPMENT H B R OW TO UILD A OBUST C -G P E OMMERCIAL RADE HYSICS NGINE G FOR YOUR AME Second Edition IANMILLINGTON AMSTERDAM•BOSTON•HEIDELBERG•LONDON NEWYORK•OXFORD•PARIS•SANDIEGO SANFRANCISCO•SINGAPORE•SYDNEY•TOKYO MorganKaufmannPublishersisanimprintofElsevier MorganKaufmannPublishersisanimprintofElsevier. 30CorporateDrive,Suite400,Burlington,MA01803,USA Thisbookisprintedonacid-freepaper. Copyright©2010ElsevierInc.Allrightsreserved. Nopartofthispublicationmaybereproducedortransmittedinanyformorbyanymeans,electronicormechanical,including photocopying,recording,oranyinformationstorageandretrievalsystem,withoutpermissioninwritingfromthepublisher. Detailsonhowtoseekpermission,furtherinformationaboutthePublisher’spermissionspoliciesandourarrangementswith organizationssuchastheCopyrightClearanceCenterandtheCopyrightLicensingAgency,canbefoundatourwebsite: www.elsevier.com/permissions. ThisbookandtheindividualcontributionscontainedinitareprotectedundercopyrightbythePublisher(otherthanasmaybe notedherein). Notices Knowledgeandbestpracticeinthisfieldareconstantlychanging.Asnewresearchandexperiencebroadenourunderstanding, changesinresearchmethods,professionalpractices,ormedicaltreatmentmaybecomenecessary. Practitionersandresearchersmustalwaysrelyontheirownexperienceandknowledgeinevaluatingandusinganyinformation, methods,compounds,orexperimentsdescribedherein.Inusingsuchinformationormethodstheyshouldbemindfuloftheirown safetyandthesafetyofothers,includingpartiesforwhomtheyhaveaprofessionalresponsibility. Tothefullestextentofthelaw,neitherthePublishernortheauthors,contributors,oreditors,assumeanyliabilityforanyinjury and/ordamagetopersonsorpropertyasamatterofproductsliability,negligenceorotherwise,orfromanyuseoroperationofany methods,products,instructions,orideascontainedinthematerialherein. LibraryofCongressCataloging-in-PublicationData Millington,Ian. Gamephysicsenginedevelopment:howtobuildarobustcommercial-gradephysicsengineforyour game/IanMillington.–2nded. p.cm. Includesindex. ISBN978-0-12-381976-5(pbk.:alk.paper) 1.Computergames–Programming.2.Physics–Dataprocessing.I.Title. QA76.76.C672M552010 794.8(cid:2)1526–dc22 2010014533 BritishLibraryCataloguing-in-PublicationData AcataloguerecordforthisbookisavailablefromtheBritishLibrary. ISBN:978-0-12-381976-5 ForinformationonallMorganKaufmannpublications visitourWebsiteatwww.mkp.comorwww.elsevierdirect.com Typesetby:diacriTech,India PrintedintheUnitedStatesofAmerica 10 11 12 13 5 4 3 2 1 For Richard Thispageintentionallyleftblank Contents List of Figures xix Preface to the Second Edition xxiii Preface to the First Edition xxv Acknowledgments xxvii About the Author xxix Chapter 1 Introduction 1 What Is Game Physics? 1.1 2 What Is a Physics Engine? 1.2 2 1.2.1 AdvantagesofaPhysicsEngine 3 1.2.2 WeaknessesofaPhysicsEngine 4 Approaches to Physics Engines 1.3 5 1.3.1 TypesofObjects 5 1.3.2 ContactResolution 6 1.3.3 ImpulsesandForces 6 1.3.4 WhatWe’reBuilding 7 The Mathematics of Physics Engines 1.4 8 1.4.1 TheMathYouNeedtoKnow 8 1.4.2 TheMathWe’llReview 9 1.4.3 TheMathI’llIntroduce 10 The Source Code in the Book 1.5 10 How the Book Is Structured 1.6 11 1.6.1 ExercisesandProjects 12 vii viii Contents PART I Particle Physics 15 Chapter 2 The Mathematics of Particles 17 Vectors 2.1 17 2.1.1 TheHandednessofSpace 21 2.1.2 VectorsandDirections 23 2.1.3 ScalarandVectorMultiplication 25 2.1.4 VectorAdditionandSubtraction 27 2.1.5 MultiplyingVectors 29 2.1.6 TheComponentProduct 30 2.1.7 TheScalarProduct 31 2.1.8 TheVectorProduct 33 2.1.9 TheOrthonormalBasis 37 Calculus 2.2 38 2.2.1 DifferentialCalculus 38 2.2.2 IntegralCalculus 43 Summary 2.3 44 Exercises 2.4 45 Chapter 3 The Laws of Motion 47 The Particle 3.1 48 The First Two Laws 3.2 49 3.2.1 TheForceEqu ations 50 3.2.2 AddingMasstoParticles 51 3.2.3 MomentumandVelocity 52 3.2.4 TheForceofGravity 53 The Integrator 3.3 55 3.3.1 TheUpdateEquations 55 3.3.2 TheCompleteIntegrator 57 Summary 3.4 58 Exercises 3.5 59 Chapter 4 The Particle Physics Engine 61 Ballistics 4.1 61 4.1.1 SettingProjectileProperties 62 4.1.2 Implementation 63 ix Contents Fireworks 4.2 66 4.2.1 TheFireworksData 66 4.2.2 FireworkRules 67 4.2.3 TheImplementation 69 Summary 4.3 73 Projects 4.4 73 PART II Mass Aggregate Physics 75 Chapter 5 Adding General Forces 77 D’Alembert’s Principle 5.1 77 Force Generators 5.2 80 5.2.1 InterfacesandPolymorphism 81 5.2.2 Implementation 81 5.2.3 AGravityForceGenerator 84 5.2.4 ADragForceGenerator 85 Built-In Gravity and Damping 5.3 87 Summary 5.4 87 Exercises 5.5 88 Chapter 6 Springs and Spring-Like Things 89 Hook’s Law 6.1 89 Spring-Like Force Generators 6.2 92 6.2.1 ABasicSpringForceGenerator 92 6.2.2 AnAnchoredSpringGenerator 94 6.2.3 AnElasticBungeeGenerator 96 6.2.4 ABuoyancyForceGenerator 98 Stiff Springs 6.3 101 6.3.1 TheStiffSpringsProblem 102 6.3.2 FakingStiffSprings 104 Summary 6.4 110 Exercises 6.5 110

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.