physics for game developers 2nd edition

577 1.1K 0
physics  for  game  developers  2nd  edition

Đ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

www.it-ebooks.info www.it-ebooks.info David M. Bourg and Bryan Bywalec SECOND EDITION Physics for Game Developers www.it-ebooks.info Physics for Game Developers, Second Edition by David M. Bourg and Bryan Bywalec Copyright © 2013 David M. Bourg and Bryan Bywalec. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or corporate@oreilly.com. Editors: Andy Oram and Rachel Roumeliotis Production Editor: Christopher Hearse Copyeditor: Rachel Monaghan Proofreader: Amanda Kersey Indexer: Lucie Haskins Cover Designer: Randy Comer Interior Designer: David Futato Illustrator: Rebecca Demarest April 2013: Second Edition Revision History for the Second Edition: 2013-04-09: First release See http://oreilly.com/catalog/errata.csp?isbn=9781449392512 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Physics for Game Developers, 2nd Edition, the image of a cat and mouse, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trade‐ mark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 978-1-449-39251-2 [LSI] www.it-ebooks.info Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Part I. Fundamentals 1. Basic Concepts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Newton’s Laws of Motion 3 Units and Measures 4 Coordinate System 6 Vectors 7 Derivatives and Integrals 8 Mass, Center of Mass, and Moment of Inertia 9 Newton’s Second Law of Motion 20 Inertia Tensor 24 Relativistic Time 29 2. Kinematics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Velocity and Acceleration 36 Constant Acceleration 39 Nonconstant Acceleration 41 2D Particle Kinematics 42 3D Particle Kinematics 45 X Components 46 Y Components 47 Z Components 48 The Vectors 48 Hitting the Target 49 Kinematic Particle Explosion 54 Rigid-Body Kinematics 61 Local Coordinate Axes 62 iii www.it-ebooks.info Angular Velocity and Acceleration 62 3. Force. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Forces 71 Force Fields 72 Friction 73 Fluid Dynamic Drag 75 Pressure 76 Buoyancy 77 Springs and Dampers 79 Force and Torque 80 Summary 83 4. Kinetics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Particle Kinetics in 2D 87 Particle Kinetics in 3D 91 X Components 94 Y Components 95 Z Components 95 Cannon Revised 95 Rigid-Body Kinetics 99 5. Collisions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Impulse-Momentum Principle 104 Impact 105 Linear and Angular Impulse 112 Friction 115 6. Projectiles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Simple Trajectories 120 Drag 124 Magnus Effect 132 Variable Mass 138 Part II. Rigid-Body Dynamics 7. Real-Time Simulations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Integrating the Equations of Motion 144 Euler’s Method 146 Better Methods 153 iv | Table of Contents www.it-ebooks.info Summary 159 8. Particles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Simple Particle Model 166 Integrator 169 Rendering 170 The Basic Simulator 170 Implementing External Forces 172 Implementing Collisions 175 Particle-to-Ground Collisions 175 Particle-to-Obstacle Collisions 181 Tuning 186 9. 2D Rigid-Body Simulator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Model 190 Transforming Coordinates 197 Integrator 198 Rendering 200 The Basic Simulator 201 Tuning 204 10. Implementing Collision Response. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 Linear Collision Response 206 Angular Effects 213 11. Rotation in 3D Rigid-Body Simulators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Rotation Matrices 228 Quaternions 232 Quaternion Operations 234 Quaternions in 3D Simulators 239 12. 3D Rigid-Body Simulator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 Model 243 Integration 247 Flight Controls 250 13. Connecting Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 Springs and Dampers 257 Connecting Particles 258 Rope 258 Connecting Rigid Bodies 265 Links 265 Table of Contents | v www.it-ebooks.info Rotational Restraint 275 14. Physics Engines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Building Your Own Physics Engine 281 Physics Models 283 Simulated Objects Manager 284 Collision Detection 285 Collision Response 286 Force Effectors 287 Numerical Integrator 288 Part III. Physical Modeling 15. Aircraft. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 Geometry 294 Lift and Drag 297 Other Forces 302 Control 303 Modeling 305 16. Ships and Boats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 Stability and Sinking 323 Stability 323 Sinking 325 Ship Motions 326 Heave 327 Roll 327 Pitch 328 Coupled Motions 328 Resistance and Propulsion 328 General Resistance 328 Propulsion 334 Maneuverability 335 Rudders and Thrust Vectoring 336 17. Cars and Hovercraft. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 Cars 339 Resistance 339 Power 340 Stopping Distance 341 Steering 342 vi | Table of Contents www.it-ebooks.info Hovercraft 345 How Hovercraft Work 345 Resistance 347 Steering 350 18. Guns and Explosions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 Projectile Motion 353 Taking Aim 355 Zeroing the Sights 357 Breathing and Body Position 360 Recoil and Impact 361 Explosions 362 Particle Explosions 363 Polygon Explosions 366 19. Sports. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369 Modeling a Golf Swing 370 Solving the Golf Swing Equations 373 Billiards 378 Implementation 380 Initialization 383 Stepping the Simulation 386 Calculating Forces 388 Handling Collisions 393 Part IV. Digital Physics 20. Touch Screens. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403 Types of Touch Screens 403 Resistive 403 Capacitive 404 Infrared and Optical Imaging 404 Exotic: Dispersive Signal and Surface Acoustic Wave 404 Step-by-Step Physics 404 Resistive Touch Screens 404 Capacitive Touch Screens 408 Example Program 410 Multitouch 410 Other Considerations 411 Haptic Feedback 411 Modeling Touch Screens in Games 411 Table of Contents | vii www.it-ebooks.info Difference from Mouse-Based Input 412 Custom Gestures 412 21. Accelerometers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 Accelerometer Theory 414 MEMS Accelerometers 416 Common Accelerometer Specifications 417 Data Clipping 417 Sensing Orientation 418 Sensing Tilt 420 Using Tilt to Control a Sprite 420 Two Degrees of Freedom 421 22. Gaming from One Place to Another. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427 Location-Based Gaming 427 Geocaching and Reverse Geocaching 428 Mixed Reality 428 Street Games 428 What Time Is It? 429 Two-Dimensional Mathematical Treatment 429 Location, Location, Location 433 Distance 433 Great-Circle Heading 435 Rhumb Line 436 23. Pressure Sensors and Load Cells. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 Under Pressure 440 Example Effects of High Pressure 440 Button Mashing 442 Load Cells 444 Barometers 448 24. 3D Display. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451 Binocular Vision 451 Stereoscopic Basics 454 The Left and Right Frustums 454 Types of Display 458 Complementary-Color Anaglyphs 458 Linear and Circular Polarization 459 Liquid-Crystal Plasma 462 Autostereoscopy 463 Advanced Technologies 465 viii | Table of Contents www.it-ebooks.info [...]... www.it-ebooks.info Preface Who Is This Book For? Simply put, this book is targeted at computer game developers who do not have a strong mechanics or physics background, charged with the task of incorporating real physics in their games As a game developer, and very likely as a gamer yourself, you’ve seen products being advertised as “ultra-realistic,” or as using “real-world physics. ” At the same time you, or... leverage these effects in their games Chapter 26, Sound Sound is a particularly important part of a game s immersive experience; however, to date no book on game physics addresses the physics of sound This chapter will focus on sound physics including such topics of sound speed and the Doppler Effect Discussions will also include why sound physics is often ignored in games, for example, when simulating... directly, or too advanced requiring you to search for other sources to get up to speed on the basics This book will pull together the information you need and will serve as the starting point for you, the game developer, in your effort to enrich your game s content with physics- based realism This book is not a recipe book that simply gives sample code for a miscellaneous set of problems The Internet... games Arrangement of This Book Physics- based realism is not new to gaming, and in fact many games on the shelves these days advertise their physics engines Also, many 3D modeling and animation tools have physics engines built in to help realistically animate specific types of motion Naturally, there are magazine articles that appear every now and then that discuss various aspects of physics- based game. .. model Or, perhaps you are charged with the task of tuning someone else’s physics code but you really don’t understand how it works Well then, this book is for you Sure you could scour the Internet, trade journals, and magazines for information and how-to’s on adding physics- based realism to your games You could even fish out that old physics text and start from scratch However, you’re likely to find that... book into your product’s documentation does require permission We appreciate, but do not require, attribution An attribution usually includes the title, author, publisher, and ISBN For example: Physics for Game Developers, 2nd Edition by David M Bourg and Bryan Bywalec (O’Reilly) Copyright 2013 David M Bourg and Bryan Bywalec, 978-1-449-39251-2.” If you feel your use of code examples falls outside fair... upon by an external force This is the so-called concept of inertia Law II The acceleration of a body is proportional to the resultant force acting on the body, and this acceleration is in the same direction as the resultant force Law III For every force acting on a body (action) there is an equal and opposite reacting force (reaction), where the reaction is collinear to the acting force 3 www.it-ebooks.info... (albeit in reverse), and all that means is that any formulas you develop to represent a force acting on a body had better come out to a consistent set of units in the form (M) (L/T2) This may seem trivial at the moment; however, when you start looking at more complicated formulas for the forces acting on a body, you’ll want to be able to break down these formulas into their component dimensions so you... the Wii Fit game This chapter will explain the physics behind such pressure sensors, what data they generate, and how to manipulate that data for game interaction Preface www.it-ebooks.info | xvii Chapter 24, 3D Display The new PlayStation Move and Microsoft’s Kinect use optical tracking systems to detect the position of players’ game controllers or gestures This chapter will explain the physics behind... both the motion of bodies and the forces that act on or otherwise affect bodies in motion We’ll take a very close look at these two subjects throughout this book Preface www.it-ebooks.info | xiii Digital Physics This book’s first edition focused exclusively on mechanics More than a decade after its release we’ve broadened our definition of game physics to include digital physics not in the cosmological . www.it-ebooks.info www.it-ebooks.info David M. Bourg and Bryan Bywalec SECOND EDITION Physics for Game Developers www.it-ebooks.info Physics for Game Developers, Second Edition by David M. Bourg and Bryan Bywalec Copyright. Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Physics for Game Developers, 2nd Edition, the image of a cat and mouse, and related trade dress are trademarks of. Book For? Simply put, this book is targeted at computer game developers who do not have a strong mechanics or physics background, charged with the task of incorporating real physics in their games. As

Ngày đăng: 05/05/2014, 15:55

Từ khóa liên quan

Mục lục

  • Copyright

  • Table of Contents

  • Preface

    • Who Is This Book For?

    • What We Assume You Know

    • Mechanics

    • Digital Physics

    • Arrangement of This Book

    • Conventions Used in This Book

    • Using Code Examples

    • Safari® Books Online

    • How to Contact Us

    • Acknowledgments

    • Part I. Fundamentals

      • Chapter 1. Basic Concepts

        • Newton’s Laws of Motion

        • Units and Measures

        • Coordinate System

        • Vectors

        • Derivatives and Integrals

        • Mass, Center of Mass, and Moment of Inertia

        • Newton’s Second Law of Motion

        • Inertia Tensor

Tài liệu cùng người dùng

Tài liệu liên quan