Game Development Reference
In-Depth Information
Having brought up numerous complications and then promptly set them
aside, we are now ready to present the basic equations for Euler integration
of position, velocity, and acceleration.
Euler Integration of Acceleration and Velocity
a k = f k /m
(Newton's second law),
v k+1 = v k + h a k
(integrate acceleration),
p k+1 = p k + h v k+1
(integrate velocity).
These are key operations, so let's see how they might get implemented
in C++. The code in Listing 12.7 is a bit easier to read than the equations,
since the order of operations makes the subscripting unnecessary.
s t r u c t
P a r t i c l e
{
V e c t o r 3
po s ;
/ /
world
p o s i t i o n
o f
c e n t e r
o f
mass
V e c t o r 3
l i n V e l ;
/ /
v e l o c i t y
V e c t o r 3
f o r c e ;
/ /
c u r r e n t
f o r c e s
f l o a t
mass ;
/ /
mass
o f
o b j e c t
/ /
Take
a
s i m p l e
E u l e r
s t e p
f o r w a r d
i n
t i m e
by
t h e
t i m e
s t e p
d t
v o i d
e u l e r I n t e g r a t e ( f l o a t
d t )
{
V e c t o r 3
a c c e l e r a t i o n
=
f o r c e
/
mass ;
l i n V e l
+=
a c c e l e r a t i o n
d t ;
p o s
+=
l i n V e l
d t ;
}
}
Listing 12.7
Simple Euler integration
12.6.4 Integration of Rotation
Now let's say a few words about integration of 3D rotational data. What
is the equivalent of p k+1 = p k +h v k for rotation? First, let's present some
well-known results from mechanics concerning the relationship between an-
gular velocity and the derivative of orientation values.
Consider an arbitrary point r fixed on a body that is rotating about
its center of mass at an instantaneous angular velocity ω. We assume the
coordinate space used to describe r has its origin at the body's center of
mass, but the axes do not rotate with the body. (In this topic, we say
that we are expressing the coordinates of the point in “upright space.”
These coordinates are also sometimes called “center of mass coordinates.”)
 
Search WWH ::




Custom Search