Digit 7

Your source for XNA tutorials and 3D programming ideas.

Home     Shader Tutorials     XNA/C# Downloads     Links      
Blackjack Simulation
Heightmap Generator
Physics Simulator
Procedural Tree Generator
QuadTree
Swarm Intelligence
Matrix Solver
Massive Battle

3D Physics Simulator


Downloads
-XNA Project - Build 2
-XNA Project - Build 1
-Executable - Build 2
-Executable - Build 1

BUILD 2

         

After a few busy weeks I've finally managed to make some headway. Here's a list of the new features/fixes:
  • You can now create, save and load experiments.
  • Fluid Volumes - A static, rectangular volume of fluid with a density and drag-coefficient. Exerts drag and buoyancy on objects within the volume.
  • Added a Density property to rigid bodies.
  • The ability to add/delete/edit spheres, elastic connections an fluid volumes from an experiment.
  • Collisions are now calculated correctly. I visited Wikipedia and implemented the formulas for objects with unique coefficients of restitution. Not a perfect way of modeling collisions but it will work for now.
  • Restructuring of the UI into a tree view control.
  • Change the direction of gravity.
  • The choppiness bug was just a problem with my graphics driver and Windows 7.

There are plenty of bugs too, this is a very rough build. I just wanted to give you guys something to look at. Here's a few key ones to watch out for:
  • You cannot modify the state of an object while the simulation is running (it's supposed to work this way but the UI doesn't stop you in any way).
  • Recording doesn't function properly.
  • Normal forces are calculated incorrectly for resting objects with multiple contact points.
  • The density of a fluid is constant over the entire volume (should be denser at bottom).

You can look for these features in Build 3. Be aware that these are some hour-heavy changes so unfortunately I won't have a new build soon. (I'll cross them out as I complete them).
  • Visualization of forces acting on an object.
  • Data logging for attributes and objects.
  • More attributes for rigid bodies (momentum, kinetic energy, etc.)
  • Fixing the normal force calculation.
  • Rotation of rigid bodies.
  • Enhanced graphical features.
  • Optimizing the code to allow for faster collision detection (i.e. object-space partitioning)

Last Update: 12/2/09
BUILD 1



     This application is a 3D physics simulator which I've been working on. Here's essentially how it works:
  • You set up modules called "Experiments". The application maintains a list of experiments so you can go back and forth between them.
  • Within an experiment, you can set up objects with an initial state at t = 0.
  • You can then run the experiment. I've set it up so you can start and stop the action whenever you want. If you want a detailed look at things, you can even go through frame by frame. The time step is fully adjustable also, so you can slow things down to get a more accurate simulation.
  • There's also a list of objects which is populated when you select an experiment. By clicking on an object in this list, you can view its properties. If you have an object selected while the simulation is running, you can track how the properties change over time.

     The controls are fairly simple too. Everything in the menus is mapped to a key shortcut or a button on the tool bars. To control the camera, W,A,S,D control forward, left, back and right, respectively. If you want to speed up the camera, hold down the left-shift key while you're moving.

     Since the application is still in the early development stages, I haven't added a lot of features yet. Here's what I have so far:
  • Gravity
  • Collisions
  • Springs (These can only be added through code right now)
  • Elastic Ropes (These can only be added through code right now)
  • The only object you can place in the simulation is a sphere
  • Simulation controls: Start, stop, next frame, record, set current state to initial state, increase time step, decrease time step
  • Creating, saving and loading experiments.
  • Record experiment data to a text file.

     A few notes on recording: if you want to record an experiment, press press the record button. You should see it depress. Then play the simulation for as long as you want. Once you stop the simulation, press the record button again. Then go to the menu and click Data->Export to Text File...

     There are still plenty of improvements to be made. Here's a few known bugs and things I plan to add in the near future:
BUGS
  • Fix how the states (initial and current) are stored. Right now it's very inefficient and the code and performance suffer because of it.
  • Imperfectly elastic collisions (slightly inelastic) aren't calculated right.
  • There's an issue where if you run the application too many times, it becomes choppy and you have to restart your computer for it to go away.
ADDITIONS
  • Box objects
  • Create a room for the experiment to take place in so everything doesn't fall into oblivion.
  • Rotational Dynamics
  • Graph recorded data
  • Be able to Add elastic connectors to the scene
  • Provide a better way of adding objects to the experiment (aka visual).
  • Optimize collisions
  • Buoyancy/Fluids
  • Rigid arms
  • Thrusters
  • etc...

     There is plenty left to be done. I'll keep this up to date when new additions are made. I wouldn't bother reporting any bugs to me at the moment since there are more than I can count. Just play around with it. It will be easiest to download the XNA project and create an experiment through code. I've created several; the code is under frmMain.cs->initialize(). As always, if you have any questions you can email me at dan@digitseven.com.



    


     It's taken me quite a while to finally post this on there even though I've been working on it for a few weeks... Since physics is my primary area of interest, I decided to start on a physics engine. It started off as a 3D engine, but I soon realized the complexity of the project and scaled it down to 2D. Programming a physics engine is really fun stuff. It's amazing to see the results once you get all the equations and collision detection lined up. It's in the very beginning stages right now, but I have enough of a demonstration to show you guys what I'm doing. Eventually I'm going to give a full tutorial on how to implement this engine in XNA since there are very few tutorials right now not in white paper format. I found most of the information from Chris Hecker's GDM article, which you can find under the Physics category on my
Links page. It's a great article, but still pretty complex and short-handed.
     There's essentially three main components to the engine so far: the physics engine itself, the integrator used for solving the integrals in the physics engine and the collision detector. Each is a separate beast in itself and I've made all three as simple as possible at the moment. Anyway, I've posted a video with my progress with it so far. And yes... I spelled propagation wrong... It's wayyy too much work to run it back through Adobe Premiere Elements though so I think it'll be okay :). It's really satisfying to see the objects colliding and rotating semi-realistically.
     As you can tell in the video, I only have boxes right now, but don't be fooled: any object defined as a TriangleStrip can be plopped into my program and is automatically a physics-enabled object. All of the collision detection is done at a per-polygon level, so it's about as fine as you can possibly get. I know you're saying "Jeez! That's going to be a dog of a program!" I realize that, but I'm going for full realism on this, none of that "close-enough-for-government-work" game physics.
     Anyway, I'll keep you updated on the progress. I've been busy getting information on the site so I haven't had much time for it, but I think I'll get around to fixing the bugs below fairly soon. Let me know what you think!

Bugs
  • Objects are able to interpenetrate each other to a certain degree. Several solutions for this problem. Can either check for collisions before they happen or sub-divide the time interval to right before the collision occurs.
  • When an object strikes another and rotates, sometimes a vertex is able to swing into another object.
  • No resting contact. I have a white paper on this subject but I have yet to read through it yet.
  • Slow, slow, slow. I haven't optimized any of the routines. I practically just the collision detection semi-working a few days ago, so that will probably be the first order of business.

Downloads
-XNA Project
-Executable

Last Updated: 7/24/09