Newton Game Dynamics is a free phsyics simulation library for simulating the
physical behavior of rigid bodies. The SDK is written in the C language, and is
very versatile and powerful. I (walaber) take no credit for the design of this
system. I simply made a DLL which allows Dark Basic Professional developers to
access this powerful system. For more information on the system itself, I
suggest you visit the Official Newton
Website. The author is very helpful, and often visits the forums to
answer questions and provide information. You will probably see me on the
forums as well, under the handle "walaber".
SIMPLE INTRODUCTION TO CONCEPTS USED IN NEWTON
Newton requires some basic knowledge of physics in order to be used properly.
If you have never used a physics engine before, you may find it a bit awkward,
and counter-intuitive (coming from a traditional game programming perspective).
This is because when you use a physics system, you have to relenquish a lot of
"control" over your objects. What this means, is that, for example, you cannot
directly move objects around by simply setting your location. Although
technically it is possible in Newton, doing so counters all of the benefits of
using Newton in the first place. With a little practice, you will become
comfortable with how to build and control a world using physics, and I promise
you will be impressed with the results.
Newton works like this: First you setup your world with Newton, telling it what
kind of objects are in your world, and what properties they have (mass, size,
etc). Then you assign 3D graphical objects to represent these bodies visually.
then you control your objects with physics. this means applying forces,
impulses, etc. to the objects. Newton will automatically update the graphical
objects to represent what is happening in the world. you do not
move the objects around like you're probably used to with the position object /
rotate object commands. But before we go any further, let's have a look at the
different terminology necessary to deal with physics:
BASIC TERMINOLOGY
Here is a list of basic terms you will need to understand to use Newton (and to
understand the documentation).
|
BODY |
a body is the general term used for a RIGID BODY. a rigid body is any solid
object in your world that interracts with other objects. |
|
OBJECT |
In the wrapper documentation, any reference to an "object" refers to the 3D
model used to visually represent a BODY. |
|
VECTOR |
a set of 3 numbers that decribe a position or direction in 3D space. |
|
MATRIX |
a set of (usually 16) numbers that describe rotation and translation in 3D
space. |
|
MASS |
a number that describes the "weight" of a body. |
|
MOMENT OF INERTIA |
a number that describes the how much a body "resists" rotation on a specific
axis. |
...Okay so that was all pretty simple. So back to the matter at hand. When you
use a physics engine, you can't control your object like you ordinarily would
in a game. Normally you store the positions and rotations for all of your
characters / objects, and by changing those variables, you can adjust the
position of objects, and get them to move around. So why can't you do the same
with a physics system like Newton? Let's imagine you have a box. you want to
move the box 10 units to the left. so you manually reset the position of the
box. Now let's imagine that box, after being moved 10 units left, hits a wall.
In order to calculate how the ball should react to hitting the ball, Newton
needs to know the velocity of the ball, where is was a second ago, which way it
was heading, etc. By manually moving the object, Newton has no way to calculate
this important data- and thus your box won't react realistically when it hits
the wall. Instead, you need to leave the actual moving of the objects up to
Newton, and spend your time telling Newton how to move the objects.
But don't worry, Newton provides lots of powerful ways to control your obects
the right way, with physics.
One thing you will notice is that the game loop in a newton program is
deceptively simple. in fact, simple programs can have as little as one command
to handle the physics: NDB_NewtonUpdate. However you will also probably
notice that the init stage of the program is pretty complex (at least at first
glance). This is pretty common in physics simulations... the key is setting up
your bodies properly, with appropriate mass, moment of inertia, and gravity
values. Although this can at first be a bit daunting, it's actually quite easy
to get simple physics working with relatively little confusion. If you haven't
already, have a look at the demos that come with the wrapper. They go in order,
from simple to more complex. You can learn a lot from these demos, please have
a look at them.
Well that's about all I think you need to know to get started. Try compiling
and running the various demos, and then examining the source code to see how
they are done. And don't forget to check the command reference (if you
installed the wrapper properly, pressing F1 should bring up the command
reference) for each command if you're confused. I spent a lot of time on the
command documentation, and I think it's all you really need to understand the
system.
|
|