[size="3"][b]Physical Simulation[/b][/size]

[b]Two tools - Analytical and Numeric methods[/b]

In a few years, an important gap has been filled by the video game industry. Now the GPU and hardware computation have replaced the CPU and software emulation. But several progress axes remain very little explored by video games, like AI or physical simulation, though paradoxically these fields were studied first at the beginning of the computer age.

Let us take the case of the physical simulation. Before the middle of the twentieth century, physicians have set up a lot of analytical equations for many classic physical problems. But unfortunately, solutions to these equations resolved only simple cases. For example, what is called [i]Strength of Materials[/i] has resolved some problems to calculate deformations, but applications have a small scope (i.e. cases of study). When computer started being used, analytical equations allowed finding approximate solutions; it was the beginning of the [i]numerical computation[/i].

The use of numerical methods enables the engineer to expand his ability to solve practical design problems. He may now treat real shapes as distinct from the somewhat limited variety of shapes from simple analytic solution. In the same way, he needs no longer force a complex loading system to fit a more regular load configuration in order to conform to a purely academic situation. Numerical analysis thus provides a tool with which the engineer may feel freer to look for the solution of problems that he faces in practice.

[b]Two pitfalls - Real-time and Generic solutions[/b]

The application of these engineering tools cannot be adapted to the video games because:

[list][*]On one side, interactive virtual world must simulate a large variety of physical problems, each problem being different. For example, the player throws a stone in a closed room and the stone moves according to the starting velocity, the geometry of the room and player's orientation and position. Moreover this depends on random events like stranger compounds interfering. Analytical solution of the stone throw differs each time, so the only choice consists in computing the displacement step by step. Consequently, setting up an analytical formula of a physical phenomenon reduces the computation time due to the factorisation, but this formula is very difficult to elaborate.[*]On the other side, the numerical computation, often iterative, is rarely possible in real-time. The computation takes several minutes, sometimes hours or days to solve engineering problems. It is then impossible to achieve simulation in real-time especially for video games.[/list][center] [attachment=3520:PITFALLS.GIF] [/center]

[b]Two notions - Realistic and Real solutions[/b]

The last aspect of the physical simulation is the duality between the realistic appearance and the real. A real solution is an correct solution. In such case we admit that a solution is correct when the difference between the theory and the solution found is negligible in comparison with the dimension of the physical problem.

A realistic solution seems to be physically correct. It is a relative notion, which depends on the observer. If a player throws a stone, and if the reality differs from the solution by several centimetres, the player has seen the stone bouncing from the wall/s and he has admitted that the path is right.

That is why particle systems are very used in video games. In this case, the simulation is not physically correct but is realistic. Simplifying the reality is not a problem if the results are realistic.

[size="3"][b]Objectives of this article - Study the deformation of solids in real-time[/b][/size]

In this technical article, I have opted to concentrate on elements that haven't been really studied in the game industry. So I have selected the deformation of solids i.e. steel or concrete structures. Deformations of solids could occur in many occasions during a game for example when a car crashes into a wall, or the player fires a rocket into a structure.

[b]Main specifications[/b]

I am going to explain how to build a simulation with the following features:

[list][*]In real-time;[*]Obtain realistic solution;[*]Manage a large variety of shapes for the body;[*]Apply various boundary conditions.[/list][center][attachment=3521:specification.gif]

[b]Specifications of the simulation[/b]

[/center]

Besides the only tolerated hypothesis is that the deformations always occur in the elastic domain, i.e. there is a linear relation between the applied forces and the displacements.

I know the specifications are ambitious and seem to be contradictory. Nevertheless, I will explain further how to mix multidisciplinary fields to achieve my goals:

[list][*][alink='1']Preliminary discussion[/alink]. Some technical terms and hypotheses are defined.[*][alink='2']Finite Element Method[/alink]. I present the core method used to meet the specifications.[*][alink='3']Adaptation of the FEM[/alink]. This method, like a lot of others, must be adapted.[*][alink='4']Appendix[/alink]. Relevant links and resources about the subject.[/list] [b]Foreword[/b]

