Physics simulation in a 3D environment - PowerPoint PPT Presentation

About This Presentation
Title:

Physics simulation in a 3D environment

Description:

Title: Physics simulation in a 3D environment Author: eudiers Last modified by: eudiers Created Date: 5/25/2004 7:51:05 PM Document presentation format – PowerPoint PPT presentation

Number of Views:242
Avg rating:3.0/5.0
Slides: 46
Provided by: eudi
Category:

less

Transcript and Presenter's Notes

Title: Physics simulation in a 3D environment


1
Physics simulation in a 3D environment
  • Sylvain EUDIER
  • MSCS Candidate

Union College May 28th, Spring 2004
2
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

3
Why Physics Simulation?
  • Getting more and more interest from the game
    industry
  • How does it work behind the scenes?
  • Combines physics and CS

4
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

5
Evolution Quake 2 Doom 3
6
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

7
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

8
The CVector3D class
  • 3 constructors Default, copy, by components
  • Overloading of operators
  • , -, , /, , -, , /
  • Methods length, normalize, unit, crossProduct
    and dotProduct

9
What can I start with?
  • The spring model
  • Simulate the behavior of a deformable object
  • under certain constraints.
  • Easy to implement (as a beginning)
  • Gives convincing results rapidly
  • Allows me to test the architecture of my program

10
The Spring Model
  • To the basic formula, we add the inner friction
    (to stabilize it)

11
The Spring Model
  • These properties are the basics we can give to a
    mass.
  • Considered as a dot

12
The Spring Model
  • For the computation
  • L steady length
  • x actual length of the spring
  • u unit vector between mass1 and mass2

13
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

14
Demonstration
  • Rope simulation 1
  • Rope simulation 2

15
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

16
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()

17
Spring Model Stiffness issue
  • The stiffness problem
  • Due to the Eulers approximation method

18
Spring Model Stiffness issue Why?
19
Euler function stability comparison
20
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

21
The Runge-Kutta Algorithm
Runge-Kutta 4 (55, 200000)
22
Spring Model Flag simulation
  • A flag is just a patch of springs
  • Create nm masses
  • Create (n-1)(m-1) springs
  • Connect the springs to the masses
  • Possibility to add a wind effect

23
Spring Model Flag simulation
  • Flag simulation

24
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

25
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

26
High quality flag simulation
  • Demonstration

27
Collision Detection
  • Why?
  • How?
  • Dependencies
  • A strong math library vectors, matrices,
    plane-point collision, face-face collision
  • Possibility to work on predefined meshes

28
On the way to the collision
  • Math library
  • Matrices
  • Overloading of arithmetic operators (, -, ,
    )
  • Overloading of input / output operators (, ltlt)
  • Matrices functions determinant,
    multiplications, inversions, transposition,
    identity
  • Matrix-related functions rotate, scale,
    translate
  • Vectors
  • Collision functions PointToPlaneDistance,
    IsPointInPolygon

29
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

30
Into the collision
  • Brute force algorithm
  • CheckForCollisions()
  • MakePreselection(Scene, Collisions)
  • For all objects in the Collision List
  • if(this object collides with another one)
  • Find the collision point
  • Apply the physics on the objects, at that point
  • But this will never work!!!

31
Buggy Collision
  • Demonstration

32
Into the collision (2)
  • New algorithm
  • Do
  • Do
  • ComputePhysics(NextTimeChunk)
  • CheckForCollisions(Scene, Collisions)
  • if(MaxPenetrationInAnObject lt Limit)
  • Problem is solved
  • if(Problem NOT solved)
  • NextTimeChunk PreviousTime / 2
  • CancelTheComputations()
  • else
  • ValidateTheComputations()
  • While(Problem is NOT solved)
  • proceed to the next time chunk
  • While(TimeChunknotSimulated)

33
The rollback function
34
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

35
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
36
Example of an approximation algorithm
  • Approximation Based on some assumptions over
  • insignificant constraints of objects (has to
    look
  • good enough)
  • The Opposing Face Geometry algorithm
  • Algorithm in 8 steps,
  • The pro
  • And cons

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

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

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

40
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(nm)
  • n and m could be 1000 of faces
  • (-) Cannot really work on concave polygons
  • This is TRUE for most of todays engines

41
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

42
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

43
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 Heckers famous columns about physics
  • http//www.d6.com/users/checker/dynamics.htmarti
    cles
  • 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/

44
Conclusion - Discussion
  • Questions? Need Explanations?
  • What kind of extensions could we add to a physics
    simulator?

45
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)
Write a Comment
User Comments (0)
About PowerShow.com