6
Physics Engine for Simulation R. Gaurav Agarwal B. Tech Information Technology R.M.K. Engineering College, Kavaraipettai, Chennai India E-mail: [email protected] Ph: 9176343852 Abstract- This paper explores the use of Physics Engine in various fields such as in Development of Video Games, Computer Graphics, Film Making (Animation) and Simulations. Most Virtual Reality (VR) applications use libraries called physics engine for enforcing physics laws in their virtual worlds. Although the concept of using physics engines is ideal for development of VR applications, in practice it does impose many limitations. For instance, there are many physical laws created by nature, and one physics engine cannot provide all of them. Each physical law can be implemented differently based on the requirements. Some of them are optimized for fast response whereas others are designed for being precise. Keywords- Physics Engine, Virtual Reality, 3D Engine I. INTRODUCTION A physics engine is computer software that provides an approximate simulation of certain simple physical systems, such as rigid body dynamics (including collision detection/response), soft body dynamics, and fluid dynamics, of use in the domains of computer graphics, video games and film. Their main uses are in video games (typically as middleware), in which case the simulations are in real-time. The term is sometimes used more generally to describe any software system for simulating physical phenomena, such as high-performance scientific simulation. There are generally two classes of physics engines, real-time and high-precision. High-precision physics engines require more processing power to calculate very precise physics and are usually used by scientists and computer animated movies. In video games, or other forms of interactive computing, the physics engine simplifies its calculations and lowers its accuracy so that they can be performed in time for the game to respond at an appropriate rate for gameplay. This is referred to as real-time physics. Computer games use physics engines to improve realism. Hybrid methods are possible that can be created with the help of dedicated hardwares. A clear illustration of the need for physics engine can be seen in Fig. 1. Fig. 1 These are four examples of a physics engine simulating an object falling onto a slope. The examples differ in accuracy of the simulation: 1. No physics 2. Gravity, no collision detection. 3. Gravity and collision detection, no rotation calculations. 4. Gravity, collision detection and rotation calculations. II. BASIS FOR A PHYSICS ENGINE A Physics Engine is a collection of library files which implement complex algorithms to identify and provide approximate simulation of certain simple physical systems, such as rigid body dynamics, soft body dynamics and fluid dynamics. There are many solutions and challenges for a Physics Engine. The different physical systems are as discussed below:

Physics Engine for Simulation

Embed Size (px)

DESCRIPTION

This paper explores the use of Physics Engine in various fields such as in Development of Video Games, Computer Graphics, Film Making (Animation) and Simulations.Most Virtual Reality (VR) applications use libraries called physics engine for enforcing physics laws in their virtual worlds. Although the concept of using physics engines is ideal for development of VR applications, in practice it does impose many limitations. For instance, there are many physical laws created by nature, and one physics engine cannot provide all of them.Each physical law can be implemented differently based on the requirements. Some of them are optimized for fast response whereas others are designed for being precise.

Citation preview

Page 1: Physics Engine for Simulation

Physics Engine for Simulation

R. Gaurav Agarwal B. Tech Information Technology

R.M.K. Engineering College, Kavaraipettai, Chennai

India

E-mail: [email protected] Ph: 9176343852

Abstract- This paper explores the use of Physics Engine in various fields such as in Development of Video Games, Computer Graphics, Film Making (Animation) and Simulations.

Most Virtual Reality (VR) applications use libraries called physics engine for enforcing physics laws in

their virtual worlds. Although the concept of using physics engines is ideal for development of VR applications, in practice it does impose many limitations. For instance, there are many physical laws created by nature, and one physics engine cannot provide all of them.

Each physical law can be implemented differently based on the requirements. Some of them are optimized for fast response whereas others are designed for being precise.

Keywords- Physics Engine, Virtual Reality, 3D Engine

I. INTRODUCTION

A physics engine is computer software that

provides an approximate simulation of certain simple

physical systems, such as rigid body dynamics

(including collision detection/response), soft body

