You are previewing Physics for JavaScript Games, Animation, and Simulations: with HTML5 Canvas.
O'Reilly logo
Physics for JavaScript Games, Animation, and Simulations: with HTML5 Canvas

Book Description

Have you ever wanted to include believable physical behaviors in your games and projects to give them that extra edge? Physics for JavaScript Games, Animation, and Simulations teaches you how to incorporate real physics, such as gravity, friction, and buoyancy, into your HTML5 games, animations, and simulations. It also includes more advanced topics, such as particle systems, which are essential for creating effects such as sparks or smoke. The book also addresses the key issue of balancing accuracy and simplicity in your games and simulations, and the final chapters provide you with the information and the code to make the right choice for your project.

Physics for JavaScript Games, Animation, and Simulations assumes you have a basic knowledge of JavaScript and HTML5. However, no previous knowledge of physics is required—only some very basic math skills. The authors present everything from basic principles to advanced concepts in an approachable way, so you'll be able to follow the logic and easily adapt the principles to your own applications.

The book is packed full of practical examples of how you can apply physics to your own games and applications. Spring behaviors can be used for anything from tweaking lowrider suspension to creating cloth simulation; flotation mechanics enable the simulation of submersibles or dirigibles; you can even create your own solar system with accurate orbits and gravity. It doesn't matter if you're modeling the Lorentz force in an electromagnetic field or you're modeling the lift force in a flight simulator, Physics for JavaScript Games, Animation, and Simulations enables you to fill your games and applications with accurate and realistic effects.

What you'll learn

  • Learn all the basic math and physics you'll need to incorporate realism into your projects

  • Incorporate a wide range of forces, such as gravity, friction, and buoyancy

  • Build a number of realistic simulations

  • Model particle systems and use them to create visual effects

  • Create complex systems using rigid bodies and mass-spring systems

  • Deal with numerical subtleties, including accuracy and stability of integration schemes

  • Who this book is for

    Physics for JavaScript Games, Animation, and Simulations is for JavaScript developers interested in incorporating real physics into their games, animations, simulations, or generative art projects

    Table of Contents

    1. Title Page
    2. Dedication
    3. Contents at a Glance
    4. Contents
    5. About the Authors
    6. About the Technical Reviewer
    7. Acknowledgments
    8. Introduction
    9. PART I: The Basics
      1. CHAPTER 1: Introduction to Physics Programming
        1. Why model real physics?
        2. What is physics?
        3. Programming physics
        4. A simple physics simulation example
        5. Summary
      2. CHAPTER 2: JavaScript and HTML5 Canvas Basics
        1. HTML5, the canvas element, and JavaScript
        2. JavaScript objects
        3. JavaScript language basics
        4. Events and user interaction
        5. The canvas coordinate system
        6. The canvas drawing API
        7. Producing animation using code
        8. Summary
      3. CHAPTER 3: Some Math Background
        1. Coordinates and simple graphs
        2. Basic trigonometry
        3. Vectors and basic vector algebra
        4. Simple calculus ideas
        5. Summary
      4. CHAPTER 4: Basic Physics Concepts
        1. General physics concepts and notation
        2. Things: particles and other objects in physics
        3. Describing motion: kinematics
        4. Predicting motion: forces and dynamics
        5. Energy concepts
        6. Summary
    10. PART II: Particles, Forces, and Motion
      1. CHAPTER 5: The Laws Governing Motion
        1. Newton’s laws of motion
        2. Applying Newton’s laws
        3. Newton’s second law as a differential equation
        4. The principle of energy conservation
        5. The principle of momentum conservation
        6. Laws governing rotational motion
        7. Summary
      2. CHAPTER 6: Gravity, Orbits, and Rockets
        1. Gravity
        2. Orbits
        3. Local gravity
        4. Rockets
        5. Summary
      3. CHAPTER 7: Contact and Fluid Forces
        1. Contact forces
        2. Pressure
        3. Upthrust (buoyancy)
        4. Drag
        5. Lift
        6. Wind and turbulence
        7. Summary
      4. CHAPTER 8: Restoring Forces: Springs and Oscillations
        1. Springs and oscillations: Basic concepts
        2. Free oscillations
        3. Damped oscillations
        4. Forced oscillations
        5. Coupled oscillators: Multiple springs and objects
        6. Summary
      5. CHAPTER 9: Centripetal Forces: Rotational Motion
        1. Kinematics of uniform circular motion
        2. Centripetal acceleration and centripetal force
        3. Non-uniform circular motion
        4. Summary
      6. CHAPTER 10: Long-Range Forces
        1. Particle interactions and force fields
        2. Newtonian gravitation
        3. Electrostatic force
        4. Electromagnetic force
        5. Other force laws
        6. Summary
    11. PART III: Multi-particle and Extended Systems
      1. CHAPTER 11: Collisions
        1. Collisions and their modeling
        2. Bouncing off horizontal or vertical walls
        3. Bouncing off inclined walls
        4. Collisions between particles in 1D
        5. Collisions between particles in 2D
        6. Summary
      2. CHAPTER 12: Particle Systems
        1. Introduction to particle system modeling
        2. Creating animated effects using particles
        3. Particle animations with long-range forces
        4. Interacting particle systems
        5. Summary
      3. CHAPTER 13: Extended Objects
        1. Rigid bodies
        2. Deformable bodies
        3. Summary
    12. PART IV: Building More Complex Simulations
      1. CHAPTER 14: Numerical Integration Schemes, Accuracy, and Scaling
        1. General principles
        2. Euler integration
        3. Runge-Kutta integration
        4. Verlet integration
        5. Tips for achieving accuracy
        6. Building scale models
        7. Summary
      2. CHAPTER 15: Doing Physics in 3D
        1. 3D physics and math
        2. 3D rendering: Introducing WebGL and three.js
        3. Simulating particle motion in 3D
        4. Simulating rigid body motion in 3D
        5. Summary
      3. CHAPTER 16: Simulation Projects
        1. Building a submarine
        2. Building a flight simulator
        3. Creating an accurate solar system model
        4. Summary
    13. Index