Lets say you attached a device that would hold a ball and release it to the roundabout. If you placed it in the center the ball should mostly just rotate on the spot when released. But if you had it placed at the edge the ball should fly away when released.
That's handled by this code i've posted before:
- Code: Select all
sVec3 v = oldBody.velocity,
w = oldBody.omega,
c = oldBody.centerOfMass;
detachingBody.velocity = v + w.Cross (detachingBody.centerOfMass - c);
remainingBody.velocity = v + w.Cross (remainingBody.centerOfMass - c);
detachingBody.omega = w;
remainingBody.omega = w; // unnecessary, already is
oldBody is initial compound,
remainingBody is the same compound wihout the detaching body
detachingBody is the new body.
Just set velocities like this that's all you need to do - no problem.
The discussion was about Stucuks assumption the detachingBody would have less angular velocity which is wrong.
Honestly, I'm a little surprised that there isn't a more robust system in place that deals with the case of "compound bodies", which is probably the best way to describe this. that's why I think the joints are the way to go.
I also wanted to ask: Is CustomHinge the best hinge/joint type to rigidly connect 2 objects? What are the constraints used for?
Compounds are robust - Julio could do those velocity settings automatitcally eventually.
But the user would be still responsible to set mass and moment of inertia values so he needs to care anyways.
The hinge is not ideal, for orientation it ends up using 2 angular rows to fix only 1 dof,
and the rest is done using linear rows.
It should work better to either use 3 linear or 3 angular rows - worth to test both (by creating your own joint).
What i would do is this:
Keep your hinge approach as a reference to compare it with the compound approach - they should react similar on detachement. (You need proper visuals here to compare, do they work now?)
When compound approach works, you may still need a joint for the transition (coupling two separated spaceship parts together) to simulate any nut and bolt or snapping mechanics.
Then when both parts are in place, change positions directly to eliminate any remaining tiny error, remove the joint and make the compound.
The necessary joint would need motors for both rotation and position to operate smoothly.
JoesRagdollJoint in StandartJoints.cpp demo has motor for orientation.
Adding motor for position would be a small change.
However, if ship control is accurate enough no joint is needed and you can go to compound directly.