xbdev - software development
Sunday May 19, 2024
home | contact | Support | Physics.... Squishy, Bouncy, Springy, Rigid, ...Bodies... | Game Physics Programming.. Bouncing Objects, Springs, Balls, Rigid Bodies...


Game Physics Programming..

Bouncing Objects, Springs, Balls, Rigid Bodies...


Impulse Physics - Iterative Constraint Demo

by Ben Kenwright


Using the basic impulse methods, we can construct various constraints, which go beyond the basic collision contacts.  These include ball-joints, hinges, joints, angular-linear combinations etc.  Of course once you've created one constraint you can combine it with other constraints to form more complicated ones.

The beauty of using impulse base methods is the principles are easy to follow and work with, also, using the method in the examples, we can use multiple iterations to validate the constraint, so the more iterations you apply the more accurate the constraint is to its ideal solution.  (For example, when large forces are applied, you'll usually need to apply more iterations ~2-10).

PART 1 - The Theory

Well to give a bit of theory on the subject, I thought I'd include the technical paper on the subject which I wrote, it mostly focuses on the equations used and the principles being applied to real time characters for use in games.  Its just for those who want to diverge a bit more into the details rather than the coding side of it.

Its in an easy to download pdf file, so for those like myself, who like to sit down with a coffee and read over things

PART 2 - Basic Code and Test Cases
The first demo was basically to test out all sorts of test cases, bridges, stacks of blocks, bowling, marbles, various shapes, and variuos simple test ragdolls to see how framerate, collisions, stablity is handled.

The code is compiled in Visual Studio 2008 with C# and runs at a reasonable frame rate.  The code could seriously be speeded up using C/C++ and SIMD as a lot of the data/updates could be performed in parallel.

But to keep the code simple and usable and just to test the various test cases.  Hopefully it will good fun to have a play around with.  Great fun being able to drag the ragdoll around and play with springy bridges.

The code lets you switch between springs/constraints etc to see the various stablity issues.

One of the biggest slowdown is the generation of some of the more complicated shapes - uses a quick convex hull generation algorithm, which is simple but can be a bit slow and produce excessive numbers of triangles for some of the shapes, but really wanted to focus on the physics and constraints rather than the shape generation code.  Still it lets you have more than just cubes!..Cubes are great, but can get a bit boring after a while.

PART 3 - Focusing on Characters

Of course, using the basics from the above demo, I focused more on characters, adding in a custom .x loader/parser, so I could load in .x models and render there skeleton with a ragdoll, while also applying a skin.  Seemed to perform quiet well, some of the lesser bones like fingers where thrown away, to simplify the number of ragdoll bones.  Also, a simple blending option to test the blending between the animation-ragdoll was added with a slider.

Ragdolls are fun, so I decided to focus on them.  Improving there constraints, and making the code more robust so it could handle invalid joint positions without exploding.

You can choose to use, ellipsoids, spheres, boxes etc for the various joints as in the previous example.  I just chose boxes for the screenshots as there the default for the ragdolls.

The zip file is a little big, as I included the test .x model files with textures etc.

PART 4 - Further Work

This is a never ending rabbit hole, so many exciting things to still try, but a few major ones to look at are:

o Applying a more parallel architecture to the impulse updates - maybe multiple threads to increase the bottleneck.
o Creating more joint types.




Advert (Support Website)

Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.