rigid body simulation

Started by
18 comments, last by MrRowl 19 years, 6 months ago
Hello (1st post), I'm trying to develop a simple rigid body engine (in C#). After a few tries, I based my code on Danny Chapman's code (http://www.rowlhouse.co.uk/jiggle/index.html). I do the same collision response and overall simulation. But I just want boxes in my simulation so I used the separating axis algorithm to obtain collision info (point,normal,depth) instead of Chapman's more general poly/poly algorithm. My test program is just 2 boxes floating in the air. Depending on the orientation, the boxes bounce ok the first time but don't really depart from each other after and start doing weird things after a few correct bounces. Here is my test program with source code http://vlad-game-coding.site.voila.fr/Zip/Physic_Engine_2_Release.zip The user has control over the left box via a force or a torque. Controls : Camera : Mouse, Q,D,Z,X (quake style) Force on left box : F,H,T,B,R,Y Torque on left box : J,L,I,";",U,O Stop velocity,omega of left box : Space Restart simulation : Enter (sorry for non-french keyboard owners:) - Does someone has an idea of the problem ? - Is it the separating axis collision detection that is insufficient ? (returns only 1 point of collision). I doubt since Oliiii used it with success (if I remember right).
Advertisement
I tried running it but got "An exception 'System.Reflection.ReflectionTypeLoadException' has occurred in Axiom.exe

I'd unzipped everything and was running from the bin\Debug directory. There's nothing helpful in the log file. This is under M$ Windows XP with all updates etc.
Just a hunch...no time to check the code nor the execution.

Are you sure you've departed the boxes from each other at the time of the next separating axis check?

It is quite easy to code a collision system such that impact impulses are correct after the first collision, i.e., the objects are flying in opposite directions but the objects are still interpenetrating when the next check executes and the impact impulses are reversed. In effect the boxes get stuck, shake and after a few rounds (enter floating point arithmetic and cheap integrators) the system blows up.

How does your collision restitution model cancel the interpenetration?

JD
Quote:Original post by MrRowl
I tried running it but got "An exception 'System.Reflection.ReflectionTypeLoadException' has occurred in Axiom.exe

I'd unzipped everything and was running from the bin\Debug directory. There's nothing helpful in the log file. This is under M$ Windows XP with all updates etc.

I'm sorry I don't know what causes this. When I download the zip file, the exe in bin/Debug works for me. I also have XP. I think it's an axiom engine related problem. I updated the zip by modyfing minor config things, hope it works now. I really would like you to see it :)
Can someone launch my test program ?

Quote:Original post by JesusDesoles
Are you sure you've departed the boxes from each other at the time of the next separating axis check?

I follow MrRowl scheme :
- save bodies velocities and positions
- update bodies velocities and positions
- detect collisions (points,normal,depth)
- restore bodies velocities
- apply impulses to bodies ( I do P+=impulse and L+=(position-x).Cross(impulse) )
- restore bodies positions
- update bodies velocities and positions

(PS: I use state variables x (position), q (orientation), P (velocity*mass), L (Iworld*omega), my mass are always 1 and my inertia matrices are identity (cubes) )

And yes I forgot the next to last step "restore bodies positions" so you were right, I forgot to depart the boxes from each others.
But correcting this did not change the results unfortunately.

The problem is elsewhere. Maybe the impulse is false
I calculate it this way :
                        -(1+e)vab.nj = ---------------------------------------------------    ( 1/Ma + Iainv*(pos-xa)^n^(pos-xa) + same for b ).n

where
n : normal of contact normalized
pos : position of contact point
xa : position of center of mass of body A
vab : va+omegaA^(pos-xa) - (vb+omegaB^(pos-xb)
* : matrix vector multiplication
^ : vector cross product
. : vector dot product

What is the unit of an impulse ? num = m.s-1 denom = kg-1.m2 so j = kg.m-1.s-1 ? weird
j should be kg.m.s-1 because I do P = P + j (with P=mv)

The problem seems to be that when I do :
P+=j
L+=(pos-x).Cross(j)
j is too small (around 1)
how can such a small change in velocity be enough ? The translational impulse response seems too weak.
as for L, (pos-x).Cross(j) is far bigger since my boxes are of 100 unit length, so the rotational impulse response seems correct.
Is this a problem to have such big boxes ?
Quote:Original post by _Vlad
I'm sorry I don't know what causes this. When I download the zip file, the exe in bin/Debug works for me. I also have XP. I think it's an axiom engine related problem. I updated the zip by modyfing minor config things, hope it works now.


Sorry - still get what's probably the same error. This time running at home (XP home) - when I click on OK to make the error dialog box there's a console window that fills up with some trace output... but it immediately closes! So I con't tell you what it says.

Again, the log file is pretty much empty... sorry!
It's not easy to release a program properly with visual studio.
I asked some help on the axiom forum. I'm waiting for their reply.
Does my program work for other people ?
Quote:Original post by _Vlad
Quote:Original post by MrRowl
I tried running it but got "An exception 'System.Reflection.ReflectionTypeLoadException' has occurred in Axiom.exe

I'd unzipped everything and was running from the bin\Debug directory. There's nothing helpful in the log file. This is under M$ Windows XP with all updates etc.

I'm sorry I don't know what causes this. When I download the zip file, the exe in bin/Debug works for me. I also have XP. I think it's an axiom engine related problem. I updated the zip by modyfing minor config things, hope it works now. I really would like you to see it :)
Can someone launch my test program ?


I'm almost certain that this is the error you will get when you either don't have the managed extensions for DirectX installed, or you have a different version of the extensions installed from what the program was compiled with.
I believe that the version of Axiom that _vlad has compiled is referencing the DirectX 9.0b (summer 2003 update) libraries, so you will need to have those managed extensions installed. If this is the case, then you will need to get the DirectX redistributable package and run the installation with the /InstallManagedDX command line argument. If that does not work (and in some cases it doesn't work), then you can extract the contents of the ManagedDX.cab file, in there there will be a file named mdxredist.msi, which you can use to force the managed extensions to install.

Even though _vlad did not include the DirectX renderer plugin, the Windows platform manager references Direct Input unless _vlad has made some changes to strip it out.

J.W.
errr wouldn't it just be easier to write generic c++ with some standard, cross platform libraries?!?
Quote:Original post by MrRowl
errr wouldn't it just be easier to write generic c++ with some standard, cross platform libraries?!?


Questions like that usually just lead to religious holy wars over which language is better. I say that it all depends on your personal preference, and in this case, _vlad has chosen to use C# and Axiom. Which once the SDL platform manager is complete should be fully cross platform (without requiring comipilation for a specific platform).

J.W.
Thanks for the advice jwace81,

Wow, directX sucks[flaming]
In fact I had to remove the directX project from the axiom solution because of compile problems (things like Light.Commit() not existing) and me not being able to install correctly the managed extensions (/InstallManagedDX very hard to do)
I had some more problems with the reference to directInput which I couldn't remove.

I also installed several directX versions with more or less managed extensions from different versions and seasons so I don't know what I'm using exactly.
Dxdiag gives me DirectX 9.0c (4.09.0000.0904)

And installing several directX sdk with a 16Ko/s connection is a pain so I'll maybe try again but not right now.

Quote:Original post by MrRowl
errr wouldn't it just be easier to write generic c++ with some standard, cross platform libraries?!?

I have coded also a lot with c++ but
- I now prefer to develop in C#, it's really more productive and elegant I think.
- The axiom engine is awesome I think and it's in C#.
- even in c++, people were missing some msvcrt??.dlls

So if you feel like updating your directx with the information given by jwace81 it would be nice. Elseif I'll do it in a near future (motivation+16Ko/s).

This topic is closed to new replies.

Advertisement