A project, called Hyperion Project (see the part bellow), illustrates the subject of the article. Moreover all the sources are licensed under LGPL (Lesser General Public License). See [url="http://www.gnu.org/"]http://www.gnu.org[/url] for more information about the license.

I let an important liberty on the complete source:

[list][*]to prove that the explained method is not so complex;[*]to promote the method in the video games industry.[/list] [size="3"][b]The Hyperion Project[/b][/size]

[b]Component Technology[/b]

The notion of binary components and oriented object design are one of the interesting subjects in the programming and conception field. During the year 1999, I worked for an industrial software company specialised in real time and embedded systems. There, I developed a mechanism close to Component Object Model by Microsoft and adapted for Unix, Windows and VxWorks operating systems.

[center][attachment=3522:HYP.LOGO.HYPPATTERN.GIF][/center]

This system was re-adapted for the kernel of Hyperion to obtain a set of classes, which allows to create very quickly Hyperion components. This new framework has been called Hyperion Pattern. This framework has been designed for environments supporting dynamic libraries.

[b]Library of specialised components[/b]

With the help of this framework, the applications could be not only object oriented but also could be component oriented. Moreover I am open-minded to many aspects of engineering subjects, especially analytical mathematics and mechanical engineering. So in order to test on a large scale the new developed framework, I created the first components specialised in the physical simulation in real-time. The long-term prevision is to set a coherent and dense library of components in the same way as Direct X, which is specialised in the multimedia.

[center][attachment=3523:HYP.LOGO.SLOGAN.GIF]

[/center]

[b]Ephydryne components[/b]

The Ephydryne Components compute the deformation of solids and so realise the specifications explained in the previous part. The Ephydryne package defines a set of interface and implements the necessary components to make all the necessary computing steps.

[center][attachment=3524:HYP.LOGO.EPHYDRYNE.GIF][/center]

[b]State of the realization[/b]

To prove the capabilities of the Ephydryne components and the viability of the chosen solutions, two client applications have been developed:

[list][*]HypDev;[*]HypVisual.[/list][center][attachment=3525:HYP.LOGO.HYPDEV.GIF][nbsp][nbsp][nbsp][nbsp][attachment=3526:HYP.LOGO.HYPVISUAL.GIF][/center]

HypDev and HypVisual are considered as demonstration products because the Ephydryne Components are the core of the project.

Go to [url="http://sourceforge.net/projects/ephydryne/"]http://sourceforge.n...ects/ephydryne/[/url] to download sources and documentation.

[size="5"][b][aname='1']Preliminary discussion[/b][/size]

[size="3"][b]Some definitions[/b][/size]

[b]Hypothesis of continuity[/b]

The basic structure of the matter is characterized by non-uniformity and discontinuity attributable to its various subdivisions: molecules, atoms and subatomic particles. The concern in this document is to replace the actual system of particles with a continuous distribution of matter. There is the clear implication in such an approach that any small volumes which could be considered here are enough to contain a lot of particles. Random fluctuations in the properties of the material are not considered to be important.

[b]Definition of the studied system[/b]

The studied system is a [i]solid[/i], which is sometimes referred to by the name of [i]body[/i]. Some of the main abilities of a solid are:

[list][*]to maintain its shape without need of a container;[*]to resist continuous shear and tension.[/list] [b]Mechanics of solids[/b]

In contrast with rigid body statics and dynamics, which treat the external behaviour of bodies, the [i]mechanics of solids[/i] are concerned with the relationship of external effects (i.e. forces and moments) to internal stresses and strains.

[b]Types of strains[/b]

External forces actions on a body may be classified as surface forces and body forces. A surface force is of the concentrated type when it acts at a point; a surface force may also be distributed uniformly or non-uniformly over a finite area. Body forces act on volumetric elements rather than surfaces and are attributable to fields such as gravity and magnetism.

