[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] physics basics?



Michal Wallace <sabren@manifestation.com>:
[snip]
> I thought a much better model was given by Steve Grand in
> his book Creation: Life and How to Make it. (He's the guy
> that developed the game Creatures)
> 
> Grand creates a world where at each tick of the clock,
> simulated forces are applied to simulated objects. In other
> words, rather than hard coding the bouncing equation, he
> gives code for gravity and inertia and the correct path of
> the ball emerges naturally.

The problem with this is that it is simply a (rather poor) approximate
numerical solution to the equations to which you just referred
(Euler's method of numerical integration or somesuch).

So it's a matter of weighing pros and cons, as always. With the
incremental method where you only work with acceleration (i.e. forces)
you get more intuitive code, but by integrating symbolically (the
forces make up a differential equation) you get more accurate results.
The difference becomes more pronounced over time.

There are many other methods that are better than Euler's method (e.g.
Runge-Kutta) that aren't that much more complicated.

> Elsewhere, Grand points out that the reason Newton had to
> invent calculus was that he didn't have a computer to do
> simple addition! :)

That's one way of putting it, of course. Another is that given
Newton's assumptions (his three laws), his calculus gives exact
results, while the "simple addition" method does not.

But, of course, in games you may well not be interested in that level
of accuracy -- or in the end result. And the more complex the physical
system you want to simulate, the less likely it is that you'll want to
actually solve the differential equations describing it... :]

I'm not sure if the O'Reilly book has any material on numerical
approximations, but I my first impression (from just thumbing through
it) is that its treatment of basic physics, and how to simulate it, is
absolutely excellent. They should use this book in high school physics
classes :)

P.S: After some more thumbing I see that chapter 11, "Real-Time
Simulations" *does* include material on Euler's method, improved
Euler, and Runge-Kutta. So, basically, Grand's way of doing things
is described here as well. If you don't get queasy by a few equations,
it's well worth the look.

-- 
Magnus Lie Hetland        Practical Python          The Anygui Project
http://hetland.org        http://ppython.com        http://anygui.org
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org