The effect works fine with the code I have now, but at the edge of the limit, the bodies are also able to push each other with the joint, until I sort of "overcome" it. The pushing forces always return a positive value with NewtonUserJointGetRowForce, and pulling forces always return a negative. What I'd like to do is just zero the stiffness if the result is positive, if that's possible. Right now, for any of my joints, if I set stiffness to 0, the joint is less solid, but it's still definitely affecting the bodies.
Here's an example of the code I'm using:
- Code: Select all
NewtonBodyGetMatrix(((Obj*)parent)->body, matrix);
MatrixToQuatPos( matrix, nodedatums[parent].orient, nodedatums[parent].pos);
Ogre::Vector3 X = newtonVector(nodedatums[parent].pos+nodedatums[parent].orient*A->get_vec3(VAR_POSITIONPARENT));
if(typeint==JT_BALL) {
Ogre::Vector3 P = V-X;
float a = P.normalise()-A->get_float(VAR_LENGTH)/NEWTON_SCALE;
if(a>0) {
V -= P*A->get_float(VAR_LENGTH)/NEWTON_SCALE;
NewtonUserJointAddLinearRow(joint,&V.x,&X.x,&P.x);
NewtonUserJointSetRowStiffness(joint,stiffness);
A->set(VAR_FORCE,NewtonUserJointGetRowForce(joint,0)*-1);
}
else A->set(VAR_FORCE,0);
}