[b]Units[/b]

All the units follow the international standard (IS).

Data | Dimension | Symbol |

Length | Meter | m |

Force | Newton | N |

Pressure | Pascal | Pa |

Masse | Kilogram | kg |

[center][attachment=3527:system_rhanded.gif][b]

Right-handed system[/b]

[/center]

[size="3"][b]Which method to use?[/b][/size]

[b]Aim of the project[/b]

According to the first part of this document, the first target of the Hyperion Project is to calculate the deformations of a solid with a distribution of forces. As above the main specifications impose the following conditions for the simulation:

[list][*]Real-time;[*]Realistic solution[*]Generation of a large variety of shapes for the body;[*]Application of usual boundary conditions;[*]Elastic hypothesis[/list] [b]Analytical vs. Numerical methods[/b]

So what are the classical means to calculate the system deformations? To succeed in this task, classic analytical methods used in the mechanics of solids are limited. Strength of Materials has resolved some problems but they are too specific. Navier relations for plates and shells are also not enough generic. In conclusion, the analytical methods seem to be less adapted than the numerical method.

Nowadays, the most powerful method to resolve physical problems is a numerical method called the Finite Element Method (FEM).

[size="5"][b][aname='2']The Finite Element Method (FEM)[/b][/size]

[size="3"][b]Introduction[/b][/size]

The efficient finite element method originates in the 1950's and with the widespread use of the digital computers has since gained considerable favour compared to other numerical approaches. This method allows to foresee stress and strain in an engineering structure, with unprecedented ease and precision. In this article, we only discuss about continuum mechanics and its applications in the FEM.

The general procedure of the finite element and conventional [i]structural matrix method[/i] are similar. Consequently, I am going to present this method first as it easier to understand than the FEM.

[size="3"][b]Structural Matrix Method[/b][/size]

This method allows to calculate the displacement and the stress in a structure usually made of beams. The structure is idealized as an assembly of structural members connected to one another at joints or [i]nodes[/i] at which the resultants of the applied forces are assumed to be concentrated.

Employing the mechanics of solids or the elasticity approach, the stiffness properties of each element can be ascertained. Equilibrium and compatibility considered at each node lead to a set of algebraic equations, in which the unknowns may be nodal displacements, internal nodal forces, or both, depending upon the specific method used.

In the displacement or so-called [i]direct stiffness method[/i], the set of algebraic equations involves the nodal displacements. In the [i]force method[/i], the equations are expressed in terms of unknown internal nodal forces. A [i]mixed method[/i] is also used, in which the equations contain both nodal displacements and internal forces.

[b]A simple model[/b]

One of the simplest cases from the structural matrix method is to idealize each member of the structure by a spring. The stability of an elastic spring is characterized by its constant of rigidity [attachment=3528:IMAGE004.GIF]. This constant is used to calculate the return force [attachment=3529:IMAGE006.GIF].

[center][attachment=3530:IMAGE008.GIF]

[b]Spring fixed at its base[/b]

[/center]

The relation linking displacement and force is:

[center][attachment=3531:IMAGE010.GIF]

[attachment=3532:IMAGE012.GIF] is the relative length variation of the spring.

[left]When two axial forces are applied to the spring, the stability commands that:

[/left][/center]

[center][attachment=3533:IMAGE014.GIF]

[attachment=3534:IMAGE016.GIF]are respectively the forces and the displacements for each node.

[/center]

[center][attachment=3535:IMAGE018.GIF][b]

Axial forces applied to the spring[/b]

[/center]

A matrix relation could replace these equations:

[attachment=3536:IMAGE020.GIF]

The matrix, which links the force vector and the displacement vector, is called the [i]stiffness matrix[/i] of the spring.

We could assemble several elements modelized with springs to construct more complex structures, like this following example.

