Minimum Joint Stiffness in 2.0?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Minimum Joint Stiffness in 2.0?

Postby derdragon » Mon Mar 16, 2009 1:16 pm

Is there a minimum value you can set stiffness to for a linear row in a custom joint? My expectation would be that if I set the stiffness to 0, that the joint would essentially not act on the bodies. I'd like to do this to basically disable a row if the force on it is negative. What I'm trying to do is create a ball joint that only applies force if the distance between the two points of reference is greater than a certain amount, essentially creating an effect as though one object were dragging another by a rope.

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);
        }
derdragon
 
Posts: 13
Joined: Fri Aug 03, 2007 12:56 pm

Re: Minimum Joint Stiffness in 2.0?

Postby Julio Jerez » Mon Mar 16, 2009 2:17 pm

I cannot visualize how that cont will behaving, but can tell you the will certainly not behave as a rope.
The best analogy for a rope behavior is a reverse contact. If you understand how a contact works, then is easy to make a rope type of joint.
Basically a contact is a joint the prevent tow bodies for interpenetrating, but is does nothing If the are moving apart,
In this case you want to prevent the pivot of two bodies from moving outside come radios.

The information you have is:
P0 the pivot point on body0
P1 the pivot point on body1
R the maximum distant the you need to maintain,
The distance between the two point cannot be larger the R, but if can be smaller.

When you create the joint you nee to save these information with joint in local space
Code: Select all
Let p0 be the pivot is local space on body0
Let p0 be the pivoy is local space on body1

The constrain call back should be like this:


//Calculate q0 and q1 steh the pivots in global space

Vector q0 = GetBodyMatrix().Transfopremn(p0);
Vector q1 = GetBodyMatrix().Transfopremn(p0);

// calcualet distance between  pivots
Vector dq (q1 – q0);
// if the distance larger thane R, inforce constarint
If ( dotProduct(qp, qp) >=  R * R) {
     // the bodies are moving appar
    // the the p[oint alone the line between p0, and q1 at distance R
   Q’0 = q0 + (q1 – q0) * ( R / sqrtf (dotProduct(qp, qp));

  // now you have two points to emit a contact point constraint q’0, and q1
 // summint a contraiont that will drive the distance between those two to zero if they are poving appart.
  //The pin direction is
Vetors dir (dq.Scale (1.0f / sqrtf (dotProduct(qp, qp));
 NewtonUserJointAddLinearRow(joint,&q’0.x,&q1.x, dir.x);

// now you need to make sure the constraint only add attraction force or zero repultion force, (this is the rope trick)
NewtonUserJointSetRowMaximumFriction (const NewtonJoint* joint, 0);
// you may have to try here if NewtonUserJointSetRowMaximumFriction
// Add a repulsion force then use NewtonUserJointSetRowMinimunFriction (const NewtonJoint* joint, 0)
// or you can revers the pin diretion  dir = -dir;  NewtonUserJointAddLinearRow(joint,&q’0.x,&q1.x, dir.x);
// iether way will work fine
;
}


And badbin badbum you get your joint effect
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Minimum Joint Stiffness in 2.0?

Postby derdragon » Mon Mar 16, 2009 3:07 pm

NewtonUserJointSetRowMaximumFriction(), exactly what I was needing! Thank you so much!
derdragon
 
Posts: 13
Joined: Fri Aug 03, 2007 12:56 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 23 guests

cron