Understanding btGeneric6DofConstraint

Post Reply
blender
Posts: 2
Joined: Wed Mar 04, 2020 6:46 pm

Understanding btGeneric6DofConstraint

Post by blender »

My goal is to implement ragdoll physics and I have seen the sample code at https://github.com/kripken/bullet/blob/ ... agdoll.cpp

Because the example code is just bunch of hard-coded values and the documentation of btGeneric6DofConstraint is very limited I'm having difficulty in understanding how the constraint works. I think a good graphical illustration is needed. I see that I need to define two frames (one for each rigid body) that define constraint spaces via 4x4 transform matrices. However there is no good documentation that explains that in which space are the basis vectors of those matrices to be defined. Are they in the world space or in local space of rigid body A or in local space of rigid body B?

I created an illustration of how I try to visualize the constraint:
generic_constraint.png
generic_constraint.png (43.83 KiB) Viewed 2855 times
The rigid body transforms are A and B and the respective constraint spaces are FA and FB. So is FA transform relative to A and FB relative to B or are they relative to world? Also if translation is fully constrained, does rigid body A rotate around origin of FA and rigid body B around origin of FB?
Are the angles limited so that angle between x_FA relative to x_FB must be less than given x angle and so on for other components?

Thanks for any help.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Understanding btGeneric6DofConstraint

Post by drleviathan »

I believe the transform parameters of the btGeneric6DofConstriant represent the offset to the "pivot" of the constraint in each body's local-frame. In the simplest 6Dof configuration where all 6 degrees are fully constrained (e.g. acting like a btFixedConstraint)... in the constraint solver math will be done to satisfy the constraint. In other words: make each local-frame pivot overlap the other in the world-frame AND align their cardinal axes.

In your diagram (if I understand it correctly) I see a dotted line between two "frames": one the pivot in local-frame-A and the other pivot in local-frame-B. Assuming the 3 linear degrees of freedom are being enforced I would expect the math to try to reduce the length of that dotted line to zero.

Similarly for the angular degrees of freedom. If you configure the constraint to allow angular discrepancies between the local axes of the two pivots then... the math will try to push the axes of the two pivots closer together when the angles between respective cardinal axes exceed the limits you have set.
blender
Posts: 2
Joined: Wed Mar 04, 2020 6:46 pm

Re: Understanding btGeneric6DofConstraint

Post by blender »

Thanks for the response drleviathan I think I now have better understanding.

My biggest concern was initially that why do I need to give two frames in local coordinates instead of giving one frame in global coordinates (this would be the pivot) and the two bodies could then calculate their own local versions of that. But I've come to realize that the existing method allows some initial configuration where unconstrained degrees of freedom are at given position.

I'm mostly interested at the moment in case where the linear degrees are fully constrained so I was wondering what will happen if the two frames have different origins in world space (the dotted line in the figure). So it makes sense as drleviathan wrote that in that case the simulation would try to snap the two origins together.

I'm still unsure of following:
(1) If I limit x-angle within range [x_min, x_max], does Bullet attempt to keep the x-Euler angle within this range (rotation around local x-axis of frame A with respect to frame B?) or the angle between the local x-axes of the two frames. I believe these cases are different. Looking at the ragdoll example I think the answer is the first one but I'm not entirely sure.

(2) What is the effect of parameter useLinearReferenceFrameA ? Are the two frames always local to the to bodies respectively or does this parameter somehow affect the interpretation?

(3) If some linear degree e.g. x is unconstrained, then which "x" direction is this? Is it the origin of frame A along the local x-axis of frame B or vice versa or something else? Or is this actually related to (2)?

BTW I have created issue https://github.com/bulletphysics/bullet3/issues/2658 because I think a good picture and some explanation could have saved me a lot of time reading through examples and code and making guesses.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Understanding btGeneric6DofConstraint

Post by drleviathan »

Yeah, I've always been daunted by the complexity of the btGeneric6DofConstraint parameters. I dunno the answers to your questions. Maybe someone else does.
Post Reply