[center][attachment=3537:IMAGE022.GIF]

[b]Structure made of three spring-elements[/b]

[/center]

After assembling the three stiffness matrices of the element, a linear relation that links the forces and the displacement is found:

[center][attachment=3538:IMAGE024.GIF]

[attachment=3539:IMAGE026.GIF]

[attachment=3540:IMAGE028.GIF]

S is the section of the element

E is the Young modulus of the material

[/center]

Notice that the problem has 6 unknowns (3 nodes free along the x and the y axes), which are organized in the [attachment=3541:IMAGE012.GIF]vector.

To resolve the problem, we apply boundary conditions: the nodes 1 and 3 are fixed in the three directions. After resolving the displacements of the node 2, the reaction forces, which are applied on the nodes 1 and 3, are found.

Refer to the [alink='4']bibliography[/alink] for more information about the structural matrix method.

[b]General relation[/b]

The fundamental relation that must be remembered is the matrix relation [attachment=3538:IMAGE024.GIF]. As we are going to see, with the finite element method, theses relations could be computed for any continuous body and so not only for structures.

[size="3"][b]Principles of the FEM[/b][/size]

In contrast in the foregoing approaches, in the finite element method, the solid continuum is divided into a finite number of elements, connected not only on their nodes, but along the hypothetical inter-element boundary as well. In addition therefore to nodal compatibility and equilibrium, as in conventional structural analysis, it is clear that compatibility must also be met along the boundaries between the elements. Because of this, the element stiffness can only be approximately determined in the finite element method.

As in the structural analyses previously cited, there are several approaches for the FEM. In this article, we treat only the commonly employed finite element displacement approach.

[b]Theory[/b]

Let us take a stress analysis problem for a body under certain loading conditions.

[center][attachment=3542:theory_problem.jpg]

[b]Problem characterized by its geometry, its force loading and its boundary conditions[/b]

[/center]

The normal analytical procedure would involve taking an extremely small box element of dimensions (dx, dy, dz) each tending to zero and then writing down the equations of equilibrium and compatibility for this element.

[center] [attachment=3543:theory_equations.jpg][/center]

Then we would try to obtain a solution for the stress distribution in the body under the specified boundary conditions using the integration techniques over the entire body. The drawback of this method is that for complicated bodies it will be very difficult and sometimes impossible to carry out the integration procedure over the entire body.

The solution to such problems can be obtained very effectively and to a high degree of accuracy using Finite Element Method. Instead of assuming a displacement field for the entire body, we divide the body into smaller elements and assume a displacement field for these individual elements. The original body or structure is then considered as an assemblage of these elements. Once again, these elements are connected to each other at joints called [i]nodes[/i] or [i]nodal points[/i] to form the entire structure. These individual elements are now analysed. Instead of carrying out integration over the entire body consisting of infinite number of elements of infinitesimally small dimensions, we carry out summation over the body consisting of finite number of elements of finite dimensions. By this iterative approach, the method can be effectively implemented in a computer program.

The equations of equilibrium for the entire structure or body are then obtained by combining the equilibrium equation of each element so that the continuity is ensured at each node. The necessary boundary conditions are then imposed and the equations of equilibrium are solved to obtain the required variables such as stress, strain, temperature, distribution or velocity flow depending on the application.

[center][attachment=3544:fig1.png]

[b]The solution, divide to rule[/b]

[/center]

We must also realize that FEM is a numerical technique and the answers obtained are not the exact solutions but only approximate. However by using appropriate procedures and proper computing facilities, we can obtain an extremely high degree of accuracy which is very much acceptable in practice. Notice that the "acceptable" term is used for engineering problems. In the video games field, after using acceptable procedures, the result can be considered physically correct.

[center][attachment=3545:fig2.png][/center]

Consequently, the structural matrix method is very close to the FEM. Actually the divided structures of beams are replaced by continuum solids.

[b]Stiffness matrix[/b]

