Archived

This topic is now archived and is closed to further replies.

Hybrid

Quick and easy joints

Recommended Posts

Hi, I''ve read a lot of the joints and articulation threads on the forums, yet I still don''t have a clear idea about how to add joints in physics. I need just one joint to simulate a car and trailer for a project I''m doing, yet I dont have a clue about the maths and alogorithms needed to ''solve'' the joint. I''m still awaiting my copy of the Eberly game physics book which I understand has some method of solving joints, though until it arrives I can''t go over it. Whats the easiest way of programming a joint between a car and trailer? What methods should I be looking into? Anyone have an psuedo code for the process of solving the joint? Any help is much appreciated!

Share this post


Link to post
Share on other sites
Assuming your car and trailor are full rigid bodies, then you''ll already have code to handle collisions etc - the best (only?) way to handle joints is to integrate them into whatever collision scheme you already have. If you''re handling contacts with an LCP approach, then you''ll need to work out how to express your joints (including limits?) in those terms.

If you''re handling stuff with impulses applied sequentially, then you can very easily create a ball+socket joint by specifying two points, one on each object, and applying impulses to both objects in order to make the two points (a) occupy the same position in space and (b) have the same velocity. This is dead easy, because you can use exactly the same approach as for the collisions. The disadvantage is that it is (perhaps) slower than the LCP approach in some situations, and won''t work very well if the two connected objects have substantially different masses. Once you have this joint set up you can create hinges using two ball+socket joints, universal joints using 2 hinges etc.

Anyway, I wrote a physics demo using the latter method:
http://www.rowlhouse.co.uk/jiggle
and am happy to describe the implementation in more detail if you mail me. As it says on that page, I''m STILL waiting to hear from my employer about making the source code available.

Share this post


Link to post
Share on other sites
Thanks for the reply. I can''t do the impulse method for the reason you mentioned - they will have different masses. So I guess LCP is the way to go. Hopefully I''ll receive my physics book this week with LCP in. Have you tried implementing LCP at all? Has anyone? Is it hard?

Share this post


Link to post
Share on other sites
I would have thought a car/trailer would work fine with impulses - the ratio of masses is not going to be more than 4:1 or so, is it? It would just mean you'd need a greater number of iterations... so longs as you haven't got a huge number of car/trailers, or you aren't coding for really slow targets (e.g. PS2 ) with more than a handfull of jointed objects, the iterative/impulsive method should be fine, in my opinion.

Incidently, one thing you can do is to not display exactly what's in the simulation. For example, if you simulate two rigid bodies (car + trailer) and you have a ball+socket joint joining them, then the iterative/impulse method will sometimes let them separate a little bit, especially during nasty crashes etc. So long as you have a factor in your physics engine that resolves these broken constraints nicely over a few steps, this is OK, but it might look ugly. So, just tweak the render positions/orientations of your objects so that they actually join up. Since significant separation of the objects will only happen rarely, and in "violent" events (crashes), it won't matter that at these times the rendered objects aren't quite the same as the physics objects.

No, I haven't done the LCP solver thing.

Incidently, don't pin your hopes on Dave's book to help you solve this particular problem - whilst it's good (in a kind of special way, whatever that means!), I don't think it really covers joints. Actually, I'm not even sure it covers handling friction within the LCP framework (hmmm my copy is at work and I'm at home, so I may have just forgotton...).



[edited by - MrRowl on March 21, 2004 1:25:49 PM]

[edited by - MrRowl on March 21, 2004 1:27:01 PM]

Share this post


Link to post
Share on other sites
ODE is a free library that already does this. You can get it for reading the source, or you can just decide to use it, rather than rolling your own.

Make sure to get the latest from CVS, because it has bug fixes and improvements not in the current release.

Edit: Clicky



[edited by - hplus0603 on March 21, 2004 1:37:18 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by MrRowl
I would have thought a car/trailer would work fine with impulses - the ratio of masses is not going to be more than 4:1 or so, is it? It would just mean you''d need a greater number of iterations... so longs as you haven''t got a huge number of car/trailers, or you aren''t coding for really slow targets (e.g. PS2 ) with more than a handfull of jointed objects, the iterative/impulsive method should be fine, in my opinion.

Oh no, their masses aren''t gonna be more than 4:1, I just assumed significantly different masses in a physics simulation would be anything more than about 2:1.

There will only be one car and trailer in the simulation, with no collisions actually. The simulation is mainly focusing on altering masses in the trailer and simulating effects such as jack-knifing and trailer sliding, under different speed, friction and braking conditions - on a flat infinite plane. So I guess I can therefore afford to carry out lots of iterations each frame given that most (if not all) the CPU time will be on the physics of this one car and trailer.

Guess I''ll check out some impulse based stuff now then

hplus - I''ve looked at ODE, though I really want to understand how things are done, which ain''t so easy looking through someone else''s source. Thanks for the link anyway.

Share this post


Link to post
Share on other sites