Apply constraint forces to only one object of pair

Post Reply
ktfh
Posts: 44
Joined: Thu Apr 14, 2016 3:44 pm

Apply constraint forces to only one object of pair

Post by ktfh »

I would like to create a hinge or ballsocket style constraint that only affects one object of the pair, looking at all the different constraint types it seems its only possible to either constrain two objects mutually or to constrain a single object to a point in space. Any suggestions on how to create a parent -> child constraint where the parent does not not experience the force of the constraint?
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Apply constraint forces to only one object of pair

Post by benelot »

Hello,

How about constraining a single object A to a point in space (position of object B) and then updating the point as you move object B around? Or what does it mean to not experience the force of the constraint?
ktfh
Posts: 44
Joined: Thu Apr 14, 2016 3:44 pm

Re: Apply constraint forces to only one object of pair

Post by ktfh »

I tried this out, using btConeTwistConstraint and updating the constraint position in the internalPreTickCallback, using both the parent rigid bodies world position and predicted world position. BUT the joints position on the parent object drifts when the parent object accelerates. I am looking through the step simulation code and I don't think this is a feasible way to constrain stuff because of the order in which, forces, collisions and constraints are resolved.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Apply constraint forces to only one object of pair

Post by benelot »

What does it mean for the joint position to drift when the parent object accelerates? Does that mean it gets an offset to where you would expect it? Is it the joint attachment point that drifts or is it just that the joint elongates because of the acceleration? For now I do not see what happens.
ktfh
Posts: 44
Joined: Thu Apr 14, 2016 3:44 pm

Re: Apply constraint forces to only one object of pair

Post by ktfh »

When I create a constraint directly between the parent and child object they appear perfectly connected, when I use a static btRigidBody in place of the parent object the constraints position drifts opposite of the direction of acceleration, when the parent object is still it appears perfectly connected again. I tried using both the parent objects getWorldPosition transform and the predictIntegratedTransform but both cause the attachment point to drift.

I've been looking through the code, to try and understand how constraints work. It seems btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup turns the btConeTwistConstraint into 3 btSolverConstraints and 2 btSolverBody and then I think btSequentialImpulseConstraintSolver::resolveSingleConstraintRowGenericSIMD resolves both bodies linear and angular velocities simultaneously. After this btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyFinish applies the btSolverBody velocities to the actual btRigidBodies.

I wonder if adding an extra influence multiplier for each body to btSolverConstraint could work or would the constraints apparent position drift because only one body is under its influence? I think I would have to rewrite a bunch of ResolveSingleConstraintRowGeneric functions, possibly other implications with this solution. Another option I've been thinking about is using a separate dynamics world for these constraints that I don't want influencing other objects, but I think I would have to write my own step simulation function for it and interleave it with the main dynamics worlds step simulation. I am open to any other ideas, still not familiar with how the whole code base works.
ktfh
Posts: 44
Joined: Thu Apr 14, 2016 3:44 pm

Re: Apply constraint forces to only one object of pair

Post by ktfh »

I took another stab at this, turns out the links apparent position seemed to drift so much because the parent objects velocity was completely unaccounted for in the constraint, using a kinematic object the velocity is inferred based on the deltas between steps. The constraint seems WAY better positioned than before where it drifted equal to velocity. Now it mostly drifts afew centimeters based on acceleration and collisions.

Code: Select all

btRigidBody* parent;
btRidigBody* child;
btRigidBody* imposter = new btRigidBody(0, 0, 0);
btGeneric6DofConstraint* constraint = new btGeneric6DofConstraint(
	*child,
	*imposter,
	btTransform(btQuaternion(0,0,0,1),btVector3(1,2,3)),
	btTransform(btQuaternion(0,0,0,1),btVector3(3,2,1)),
	false
	);
myDynamicsWorld->addConstraint(constraint, true);

void myPreTickCallback(btDynamicsWorld *world, btScalar delta) {
	imposter->setWorldTransform(parent->getWorldTransform);
	imposter->saveKinematicState(delta);
};
Post Reply