dynamics, and fluid dynamics, of use in the domains

of computer graphics, video games and film. Their

main uses are in video games (typically as

middleware), in which case the simulations are in

real-time. The term is sometimes used more generally

to describe any software system for simulating physical phenomena, such as high-performance

scientific simulation.

There are generally two classes of physics

engines, real-time and high-precision. High-precision

physics engines require more processing power to

calculate very precise physics and are usually used by

scientists and computer animated movies. In video

games, or other forms of interactive computing, the physics engine simplifies its calculations and lowers

its accuracy so that they can be performed in time for

the game to respond at an appropriate rate for

gameplay. This is referred to as real-time physics.

Computer games use physics engines to improve

realism.

Hybrid methods are possible that can be created

with the help of dedicated hardwares.

A clear illustration of the need for physics engine

can be seen in Fig. 1.

Fig. 1 These are four examples of a physics engine simulating an

object falling onto a slope. The examples differ in accuracy of the simulation:

1. No physics

2. Gravity, no collision detection.

3. Gravity and collision detection, no rotation

calculations.

4. Gravity, collision detection and rotation calculations.

II. BASIS FOR A PHYSICS ENGINE

A Physics Engine is a collection of library files which implement complex algorithms to identify and

provide approximate simulation of certain simple

physical systems, such as rigid body dynamics, soft

body dynamics and fluid dynamics.

There are many solutions and challenges for a

Physics Engine. The different physical systems are as

discussed below:

Page 2: Physics Engine for Simulation

A. Rigid-body dynamics

Rigid body dynamics is the study of the motion of rigid bodies. Unlike particles, which move

only in three degrees of freedom, rigid bodies occupy

space and have geometrical properties, such as a

center of mass, moments of inertia, etc., that

characterize motion in six degrees of freedom (three

directions plus rotation in three directions). Rigid

bodies are also characterized as being non-

deformable, as opposed to deformable bodies. As

such, rigid body dynamics is used heavily in analyses

and computer simulations of physical systems and

machinery where rotational motion is important, but

material deformation does not have a significant effect on the motion of the system.

The Rigid-body dynamics basically must

deal with:

Rigid body linear momentum Rigid body angular momentum

Angular momentum and torque

B. Soft body dynamics

Soft body dynamics is a field of computer

graphics that focuses on visually realistic physical

simulations of the motion and properties of

deformable objects (or soft bodies). Unlike in

simulation of rigid bodies, the shape of soft bodies

can change, meaning that the relative distance of two

points on the object is not fixed. While the relative

distances of points are not fixed, the body is expected

to retain its shape to some degree (unlike a fluid).

The scope of soft body dynamics is quite broad,

including simulation of soft organic materials such as

muscle, fat, hair and vegetation, as well as other

deformable materials such as clothing and fabric.

Generally, these methods only provide visually

plausible emulations rather than accurate

scientific/engineering simulations, though there is

some crossover with scientific methods, particularly

in the case of finite element simulations. Several

physics engines currently provide software for soft-

body simulation. This simulation can be done by

using a variety of approaches:

Mass-spring models

Finite element simulation

Energy minimization methods

Shape matching

Rigid-body based deformation

C. Fluid Simulation

Fluid simulation is an increasingly popular

tool in computer graphics for generating realistic

animations of water, smoke, explosions, and related

phenomena. Given some input configuration of fluid

and scene geometry, a fluid simulator evolves the

motion of the fluid forward in time, making use of

the (possibly heavily simplified) Navier-Stokes

equations which describe the physics of fluids. In

computer graphics, such simulations range in

complexity from extremely time-consuming high

quality animations for film & visual effects, to simple

real-time particle systems used in modern games.

Some techniques for liquid simulation is as follows:

Eulerian grid-based methods

Smoothed particle hydrodynamics (SPH)

methods

Vorticity-based methods

Lattice Boltzmann methods

III. CHALLENGES AND APPROACHES

The various challenges for a Physics Engine

