Physics for Flash Games, Animation, and Simulations teaches ActionScript programmers how to incorporate real physics into their Flash animations, games, user interfaces, and simulations. Introduces Flash physics in an accurate, but approachable way, covering what is required to produce p
Physics for Flash Games, Animation, and Simulations
✍ Scribed by Ramtal, Dev;Dobre, Adrian
- Publisher
- Apress
- Year
- 2011
- Tongue
- English
- Leaves
- 547
- Edition
- 1st ed. 2011
- Category
- Library
No coin nor oath required. For personal study only.
✦ Synopsis
Physics for Flash Games, Animation, and Simulations teaches ActionScript programmers how to incorporate real physics into their Flash animations, games, user interfaces, and simulations.
Introduces Flash physics in an accurate, but approachable way, covering what is required to produce physically realistic simulations (as opposed to animations that look roughly right) Packed full of practical examples of how physics can be applied to your own games and applications Addresses the diverse needs of game developers, animators, artists, and e-learning developers The book assumes a basic knowledge of ActionScript and Flash.However, no previous knowledge of physics is required--only somevery basic math skills. The authors present everything from basic principlesto advanced concepts, soyou'll be able tofollowthe logic and easilyadapt the principles to your own applications. The book builds on your physics knowledge, enabling you to create notonly visualeffects, butalso more complex models and simulations. What you'll learn Basic math and physics you'll need to incorporate realism into your games, animations and simulations How toincorporate a wide range of forces, including environmental forces such as gravity and friction, and forces due to fluids, such as drag and upthrust How to build a number of realistic simulations, like submarines and flight simulators How to model particle systems and use them for generative art and to create effects, such as smoke Numerical subtleties, including accuracy and stability of integration schemes and handling boundary conditions properly; and how and when to use approximations and analytical solutions Who this book is for
Flash developers interested in incorporating real physics into their games, animations, simulations or generative art projects. Table of Contents Introduction to Physics Programming Selected ActionScript 3.0 Topics Some Math Background Basic Physics Concepts The Laws Governing Motion Gravity, Orbits, and Rockets Contact and Fluid Forces Restoring Forces: Springsand Oscillations Centripetal Forces: Rotational Motion Long-Range Forces Collisions Particle Systems Extended Objects Numerical Integration Schemes Other Technical Issues Simulation Projects "
✦ Table of Contents
Title Page......Page 2
Copyright Page......Page 3
Contents at a Glance......Page 5
Table of Contents......Page 7
About the Authors......Page 18
About the Technical Reviewer......Page 19
About the Cover Image Artist......Page 20
Acknowledgments......Page 21
What this book will (and won’t) teach you......Page 22
Source code and examples......Page 23
Part I The Basics......Page 25
Why model real physics?......Page 26
Generating art from code......Page 27
Can’t I just use a physics engine?......Page 28
The laws can be written as math equations......Page 29
Programming physics......Page 30
Hence, they can be readily coded up!......Page 31
A simple example......Page 32
Some code at last!......Page 33
Summary......Page 35
Chapter 2 Selected ActionScript 3.0 Topics......Page 36
Classes and objects......Page 37
Structure of an AS3.0 class......Page 38
Properties......Page 39
Static methods and properties......Page 40
Variables and constants......Page 41
Data types......Page 42
Arrays......Page 44
Operators......Page 45
Math......Page 46
Logic......Page 47
Loops......Page 48
Event listeners and handlers......Page 50
Drag and drop......Page 51
2D coordinates......Page 52
3D in Flash......Page 53
Drawing lines and curves......Page 55
Creating fills and gradients......Page 56
Example: Bouncing ball in a box......Page 57
Using the built-in frame stepping as a clock......Page 59
Using the Timer class......Page 60
Using getTimer() to compute elapsed time......Page 61
Collision detection......Page 63
Distance-based collision detection......Page 64
Summary......Page 66
Chapter 3 Some Math Background......Page 67
Building a plotter: the Graph class......Page 68
Plotting functions using the Graph class......Page 69
Straight lines......Page 70
Polynomial curves......Page 71
Things that grow and decay: exponential and log functions......Page 72
Making an object move along a curve......Page 74
Fun with hills......Page 75
The trouble with circles......Page 77
Using parametric equations......Page 79
Distance between two points......Page 81
Degrees and radians......Page 82
The sine function......Page 83
The tangent function......Page 85
The inverse trig functions......Page 86
Wavelength, period, frequency and angular frequency......Page 87
Damped oscillations......Page 89
Combining sine waves......Page 90
What are vectors?......Page 92
Vectors and scalars......Page 93
Adding and subtracting vectors......Page 94
Resolving vectors: vector components......Page 95
Position vectors......Page 96
Multiplying a vector by a number......Page 97
Multiplying vectors: Scalar or dot product......Page 98
Multiplying vectors: Vector or cross product......Page 99
Building a Vector class with vector algebra......Page 101
Simple calculus ideas......Page 102
Slope of a line: gradient......Page 103
Rates of change: derivatives......Page 104
Discrete calculus: difference equations......Page 107
Doing sums: integrals......Page 109
Summary......Page 111
Chapter 4 Basic Physics Concepts......Page 112
Scientific notation......Page 113
What is a particle?......Page 114
Building a Particle class......Page 115
Moving particles: the Mover class......Page 119
The Ball class......Page 121
Using the Ball class......Page 122
Describing motion: kinematics......Page 124
Displacement......Page 125
Velocity......Page 126
Acceleration......Page 127
Combining vector quantities......Page 128
Equations of motion for uniform acceleration......Page 129
Applying the equations to projectile motion......Page 131
Predicting motion: forces and dynamics......Page 135
The relationship between force, mass, and acceleration......Page 136
Types of forces......Page 137
Combining forces: force diagrams and resultant force......Page 138
Forces in equilibrium......Page 139
An example: object falling under gravity and drag......Page 140
Energy concepts......Page 143
The notion of work in physics......Page 144
The capacity to do work: energy......Page 145
Energy transfer, conversion, and conservation......Page 146
Power......Page 147
Example: a rudimentary “car” simulation......Page 148
Summary......Page 152
Part II Particles, Forces, and Motion......Page 153
Chapter 5 The Laws Governing Motion......Page 154
Newton’s first law of motion (N1)......Page 155
Newton’s second law of motion (N2)......Page 156
Newton’s third law of motion (N3)......Page 157
The Forcer class......Page 158
The Forces class......Page 160
A simple example: projectile with drag......Page 161
A more complicated example: floating ball......Page 163
Taking a deeper look at F = ma......Page 165
An example: Fall under gravity and drag revisited......Page 166
The principle of energy conservation......Page 167
An example: Energy changes in a projectile......Page 168
The principle of momentum conservation......Page 171
Example: 1D elastic collision between two particles......Page 173
Summary......Page 175
Gravity......Page 176
Newton’s universal law of gravitation......Page 177
Creating the gravity function......Page 178
Orbits......Page 180
Orbiter class......Page 181
Escape velocity......Page 184
Two-body motion......Page 185
The force of gravity near the Earth’s surface......Page 188
Variation of gravity with height......Page 189
Gravity on other celestial bodies......Page 191
Modeling the thrust of a rocket......Page 192
Building a rocket simulation......Page 193
The Rocketer class......Page 194
The Rocket class......Page 197
Summary......Page 199
Chapter 7 Contact and Fluid Forces......Page 200
Normal contact forces......Page 201
Friction......Page 202
Modeling static and kinetic friction......Page 203
The physics......Page 204
Creating the visual setup......Page 205
Making things move......Page 206
The meaning of pressure......Page 210
Density......Page 211
Variation of pressure with depth in a fluid......Page 212
Upthrust (buoyancy)......Page 213
Archimedes’s Principle......Page 214
Submerged objects......Page 215
Example: Balloon......Page 216
Drag......Page 218
Drag law for low velocities......Page 219
Drag law for high velocities......Page 220
Which drag law should I use?......Page 221
Example: Floating ball......Page 222
Terminal velocity......Page 226
Example: Parachute......Page 228
Lift......Page 231
Example: An airplane......Page 232
Force due to the wind......Page 235
Example: Air bubbles in a steady wind......Page 236
Modeling turbulence......Page 238
Summary......Page 239
Springs and oscillations: Basic concepts......Page 240
Restoring force, damping, and forcing......Page 241
Hooke’s law......Page 242
Creating a basic oscillator......Page 243
Simple harmonic motion......Page 245
Oscillations and numerical accuracy......Page 248
Damping force......Page 252
The effect of damping on oscillations......Page 253
Analytical solutions for oscillations with damping......Page 255
Driving forces......Page 256
Example: A periodic driving force......Page 257
Example: A random driving force......Page 258
Gravity as a driving force: bungee jumping......Page 259
Example: Driving force by user interaction......Page 262
Coupled oscillators: Multiple springs and objects......Page 264
Example: A chain of objects connected by springs......Page 265
Summary......Page 269
Kinematics of uniform circular motion......Page 270
Angular displacement......Page 271
Angular acceleration......Page 272
Period, frequency, and angular velocity......Page 273
Relation between angular velocity and linear velocity......Page 274
Example: A rolling wheel......Page 275
Particles with spin......Page 277
Example: Satellite around a rotating Earth......Page 278
Centripetal acceleration......Page 282
Centripetal force......Page 283
Common misconceptions about centripetal force......Page 284
Example: Revisiting the satellite animation......Page 285
Example: Circular orbits with gravitational force......Page 286
Example: Car moving around a bend......Page 289
Tangential force and acceleration......Page 293
Example: A simple pendulum......Page 294
Summary......Page 298
Particle interactions and force fields......Page 299
From particle interactions to force fields......Page 300
Gravitational field due to a particle......Page 301
Gravity with multiple orbiters......Page 302
Gravity with multiple attractors......Page 304
Particle trajectories in a gravity field......Page 307
Building a simple black hole game......Page 310
Creating the visual setup......Page 311
Programming the game functionality......Page 313
Electric charge......Page 317
Coulomb’s law of electrostatics......Page 318
Charged particle attraction and repulsion......Page 319
Electric field due to a charged particle......Page 321
Time-varying electric fields......Page 322
Magnetic fields and forces......Page 324
The Lorentz force law......Page 326
Central forces......Page 328
Gravity with a spring force law?......Page 332
Multiple attractors with different laws of gravity......Page 334
Summary......Page 336
Part III Multi-particle and Extended Systems......Page 337
Chapter 11 Collisions......Page 338
Collisions and their modeling......Page 339
Elastic bouncing......Page 340
Implementing energy loss due to bouncing......Page 343
Collision detection......Page 344
Repositioning the particle......Page 346
Calculating the new velocity......Page 347
Velocity correction just before collision......Page 349
Creating a Wall class......Page 351
Getting a ball to bounce off an inclined wall......Page 352
Dealing with a potential “tunneling” problem......Page 355
Example of ball bouncing off multiple inclined walls......Page 356
Repositioning the particles......Page 357
Elastic collisions......Page 360
Relative velocity of colliding particles......Page 361
Calculating velocities after an elastic collision......Page 362
Another special case: collision with a particle of much larger mass......Page 363
Coefficient of restitution......Page 364
Calculating velocities after an inelastic collision......Page 365
Collisions between particles in 2D......Page 366
Creating a two-particle collision simulator......Page 367
Experimenting with the particle collision simulation......Page 369
Example: multiple particle collisions......Page 370
Example: multiple particle collisions with bouncing......Page 371
Summary......Page 375
Chapter 12 Particle Systems......Page 376
Introduction to particle system modeling......Page 377
A simple example: splash effect with particles......Page 378
Creating a particle emitter......Page 381
Creating a smoke effect......Page 384
Creating a fire effect......Page 388
Making sparks......Page 390
Making the fireworks animation......Page 393
Particle paths in a force field......Page 396
Building a wormhole......Page 399
Multiple particles under mutual gravity......Page 402
A simple galaxy simulation......Page 406
Summary......Page 411
Rigid bodies......Page 412
Rotational kinematics......Page 413
Rotational kinematics with the Particle and Mover classes......Page 414
Turning effect of a force: torque......Page 415
Center of mass......Page 416
Moment of inertia......Page 417
Angular momentum......Page 418
Creating a RigidBody class......Page 419
The PolygonRB class......Page 420
Using the rigid body classes......Page 421
Newton’s second law for rotational motion......Page 422
Conservation of angular momentum......Page 424
Rotational kinetic energy......Page 425
Modifying Forcer and MultiForcer to include rotation......Page 426
A simple test......Page 427
Example: a simple wind turbine simulation......Page 429
From a particle to a rigid body simulation......Page 432
Simulating rolling without slipping......Page 435
Allowing both slipping and rolling......Page 437
More experiments with the simulation......Page 438
Linear impulse due to collision......Page 439
Angular impulse due to collision......Page 441
The final result......Page 442
Example: Simulating a single bouncing block......Page 443
Example: Colliding blocks......Page 447
Mass-spring systems......Page 449
Rope simulation......Page 451
Cloth simulation......Page 455
Summary......Page 457
Part IV Building More Complex Simulations......Page 458
Chapter 14 Numerical Integration Schemes......Page 459
Motion of a particle as an initial value problem......Page 460
Numerical integration and integration schemes......Page 461
Consistency......Page 462
Types of integration schemes......Page 463
Modifying Forcer to allow for different integration schemes......Page 464
Explicit Euler......Page 465
Semi-implicit Euler......Page 466
Comparing the explicit and semi-implicit Euler schemes......Page 467
Runge-Kutta integration......Page 468
Second-order Runge-Kutta scheme (RK2)......Page 469
Fourth-order Runge-Kutta scheme (RK4)......Page 470
Stability and accuracy of RK2 and RK4 compared with Euler......Page 471
Position Verlet......Page 472
Testing the stability and accuracy of the Verlet schemes......Page 474
Summary......Page 475
Chapter 15 Other Technical Issues......Page 476
Extending Vector3D: the Vector3DX class......Page 477
Matrix algebra in 2D......Page 478
Rotation matrices in 2D......Page 479
Doing other transformations with matrices......Page 480
Matrices and rotation in 3D......Page 481
Matrix3D class......Page 482
Creating classes for 3D objects and motion......Page 483
PolyhedronRB class......Page 485
Example: A rotating cube......Page 486
Integrating with 3D engines......Page 489
A simple example......Page 490
Scaling factors and parameter values......Page 491
Rescaling equations......Page 492
Using Number for calculations......Page 493
Using accurate initial conditions......Page 494
Summary......Page 495
Build a submarine......Page 496
The visual setup......Page 497
The setup code......Page 498
Adding controls and visual effects......Page 499
The full mover code......Page 501
Physics and control mechanisms of aircraft......Page 503
Forces on an aircraft......Page 504
Torques on an aircraft: rotation......Page 505
Aircraft parts and controls......Page 506
Takeoff and landing......Page 507
Creating the visual setup......Page 508
Coding up the physics......Page 510
Test flying the simulator......Page 514
Create an accurate solar system model......Page 515
Coding up an appropriate integration scheme......Page 516
Building an idealized single-planet simulation......Page 518
Choosing appropriate scaling factors......Page 520
Obtaining planetary data and initial conditions......Page 521
Basic solar system model......Page 522
Comparing the model results with NASA data......Page 527
Summary......Page 530
Index......Page 531
📜 SIMILAR VOLUMES
Physics for Flash Games, Animation, and Simulations teaches ActionScript programmers how to incorporate real physics into their Flash animations, games, user interfaces, and simulations. Introduces Flash physics in an accurate, but approachable way, covering what is required to produce p
Physics for Flash Games, Animation, and Simulations teaches ActionScript programmers how to incorporate real physics into their Flash animations, games, user interfaces, and simulations. Introduces Flash physics in an accurate, but approachable way, covering what is required to produce p
<p><em>Physics for Flash Games, Animation, and Simulations </em>teaches ActionScript programmers how to incorporate real physics into their Flash animations, games, user interfaces, and simulations. <p><p><ul><li>Introduces Flash physics in an accurate, but approachable way, covering what is require
<p><em>Physics for Flash Games, Animation, and Simulations </em>teaches ActionScript programmers how to incorporate real physics into their Flash animations, games, user interfaces, and simulations. <p><p><ul><li>Introduces Flash physics in an accurate, but approachable way, covering what is require
At a Glance; Introduction; Part I: The Basics; Chapter 1: Introduction to Physics Programming; Why model real physics?; Creating realistic animation effects; Creating realistic games; Building simulations and models; Generating art from code; What is physics?; Everything behaves according to the law