Game Development Reference
In-Depth Information
/ / t h e u s e r c o n s t r a i n t s .
v e c t o r
<
C o n s t r a i n t R o w
>
c o n s t r a i n t R o w s ;
c o l l i s i o n D e t e c t i o n ( c o n s t r a i n t R o w s ) ;
p r o c e s s A p p l i c a t i o n C o n s t r a i n t s ( c o n s t r a i n t R o w s ) ;
/ /
S o l v e
f o r
v e l o c i t i e s
which
s a t i s f y
t h e
c o n s t r a i n t s
s o l v e C o n s t r a i n t s ( c o n s t r a i n t R o w s ) ;
/ / Now
r e a l l y
update
t h e
p o s i t i o n s ,
based
on
t h e
computed
/ /
v e l o c i t i e s
t h a t
s a t i s f i e d
t h e
c o n s t r a i n t s
i n t e g r a t e V e l o c i t i e s ( ) ;
}
Listing 12.6
Pseudocode for a velocity-based physics simulation
The resulting matrix problem is not a standard system of linear equa-
tions; rather, it is a system of inequalities. For example, if a collision law
predicts that two objects should bounce away with a certain velocity, that
velocity is interpreted as a minimum velocity. If some other constraint (say
one object is being pulled away by a spring) causes the objects to bounce
away faster than predicted by the collision law, this is not considered a
violation of the contact constraint. This type of system can be put into a
standard form, known as the linear complimentary problem (LCP).
Various implementations of velocity-based methods borrow ideas from
penalty and sequential impulse simulations, so it can sometimes be di
cult
to classify a simulation as strictly one or the other. The incremental ma-
trix solvers that are used to solve the linear complimentary problem make
small adjustments to the velocity of the bodies; these adjustments can be
physically interpreted as a series of impulses. Thus, there are some similar-
ities between a velocity-based solver and a sequential impulse solver. The
distinction is that in a sequential impulse solver, the collision law is applied
multiple times. In a velocity-based simulation, the collision law is applied
once in order to determine the ideal relative velocity, and then this velocity
is treated as a goal or constraint. Some velocity-based solvers, notably the
Open Dynamics Engine, allow constraints to be treated as “soft,” using
techniques similar to penalty-based methods.
12.6.3 Euler Integration
Every physics engine needs to be able to “step forward” in time. We assume
that we know the position and velocity values (both linear and angular) at
some time t, and we want to determine their values at some future time
t+∆t. The outcome will depend on the net forces experienced by the object,
and, of course, the initial velocity at time t. The forces themselves may vary
depending on the position or the velocity of the body. For example, a body
connected to a fixed point by a spring experiences forces that vary based
on the position of the body, and a body moving through a fluid such as air
Search WWH ::
Custom Search