is handling deformable objects and simulating soft-

body dynamics.

Fig. 2 Depicting the compression and expansion phases of a

collision between two solid bodies.

One other difficulty is in calculating Time-

of-impact (TOI) problems of real world.

Some of the solutions to these problems are

use of Ragdoll physics (a form of procedural

animation).

To solve the TOI problems two approaches

are suggested.

One solution is based on Brian Mirtich’s

concept of Conservative Advancement. The

linear convex cast or the Swept Sphere as

described by Gino van den Bergen is an

specific case of this.

Page 3: Physics Engine for Simulation

A swept sphere is a 3D object that can

be created by pulling, or sweeping, a sphere

along a path, leaving a trace that kind of

resembles the shape of toothpaste when it comes

out of the tube. While sweeping, the radius of the

sphere may be changed, and the path does not

need to be a straight line. Quite often, though,

swept spheres are used in collision detection as

an alternative to bounding boxes. In these cases,

most of the time the path is a straight line and the

radius stays fixed. The object that is created by

sweeping a sphere like that is a cylinder with

hemispheres, which have the same radius as the

cylinder, attached to both ends. Detecting if a

point is within this object is computationally

quite simple, often easier than doing this with a

bounding box.

The other solution is featured based, and

calculates the TOI per feature pair. In

particular, Redon’s Algebraic Continuous

Collision Detection method.

IV. APPLICATIONS

A. Scientific Engines

Physics engines have been commonly used

on supercomputers since the 1980s to simulate the

flowing of atmospheric air and water, in order to

predict weather patterns. This is known as

computational fluid dynamics modeling, where

particles of air are assigned a force vector, and these

combined forces are calculated across vast regions of

space to show how the overall weather patterns will

circulate. Due to the requirements of speed and high

precision, special computer processors known as

vector processors were developed to accelerate the

calculations.

Generally weather prediction is still an

inaccurate science because the resolution of the

simulated atmosphere is not detailed enough to match

real-world conditions, and small fluctuations not

modeled in the simulation can drastically change the

predicted results after several days.

Similar fluid dynamic modeling is also commonly

used for designing new types of aircraft and

watercraft, and can provide engineers the information

that used to be obtained solely from wind tunnel

testing.

Tire manufacturers use physics simulations

to examine how new tire tread types will perform

under wet and dry conditions, using new tire

materials of varying flexibility and under different

levels of weight loading.

Electronics manufacturers use fluid dynamic

modeling to examine how cooling air will flow

through the computer case, to locate thermal hotspots that may need additional cooling.

B. Gaming Engines

In most computer games, speed of

simulation is more important than accuracy of simulation. Typically most 3D objects in a game are

represented by two separate meshes or shapes. One of

these meshes is a highly complex and detailed shape

which the player sees in the game, for example a vase

with elegant curved and looping handles. However,

for purposes of speed, a second highly simplified

invisible mesh is used to represent the object to the

physics engine. To the physics engine, the object may

be processed as nothing more than a simple tall

cylinder. It is therefore impossible to insert a rod or

fire a projectile through the handle holes on the vase, because the physics engine does not know the

handles exist and only processes the rough cylindrical

shape. The simplified mesh used for physics

processing is often referred to as the collision

geometry. This may be a bounding box, sphere, or

convex hull. Engines that use bounding boxes or

bounding spheres as the final shape for collision

detection are considered extremely simple. Generally

a bounding box is used for broad phase collision

detection to narrow down the number of possible

collisions before costly mesh on mesh collision

detection is done in the narrow phase of collision detection.

// Object-to-object 2D bounding-box collision

detector:

short int Sprite_Collide(sprite_ptr object1, sprite_ptr

object2)