Previously, the stiffness matrix of a spring has been examined above. The finite element method works with more complicated element in two or three dimensions.

[center][attachment=3546:fig3.png]

[b]Example of finite elements (from [i]An Introduction of the finite elements[/i] by Dhatt and Touzot)[/b]

[/center]

In the project, the only used element is a cube made of eight nodes with three degrees of freedom by nodes. In fact, each node could move along the x, y and z axes. In the previously example with the spring, the nodes located at each extremities of the element can move only along the axe of the spring.

[center][b]

[/b][attachment=3549:IMAGE036.GIF]

[b]The cubic element used for the project[/b]

[attachment=3550:IMAGE038.GIF]

[b]Three degrees of freedom by node[/b]

[left] Consequently, the dimension of the stiffness matrix of this element is 24 by 24:

[/left][/center]

[center][attachment=3551:IMAGE040.GIF][/center]

The matrix depends only on the material properties and dimensions of the cube. The analytical form has been calculated with Maple. The result and the Maple file is included in the attached resource file.

Refer to [alink='4']bibliography[/alink] to know how to compute stiffness matrices.

[size="3"][b]Common applications of the finite elements method[/b][/size]

FEM has a wide range of applications as follows:

[list][*]Stress Analysis;[*]Heat Transfer;[*]Fluid Flow;[*]Torsion Analysis;[*]etc.[/list] Some pictures, showing the capabilities of this method, follow.

[center][attachment=3552:IMAGE042.JPG][attachment=3553:IMAGE044.JPG]

[b]Stress in the frame of a bike[/b]

[/center]

[center][attachment=3554:IMAGE046.JPG][attachment=3555:IMAGE048.JPG]

[b]Deformation of a dam[/b]

[/center]

In this article, I will demonstrate that it is possible to adapt these industrial cases for the video games. These potential cases follow below:

[center][attachment=3556:IMAGE054.JPG][attachment=3557:IMAGE056.JPG]

[b]Turret (from Half-Life SDK)[/b]

[/center]

[size="5"][b][aname='3']Adaptation of the FEM[/b][/size]

[size="3"][b]General procedure[/b][/size]

Here are the common steps for a calculation based on the FEM:

[center][attachment=3547:fig4.png][/center]

[size="3"][b]FEM in real-time[/b][/size]

In current applications displayed in the previous pictures, the number of nodes and consequently the number of unknowns are very important. To find the displacements of the nodes, we must resolve the linear system [attachment=3538:IMAGE024.GIF]. [attachment=3528:IMAGE004.GIF]depends only on the geometry, the characteristics of the material, the number and the shape of the finite elements. Consequently, and it is the most important, the matrix [attachment=3528:IMAGE004.GIF]doesn't depend on the applied forces.

[center] [attachment=3558:IMAGE066.JPG]

[b]K doesn't depend of the loading conditions[/b]

[/center]

To resolve the matrix system, finite element applications use Gauss elimination, substitution or Newton-Raphson methods. These methods manipulate the second member of the equation (i.e. force vector [attachment=3529:IMAGE006.GIF] ), and of course these methods are the fastest. For example, the computation time to resolve a system within 10 000 degrees of freedom is about one minute. Of course it is not in real time. Let us try another trick to resolve the system. This trick is to resolve the system independently of the force vector.

[b]Resolution in two steps[/b]

The solution is to compute the [i]inverse[/i] of the matrix. But everyone knows that the inversion of matrix is a slow computation, but does it matter? If the solution doesn't depend on the force vector, the system is resolved before the beginning of the application. In more precise terms, the inverse of the matrix is stored in a file and loaded during the initialization of the application (typically during the loading of a game level).

[center][attachment=3548:fig5.png][/center]

The drawback of this method is that the boundary conditions are fixed and could not change. In fact, to inverse the matrix, simplification is done according to the boundary conditions. In the next part, called Study of a case, the detailed procedure will be explained.

