Physics Engines

Overview and aims

By the end of the lecture you will be able to:

  • Describe ways in which physics simulation is used for computer animation and games
  • Understand some of the basic principles behind a physics engine
  • Use 3rd party libraries when writing Processing code.
  • Create create animated Processing sketches using a physics engine

Physics

Simulate objects movement using the laws of physics

Very complex

Use a 3rd Party library

Examples

Half-life 2 was the first game to seriously use a game engine in its gameplay.

This is quite a good description of game physics engines.

Little Big Planet’s physics engine made very inventive gameplay possible
Contour from vanderlin on Vimeo.

There are many other, less game oriented uses of physics out there

Overview and aims

By the end of the lecture you will be able to:

  • Describe ways in which physics simulation is used for computer animation and games
  • Understand some of the basic principles behind a physics engine
  • Use 3rd party libraries when writing Processing code.
  • Create create animated Processing sketches using a physics engine

Objects

Position

Velocity

These two are what we are used to so far, physics engines add more.

Acceleration

Acceleration is the rate of change of velocity, it depends on forces.

(Forces)

Newton’s 3rd Law

f = ma

Force
= Mass
x Acceleration

This equation is the foundation of how a physics engine works. You apply forces to object, which create accelerations and therefore changes of movement.

Objects

Objects therefore have 3 basic parameters:

Position

Velocity

Mass

Objects with higher masses will be less affected by forces.

Forces

There are many types of force used in physics engines, here are some of the most common:

Gravity

Collisions

Damping

Springs

Gravity

Gravity

Gravity is a constant downwards acceleration (force proportional to mass). In the real world it has a value of 9.81m/s2, in physics engines it is often lower to get more extreme action.

Collision

Collision

A collision produces an instantaneous force pushing the two objects apart

Damping

Damping

Damping or friction causes a forces that is in the opposite direction to an objects velocity and therefore tends to slow it down.

Springs

Spring1

Springs

Spring2

Springs can model real springs but are also useful for a whole range of other physics simulation such as cloth, hair etc.

A spring joins two objects and tries to keep them a constant distance, L, appart. If they move apart further than L the spring will create a force proportional to L that will bring them together. If they get too close, it produces a force that pushes them appart.

Sodaconstructor is entirely based on springs, Trear.Physics also uses them a lot.

Types of Object

There are two basic types of object

Particles

Particle

In terms of physics, a particle is an infinitely small dot. Of course you can draw it however you like.

All you need to know about it is its position and mass.

Rigid Bodies

RigidBody

Rigid bodies have a size and shape.

More importantly they can rotate, this adds a whole world of extra complexity to the maths.

They are better models of real objects, but more complex than particles.

Overview and aims

By the end of the lecture you will be able to:

  • Describe ways in which physics simulation is used for computer animation and games
  • Understand some of the basic principles behind a physics engine
  • Use 3rd party libraries when writing Processing code.
  • Create create animated Processing sketches using a physics engine

3rd Party Libraries

Don’t Reinvent the wheel

Stuff you can’t do yourself

Quick and Easy

Open Source

Many of the libraries you will use are open source. Being open source means that you can see the original source code, and change it. This is very useful when you are programming with a library. They are also generally available at no cost (free as in beer).

To find out more about open source, this is the definition:

http://www.opensource.org/docs/osd

Open source is associate with an ideal of freedom in software development as championed by the free software foundation:

http://www.fsf.org/

This is an important part of the social, political and legal issues around software development that you should know about.

TRAER.PHYSICS

Particles and Springs

No Collisions or Rigid Bodies

Box2D

2D only

Collisions and Rigid Bodies

Difficult

Box 2D is a much more powerful engine, but is harder to learn.

For a start it is much more complex, but more importantly it is a C++ library that is wrapped for use in Java, and then Processing. This means that, though there is a lot of documenation, it is split between the C++, java and Processing versions. You will often find youself having to look things up in the C++ docs and convert is to Processing, which can be hard if you are a new programmer.

PMPD

A Physics Engine for PureData and Max/MSP/Jitter

Learning Libraries

There are normally 3 sources of information about a software library. (each is a link to an example).

Manuals

Manuals give an overview of how the library works and how to get started using it.

Reference/API docs

API docs should give detailed information about every class and method in the library and how to use them.

Examples

These will be actual bits of code that demonstrate how to use the library. They could be part of the manual or reference or separate. They are an extremely valuable learning resource.
Generally I would start by reading the manual (or skimming it if its long) to get a general idea of the concepts used in the library.

I would then find an example that is close to what I want to do, look through it to figure out how it works, and then start altering it to do what I want.

I then go to the API reference if I need specific information fot what I want to do.

Using Examples

Good practice

Best way to learn

but

Plagiarism!

Use Examples

Reference Them

Figure out how the libraries work and explain it in your report/comments in the code. In doing so you will learn a lot.

How to get a lot of marks

    /*
     * I got this code from an example here: www.aurl.com/site
     * It uses quaternions to do smooth camera animation.
     * I didn't know anything about quaternions, but I found a resource
     * here: www.quaterniontutorials.com
     * There I found out that quaternions at 4 dimensional vectors that
     * encode the angle and axis of rotation... etc.
     */
    void quaternionCamera()

How to get a less marks

    /*
     * I got this code from an example here: www.aurl.com/site
     * It uses quaternions to do smooth camera animation.
     * I don't really understand how it works
     */
    void quaternionCamera()

How to risk failing

    /*
     * I did this all myself
     */
    void quaternionCamera()
PDF Printer    Send article as PDF to