{

int left1, left2; int right1, right2;

int top1, top2;

int bottom1, bottom2;

left1 = object1->x;

left2 = object2->x;

right1 = object1->x + object1->width;

right2 = object2->x + object2->width;

Page 4: Physics Engine for Simulation

top1 = object1->y;

top2 = object2->y;

bottom1 = object1->y + object1->height;

bottom2 = object2->y + object2->height;

if (bottom1 < top2) return(0); if (top1 > bottom2) return(0);

if (right1 < left2) return(0);

if (left1 > right2) return(0);

return(1);

};

A fairly simple algorithm for 2-dimensional

objects is as given above. Below Fig. 3 depicts how a physics engine helps in improving the gaming

experience by making it realistic.

Fig. 3 a) Depicting boxes placed on top of planks.

Fig. 3 b) Boxes thrown into air due to an explosion, simulated with help of a Physics Engine.

An alternative to using bounding box-based

rigid body physics systems is to use a finite element-

based system. In such a system, a 3-dimensional,

volumetric tessellation is created of the 3D object.

The tessellation results in a number of Finite

Elements which represent the object's physical

properties (toughness, plasticity, volume

preservation, etc...). Once constructed, the finite

elements are used by a finite element solver to model

the stress within the 3D object. The stress can be used

to drive fracture, deformation and other physical

effects with a high degree of realism and uniqueness. As the number of elements in such a system is

increased, its ability to model the physical behavior

of the object increases. The visual representation of

the 3D object is altered by the finite element system

through the use of a deformation shader which either

runs on the CPU or on the GPU. Finite Element-

based systems have been impractical for use in games

in the past due to the performance overhead as well

as the lack of tools to create finite element

representations out of 3D art objects. With the advent

of high performance CPUs and GPUs as well as tools

to rapidly create the volumetric tessellations, it is now practical to have real-time finite element

systems in games. The first game to use a real-time

finite elements-based physics system was "Star Wars:

The Force Unleashed" (TFU) by LucasArts

Entertainment. TFU used the newly-created Digital

Molecular Matter (DMM) physics engine by Pixelux

Entertainment for the deformation and destruction

effects of wood, steel, flesh and plants. The

deformation and fracture performed by the DMM

solver used an algorithm developed by Dr. James

O'Brien as a part of his PhD thesis "Graphical Modeling and Animation of Brittle Fracture".

In the real world, physics is always active.

There is a constant Brownian motion jitter to all

particles in our universe as the forces push back and

forth against each other. For a game physics engine,

such constant active precision is unnecessary and a

waste of the limited CPU power. For example, in the

3D virtual world Second Life, if an object is resting on the floor and the object does not move beyond a

certain minimal distance in about two seconds, then

the physics calculations are disabled for the object

and it becomes frozen in place. It remains frozen

until a collision occurs with some other actively

physical object, and that reactivates physics

processing for the object. This freezing of stable non-

moving objects allows the physics engine to conserve

processing power and increase the framerate of other

objects currently in motion, but can lead to unusual

problems such as a huge slow pendulum freezing in place on the upswing, as it slows down and starts to

reverse direction. Often this process of deactivating

non-moving objects is referred to as "sleeping"; and

some physics engines provide the ability to prevent it,

ensuring such anomalies never occur, at the expense

of always consuming processing power.

Page 5: Physics Engine for Simulation

The primary limit of physics engine realism

is the precision of the numbers representing the

position of an object and the forces acting on that

object. When the precision is too low, errors can

creep into the calculations due to rounding, causing

an object to overshoot or undershoot the correct position. These errors are compounded in situations

where two free-moving objects are fitted together

with a precision that is greater than what the physics

engine can calculate. This can lead to an unnatural

buildup energy in the object due to the rounding

errors, that begins to violently shake and eventually

blow the objects apart. Any type of free-moving

compound physics object can demonstrate this

problem, but it is especially prone to affecting chain

links under high tension, and wheeled objects with

actively physical bearing surfaces. Higher precision

reduces the positional/force errors, but at the cost of greater CPU power needed for the calculations.

C. Other Uses

1) Surgery Simulation:

Surgery simulations are of

significant value in medical training as they provide a

less costly mean of training new surgeons. The

