just test the rag doll and there is still a bug, but I have to go now.
I check it out tonight.
Moderators: Sascha Willems, walaber
Julio Jerez wrote:but I always underestimate the amount of work
static void AddFlexiblePointToPoint (const float invTimestep, const Body* const body0, const Body* const body1, const Joint* const joint,
sQuat &cSpace, const sMat4 &matrix0, const sMat4 &matrix1,
const float reduceError, const float linearFriction, const float stiffness)
{
sQuat q1; matrix1.Rotation()->ToQuat (q1);
sVec3 pin0 = matrix0[3];
sVec3 pin1 = matrix1[3];
sVec3 diff = pin1 - pin0;
sVec3 v0 = BodyGetPointVelocity (body0, pin0);
sVec3 v1 = BodyGetPointVelocity (body1, pin1);
sVec3 relAcc = (diff * reduceError * invTimestep - (v0 - v1)) * invTimestep;
sMat3 basis;
sVec3 mainAxis = diff;
float sql = mainAxis.SqL();
if (sql > FP_EPSILON2)
{
sVec3 align = q1.Unrotate (mainAxis / sqrt (sql));
if (align.Dot(cSpace.XAxis()) < 0.0f) align *= -1.0f;
sQuat q; q.FromVecToVec (cSpace.XAxis(), align);
cSpace = q * cSpace;
cSpace.Normalize();
}
basis.FromQuat (q1 * cSpace);// constraint space attached to parent bone
for (int i=0; i<3; i++)
{
sVec3 &axis = basis[i];
NewtonUserJointAddLinearRow (joint, (float*)&pin0, (float*)&pin1, (float*)&axis);
NewtonUserJointSetRowAcceleration (joint, relAcc.Dot(axis));
#ifndef NEWTON_STIFF_JOINTS
NewtonUserJointSetRowMinimumFriction (joint, -linearFriction);
NewtonUserJointSetRowMaximumFriction (joint, linearFriction);
#endif
NewtonUserJointSetRowStiffness (joint, stiffness);
}
}
Users browsing this forum: No registered users and 1 guest