[size="3"][b]Two steps and two tools[/b][/size]

In a part of the introduction called "Hyperion Project", some units have been presented. The most important is the set of components called Ephydryne Components. These components have been developed with the Hyperion Pattern framework. The Ephydryne package defines a set of interfaces and implements components to make the appropriate computing steps of the finite element method. Two tools have been set up to use the capabilities of the Ephydryne Components.

[b]HypDev[/b]

It is a client application that uses the Ephydryne components. The goal of HypDev is to calculate the linear relations between the forces applied on the rigid bodies and the deformations. According to the method presented in this article, the linear relation is computed during the development of the level. Again the linear relation is consequently loaded during the execution of the level. So an important part of the computation is not done during the game (step which is in real-time).

[b]HypVisual[/b]

The step which is in real time is studied with the application called HypVisual. This application loads the file generated by HypDev, displays the body and manages the simulation.

Here are some screenshots from the application:

[center][attachment=3559:SCRSHOT.BEAM1.JPG][attachment=3561:SCRSHOT.PLATE.JPG][attachment=3560:SCRSHOT.CUBE1.JPG]

[attachment=3525:HYP.LOGO.HYPDEV.GIF][attachment=3562:arrow_2.gif][attachment=3524:HYP.LOGO.EPHYDRYNE.GIF][attachment=3562:arrow_2.gif][attachment=3526:HYP.LOGO.HYPVISUAL.GIF][b]

The two tools used the same set of components[/b]

[/center]

For more information about these two applications, go to the web site of the project at [url="http://sourceforge.net/projects/ephydryne/"]http://sourceforge.net/projects/ephydryne/[/url].[url="http://sourceforge.net/projects/ephydryne/"]

[/url] Here below is summarized the general process of the method:[url="http://sourceforge.net/projects/ephydryne/"]

[/url]

[center][attachment=3563:fig6.png][/center]

[size="5"][b][aname='4']Appendix[/b][/size]

[size="3"][b]Bibliography[/b][/size]

[b]Structural approaches[/b]

The structural approach is comparable in some ways with some computing methods, famous in the field of the video games. The most interesting articles are:

2D Surface Deformation by Max I. Fomitchev [url="http://www.gamasutra.com/features"]http://www.gamasutra.com/features[/url]

Devil in the Blue-Faceted Dress: Real-Time Cloth Animation by Jeff Lander [url="http://www.gamasutra.com/features"]http://www.gamasutra.com/features[/url]

Some other interesting resources could be found:

Site collected resources about particle systems [url="http://www.particlesystems.com"]http://www.particlesystems.com[/url]

Game which used the structural approach to find stress in bridges [url="http://www.bridgebuilder.de"]http://www.bridgebuilder.de[/url]

[b]Finite Element Software[/b]

Web site of the ANSYS software [url="http://www.ansys.com"]http://www.ansys.com[/url]

Web site of the ROBOT software [url="http://www.robot97.com"]http://www.robot97.com[/url]

Web site of the C Mold software [url="http://www.cmold.com"]http://www.cmold.com[/url]

[b]Resources about FEM theory[/b]

Web Site, called FEMUR, about the FEM (FEMUR = Finite Element Method Universal Resources) [url="http://femur.wpi.edu"]http://femur.wpi.edu[/url]

The Finite Element Method in Engineering Science O.C. Zienkiewicz - Mc Graw Hill - 1967

FEM/BEM Notes P. Hunter, A. Pullan - Department of the Engineering Science, University of Auckland - 2001

Accurate Real Time Deformable Object by D.L James and D.K Pai - Univeristy of British Columbia

[b]

[size="3"]Stiffness matrix of a cube with eight nodes and three degrees of freedom by nodes[/size][/b]

Expression of the matrix hyp.stiffnessmatrix.txt (see attached resource)

Maple file used to obtain the matrix hyp.stiffnessmatrix.mws (see attached resource)