quality of a surgery simulation is defined by how

realistic it is in a physical sense. These physics

aspects however have little to do the high-level

functionalities of the application. In particular, laws

are needed for simulating cutting and skin deformation.

Fig. 4 Class Hierarchy of Physical Objects in Surgery Application.

2) Virtual Desktop – A BumpTop:

Despite the metaphor, current

virtual desktops bear little resemblance to the look or

feel of real world desktops. A workspace in the

physical world typically has piles of documents.

Binders and other objects arranged in a way that

provides considerable subtle information to the

owner. Adding realism to the virtual desktop such

that certain valuable characteristics of the real world can be applied using physics engines is aim of

creating a BumpTop.

Fig. 5(a) Typical virtual desktop with structured organization. (b)

Real desk, where items are casually organized. (c) A BumpTop

prototype with piles as the fundamental organizational object, and

physical simulation affording casual, potentially more realistic interaction.

V. HARDWARE UNITS

A physics processing unit (PPU) is a

dedicated microprocessor designed to handle the calculations of physics, especially in the physics

engine of video games. Examples of calculations

involving a PPU might include rigid body dynamics,

soft body dynamics, collision detection, fluid

dynamics, hair and clothing simulation, finite

element analysis, and fracturing of objects. The idea

is that specialized processors offload time consuming

tasks from a computer's CPU, much like how a GPU

(Graphics Processing Unit) performs graphics

operations in the main CPU's place.

The first dedicated Physics Processing Unit

(PPU) from Ageia (later merged into nVidia), called

PhysX, which functions in a similar manner to the

Graphic Processing Unit (GPU) in a graphics card -

off-loading the majority of the physics processing

weight off the CPU and into a dedicated processor.

The unit was most effective in accelerating particle

systems. Only a small performance improvement was

measured for rigid body physics.

Page 6: Physics Engine for Simulation

Fig. 6 Ageia’s Physics Processing Unit (PPU).

GPGPU ("General Purpose processing on

Graphics Processing Unit") is another promising

approach for realtime physics engines, including rigid

body dynamics. ATI and NVIDIA provide rigid body

dynamics on their latest graphics cards.

NVIDIA's GeForce 8 Series supports a

GPU-based Newtonian physics acceleration

technology named Quantum Effects Technology -

which will compete directly with the PhysX PPU

hardware. NVIDIA provides an SDK Toolkit for

what they call CUDA (Compute Unified Device

Architecture) technology that offers both a low and

high-level API to the GPU. Few technical details are

available about the physics side of it, and it is not yet

clear whether this is part of Havok FX SDK, and/or

nVidia PhysX SDK, or a completely separate engine.

Fig. 7 NVIDIA’s GeForce 8800Ultra.

ATI & AMD offer a similar SDK for their

ATI-based GPUs and that SDK and technology is

called CTM (Close to Metal) which provides a thin

hardware interface. AMD has also announced the

AMD Stream Processor product line which combines

a CPU and GPU technology on one chip.

VI. FUTURE WORK

A Physics Engine can be used to solve

certain real-world problems where collision can be

detected and provide a response to it. These engines

can thereby, be used to detect collisions well in

advance using a complex set of inputs. Hence, the

simulation can be used for providing a mechanism to

trigger a response for the possible collision.

REFERENCES

[1] Collision Detection with Swept Spheres and

Ellipsoids by Jorrit Rouwé from

http://www.three14.demon.nl/

[2] Continuous Collision Detection and Physics

by Erwin Coumans, Sony Computer

Entertainment.

[3] http://www.howstuffworks.com/

[4] Role of Extensible Physics Engine in

Surgery Simulations by Saeid Nourian,

Xiaojun Shen and Nicolas D. Georganas.

[5] Keepin’ It Real: Pushing the Desktop

Metaphor with Physics, Piles and the Pen by

Anand Agarwala and Ravin Balakrishnan.

[6] www.wikipedia.com

[7] http://www.gamedev.net/