Important Concepts

advertisement
3.2. INTRODUCTIONTO REAL-TIME PHYSICS
Overview of core principles behind real-time physics systems
Important concepts and aspects of use within game physics engines
Closing velocity, collision direction and contact normal, centre of mass,
springs, coefficient of restitution
Closing Velocity
The closing velocity is the total speed at which two objects are
moving together, calculated by finding the component of
velocity in the direction of one object to the other.
In game physics engines, by convention, it is more common to
use separating velocity (i.e. opposite direction but same
magnitude as closing velocity), given as:
Collision Direction and Contact Normal
The direction in which two objects are colliding is usually called the
“collision normal” or “contact normal.”
If two objects, body 1 and 2, are colliding then, by convention, the collision
normal is given from the first object’s perspective, i.e. from the first body’s
perspective the contact is incoming from the second body, i.e. the normal
is
Centre of Mass
The centre of mass (or “centre of gravity”) is the balance point of an object.
Any separating hyperplane passing through the centre of mass will result
in two volumes of equal mass.
The centre of mass of a sphere or cuboid of uniform density will be located
at the geometric centre point. The centre of mass isn’t always contained
within the object (e.g. a donut).
Springs
Springs have many uses within games,
including obvious examples such as a
car’s suspension, but also for
representing soft and/or deformable
bodies. Springs offer a good means of
modelling cloth, rope, etc.
Video not available in on-line slides
Springs: Hook’s Law
Hook’s law states that the force exerted by a spring is
linearly dependent upon the spring extension or
compression from its rest position, i.e. where l holds the
spring length, and l0 the rest length, and k is the spring
stiffness).
More generally:
Where d is a vector representing the current spring’s
extension.
The force exerted by the spring is equally applied at both
ends of the spring, but in opposite directions, i.e. the
spring acts to pull/push the objects together/apart in
equal measure but in opposite directions.
A problem with (stiff) springs
The application of Hook’s Law can be problematic if applied within an
engine that updates the world using discrete steps. A spring with a high
stiffness factor combined with a large extension/compression will result in
a large applied force. In reality, this force is instantaneous and decreases as
soon as the spring moves towards its resting length.
Using a discrete time step, there is a danger that the force applied over the
whole step will be sufficient to provide a ‘correction’ that results in an even
larger expansion/compression in the opposite direction, which in turn, will
result in an even greater ‘correction’ in the opposite direction, etc.
Coefficient of Restitution
When two objects collide, they compress together, and the deformation of
their surfaces causes forces to build up that bring the objects apart. From
the game physics engine’s point of view this happens instantaneously.
The vast majority of collisions behave in a dampened spring like manner as:
v’s is the separating velocity and c is the coefficient of restitution.
The coefficient of restitution depends on the
materials in collision (different pairs of
material will have different coefficients). If
the coefficient is 1.0, then the objects will
bounce apart with the incident speed. If
zero, then the objects coalesce and travel
together
Resolve order and resting contacts
Impulses
An accelerative force acts to change
velocity over time. In some cases, e.g. a
fast collision, a force is applied over a
very short period of time (resulting in a
change of velocity).
This period of time is too brief to model
within the physics engine, hence an
‘instantaneous’ change in velocity is
known as an impulse.
For forces:
For impulses:
Resolution Order
If an object has two simultaneous contacts, and the engine uses an
iterative approach, then resolving one contact may change the other
contact. The order in which contacts are resolved is important.
A physically plausible approach is to resolve the most severe contact first
(i.e. the contact with the lowest separating velocity or highest
interpenetration) – this also helps avoid unnecessary work as correcting
one contact may entail that other points of contact become
separated/separating (and do not need to be further considered).
Contact 1
Contact 2
Resolution Order
A problem with this approach is when resolving one contact puts another
(previously resolved) contact back into collision.
For most systems, this can be managed by iterating over contacts until all
have been resolved (or an iteration limit reached).
The number of iterations should be at least the number of contacts (to give
them all a chance of getting seen at least once) and can be greater. More
iterations will be needed to resolve a complex, interconnected set of
contact.
Contact interpenetration
increased
Resolution Order
Typically, contacts are resolved for closing velocity and interpretation in
separate passes, thereby permitting a different ordering when selecting
which contact is to be resolved (based on the separating velocity or
interpenetration depth). If the stages are combined then no one single
optimal ordering is likely possible.
Resting Contacts
Consider the simulation of a particle resting on the ground and subject to
gravity. In the first frame the particle accelerates downward, introducing a
non-zero velocity. In the second frame the position is updated, and the
velocity increases again. Now it has begun to interpenetrate with the
ground. The collision detector picks up on the interpenetration and
generates a collision.
The contact resolver looks at the particle, corrects the interpenetration
and applies a collision response from the contact with the ground (based
on closing velocity, material restitutions, etc.). The generated upward
velocity will be small, but it may be enough to be noticed given a long
frame time.
Resting Contacts
One approach (using micro collisions) towards solving the problem is:
Detecting the problem earlier (i.e. smaller velocity to correct) by returning
contacts that are nearly, but not quite interpenetrating.
If the particular object was stationary in the previous frame and the
generated velocity is only due to gravity, then consider it to be a resting
contact, and apply an impulse that will result in a zero separating velocity.
In effect, the series of micro-collisions keep the objects apart.
Resting Contacts
A more physically realistic approach to handling resting
contacts is to apply an upwards force from the ground,
pushing the object back so that its total acceleration in
the vertical direction becomes zero.
Whilst more realistic, this
approach is also considerably
more complex as there may
be multiple points of contact
between the body and the
ground (i.e. some means of
deciding how the resting
forces should be distributed
across the various points of
contact is needed).
Additional Reading
Consult the recommended course text book for:
• Development of a range of force generators, including one for gravity
and another for a drag force generator
• Development of spring based force generators – including basic spring,
anchored spring, elastic bungee generator, buoyancy force generator,
• Development of a cable and rod constraint class
• Development of a simple particle physics engine (based on
implementation of Netwon’s first and second laws) and a massaggregate physics engine
Directed physics reading
Directed reading
• Read Chapter 5 of Game Physics
Engine Development (pp69-79) on
adding forces.
• Read Chapter 6 of Game Physics
Engine Development (pp81-101) on
modelling springs.
Summary
Today we
explored:
 Range of
important
physical
concepts.
 Range of
important
modelling
concepts.
Download