Download - Physics simulation in a 3D environment
![Page 1: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/1.jpg)
Physics simulation in a 3D
environment
Sylvain EUDIERMSCS Candidate
Union College
May 28th, Spring 2004
![Page 2: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/2.jpg)
Agenda Why Physics Simulation? Where am I, where am I going? Start Coding Entry point: The Spring Model Extension to the Flag / Cloth simulation Introduction to Collision Detection Collision improvement: an example Conclusion
![Page 3: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/3.jpg)
Why Physics Simulation? Getting more and more interest from the
game industry
How does it work behind the scenes?
Combines physics and CS
![Page 4: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/4.jpg)
Where am I? Physics are used in many programs (CAD, games,
simulators…)
Commercial physics libraries exist
As well as open source
Evolution of the simulation models up to now
![Page 5: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/5.jpg)
Evolution : Quake 2 – Doom 3
![Page 6: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/6.jpg)
Where am I going? How precisely do we want to simulate the
world
How do we want to represent it
For what expected quality / expense
![Page 7: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/7.jpg)
Start Coding – Define the rules Use of C++ Representation using the OpenGL API Game-like precision
Find a model for this problem (classes)
Starting point: Write a stable and easy-to-use CVector3D class
![Page 8: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/8.jpg)
The CVector3D class 3 constructors : Default, copy, by
components Overloading of operators:
+, -, *, /, +=, -=, *=, /= Methods: length, normalize, unit,
crossProduct and dotProduct
![Page 9: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/9.jpg)
What can I start with? The spring model
Simulate the behavior of a deformable objectunder certain constraints. Easy to implement (as a beginning) Gives convincing results rapidly
Allows me to test the architecture of my program
![Page 10: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/10.jpg)
The Spring Model
To the basic formula, we add the inner friction (to stabilize it):
IfvelmassvelmassixkF .)().2().1(..
![Page 11: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/11.jpg)
The Spring Model
These properties are the basics we can give to a mass.
Considered as a dot
![Page 12: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/12.jpg)
The Spring Model
For the computation:
L: steady lengthx: actual length of the springu: unit vector between mass1 and mass2
21.)().2().1()..( FFIfvelmassvelmassuLxkF
![Page 13: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/13.jpg)
Application to a rope The rope is made of several masses that
interact with each other
By changing the variables, the rope may be: stiffer, more / less extendable
We can create different kinds of extensible material
![Page 14: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/14.jpg)
Demonstration Rope simulation 1 Rope simulation 2
![Page 15: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/15.jpg)
Spring Model : First impressions (+) The result looks good enough for such
a simple simulation.
(-) The rope behaved differently on different machines (different speeds)
(-) The rope cannot be very stiff
![Page 16: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/16.jpg)
Spring Model : Speed problem Need for a time regulation algorithm
Why? How?
After the first try, I had a slow and fast behavior… Due to the GetTickCount() function Use of the QueryPerformanceCounter()
![Page 17: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/17.jpg)
Spring Model : Stiffness issue The stiffness problem:
Due to the Euler’s approximation method
0. vtav
amF .
0...2
1 2 postvtapos
![Page 18: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/18.jpg)
Spring Model : Stiffness issue – Why?
![Page 19: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/19.jpg)
Euler function stability comparison
![Page 20: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/20.jpg)
Spring Model : Extensions The rope does not
include any bending information: Can be solved using
interleaved springs (explained later, cf. Flag)
Stiffness problem: Regarding the sources I
found, the Runge-Kutta algorithm should solve the problem
![Page 21: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/21.jpg)
The Runge-Kutta Algorithm
Euler
Heun
Adams- Bashforth 2
Verlet
0
5000
10000
15000
20000
25000
18 20 22 24 26 28 30
Time (uSec)
Sp
rin
g S
tiff
nes
s
Runge-Kutta 4(55, 200000)
![Page 22: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/22.jpg)
Spring Model : Flag simulation A flag is just a patch of springs
Create n*m masses Create (n-1)*(m-1) springs Connect the springs to the masses
Possibility to add a wind effect
![Page 23: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/23.jpg)
Spring Model : Flag simulation Flag simulation
![Page 24: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/24.jpg)
Flag simulation : Results (+) The mesh reacts well to the wind and
gravity
(-) The flag is harder to simulate because of the stiffness problem and the lack of bending factor
![Page 25: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/25.jpg)
Flag simulation : Extensions Can simulate a flag
flexibility with interleaved springs…
…and add a universal repulsive force to every node
More complex and realistic simulation
![Page 26: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/26.jpg)
High quality flag simulation Demonstration
![Page 27: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/27.jpg)
Collision Detection Why?
How?
Dependencies: A strong math library: vectors, matrices, plane-
point collision, face-face collision… Possibility to work on predefined meshes
![Page 28: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/28.jpg)
On the way to the collision Math library:
Matrices: Overloading of arithmetic operators (+, -, *, +=…) Overloading of input / output operators ([], <<) Matrices functions : determinant, multiplications,
inversions, transposition, identity Matrix-related functions : rotate, scale, translate…
Vectors Collision functions: PointToPlaneDistance,
IsPointInPolygon…
![Page 29: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/29.jpg)
Importing 3DS files 3DS is a standard in the industry
I already had an importing class for 3DS files
.3DS files have several advantages: Face defined clockwise, Texture information, Normals information, And a lot more…
![Page 30: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/30.jpg)
Into the collision Brute force algorithm:CheckForCollisions():
MakePreselection(Scene, Collisions)For all objects in the Collision Listif(this object collides with another one)
Find the collision pointApply the physics on the objects, at that point
But this will never work!!!
![Page 31: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/31.jpg)
Buggy Collision Demonstration
![Page 32: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/32.jpg)
Into the collision (2) New algorithm:
DoDo
ComputePhysics(NextTimeChunk);CheckForCollisions(Scene, Collisions);if(MaxPenetrationInAnObject < Limit)
Problem is solved;if(Problem NOT solved)
NextTimeChunk = PreviousTime / 2;CancelTheComputations();
elseValidateTheComputations();
While(Problem is NOT solved);proceed to the next time chunk;
While(TimeChunknotSimulated);
![Page 33: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/33.jpg)
The rollback function
![Page 34: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/34.jpg)
Collision improvement We can extend the sphere collision test to
a more general one.
Add a real collision and motion behavior (friction, rotation…)
The MakePreselection function can improve a lot the computation time
![Page 35: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/35.jpg)
Improvements and trade-offs The vast majority of the program use an
aggressive MakePreselection algorithm to be able to deal with a lot of objects
Optimization without loss of information
AABB = Axis Aligned Bounding Box
OBB = Oriented Bounding Box
6-dop = Discrete Orientation Polytope
Convex Hull
![Page 36: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/36.jpg)
Example of an approximation algorithmApproximation: Based on some assumptions over“insignificant” constraints of objects (=has to lookgood enough)
The Opposing Face Geometry algorithm: Algorithm in 8 steps, The pro… …And cons
![Page 37: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/37.jpg)
Opposing Face Geometry algorithm 1. Preselection:
check collision between object A's bounding sphere and object B's bounding sphere.
2. Find the closest k faces of object A relative to object B.
![Page 38: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/38.jpg)
O.F.G. algorithm 3. Calculate the
geometric center of the new selection and the bounding sphere radius.
4. Find the closest k faces of object B relative to object A's new selection of k faces.
5. Calculate the geometric center of object B's new selection of faces and their maximal bounding sphere radius.
![Page 39: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/39.jpg)
The O.F.G. algorithm
6. PreSelection: check collision between spheres to determine if there is even a chance for face collisions.
7. Sort the two sets of faces by increasing distance
8. Test the two sets of faces against each other, starting with the closest pairs of faces.
![Page 40: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/40.jpg)
Pro / Cons of such this algorithm (+) This is a lot faster. Runtime of O(k2)
Where k is usually between 4 and 8(k is a variable representing the number of faces we want to work on)
Brute force approach would be O(n*m)n and m could be 1000 of faces
(-) Cannot really work on concave polygonsThis is TRUE for most of today’s engines
![Page 41: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/41.jpg)
The discrete Time problem Due to the intrinsic
nature of the simulation : Time-discrete based
If the dt variation is too big, an object might be “teleported” through another one
Solution: Extrude the silhouette of the object. Test this polygon for collisions
![Page 42: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/42.jpg)
Summary Springs are the basis of a lot of models
and can be used for powerful simulations (i.e. any kind of elastic models)
Collision detection needs a robust design and math support. There is a lot to do about optimization and trade-offs
Physics simulation is a vast field where a lot of techniques are to be discovered
![Page 43: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/43.jpg)
Selection of References “Computer Graphics with OpenGL”, third Edition by Hearn-
Baker, Prentice Hall
Huge source of information for game programming:www.gamedev.net
Chris Hecker’s famous columns about physics:http://www.d6.com/users/checker/dynamics.htm#articles
Everything you need to know about geometry:http://astronomy.swin.edu.au/~pbourke/geometry/
A lot about everything, from physics to light computations:http://freespace.virgin.net/hugo.elias/
![Page 44: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/44.jpg)
Conclusion - Discussion Questions? Need Explanations?
What kind of extensions could we add to a physics simulator?
![Page 45: Physics simulation in a 3D environment](https://reader036.vdocuments.us/reader036/viewer/2022062520/5681592f550346895dc66114/html5/thumbnails/45.jpg)
References Collision detection
Advanced Gamasutra - Features - "Advanced Collision Detection Techniques" [03.30.00] Advanced Collision Detection Techniques Advanced Collision Detection Techniques Chris Hecker's Rigid Body Dynamics Information DDJ
GameDev.net - Opposing Face Geometry GameDev.net - Simple Bounding-Sphere Collision Detection GameDev.net - Practical Collision Detection GameDev.net - General Collision Detection for Games Using Ellipsoids Collision Response: Bouncy, Trouncy, Fun Gamasutra - Features - "Crashing into the New Year" [02.10.00] Snooker simulation (+Formulaes) Rotation computation
HyperPhysics MODEL-BASED ANIMATION SIGGRAPH - Collision Detection ('88)
AIWisdom.com - Game Articles & Research Geometry Cours de Mécanique - Index The good-looking textured light-sourced bouncy fun smart and stretchy page Deformation
GameDev.net - Real time deformation of solids, Part 1 GameDev.net - Real time deformation of solids, Part 2 Gamasutra - Features - "Exploring Spring Models" [10.05.01]
Cloths Awesome paper on cloth simulation
ch06.pdf (application/pdf Object) Rotational Motion