23
3.2. INTRODUCTION TO REAL- TIME PHYSICS Overview of core principles behind real-time physics systems

3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

Embed Size (px)

Citation preview

Page 1: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

3.2. INTRODUCTION TO REAL-TIME PHYSICS

Overview of core principles behind real-time physics systems

Page 2: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

IMPORTANT CONCEPTSImportant concepts and aspects of use within game physics engines

The concepts in this section will be tied together in later lectures.

Page 3: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

PHYSICS CONCEPTSClosing velocity, collision direction and contact normal, centre of mass, springs, coefficient of restitution

Page 4: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

Closing VelocityThe 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:

Page 5: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

Collision Direction and Contact NormalThe 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

Page 6: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

Centre of MassThe 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).

Page 7: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

SpringsSprings 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.

Page 8: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

Video not available in on-line slides

Page 9: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

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.

Aside: Real springs are subject to Hook’s law constrained by their limits of elasticity. In game springs can be assumed to have arbitrary wide limits of elasticity.

Page 10: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

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.

Page 11: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

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

Page 12: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

IMPORTANT SIMULATION ASPECTSResolve order and resting contacts

Page 13: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

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:

Aside: Within the physics engine, impulses will not be accumulated, but rather

will be instantaneously applied to update a velocity. Normal forces will be accumulated and applied at the end of the simulation step to produce

an updated velocity, position, etc.

Page 14: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

Resolution OrderIf 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

Page 15: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

Resolution OrderA 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

Page 16: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

Resolution OrderTypically, 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.

Aside: The number of iterations used to resolve interpenetration might not necessarily be the same as the number used to resolving collisions

Page 17: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

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.

Page 18: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

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.

Page 19: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

Resting ContactsA 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).

Page 20: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

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 mass-aggregate physics engine

Page 21: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

DIRECTED READINGDirected physics reading

Directed

reading

Page 22: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

Directed 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.

Page 23: 3.2. I NTRODUCTION TO R EAL - TIME P HYSICS Overview of core principles behind real-time physics systems

Summary

To do:Read the directed

reading.

Consider if you might

wish to develop your

own physics engine as

your project.

Today we explored:

Range of important physical concepts.

Range of important modelling concepts.