Does someone know what is pinAndPivotFrame? Is it the matrix of the body or the matrix of the point to go to? and what are lineOrigin and lineSlope?
Thank you for your answers

Moderators: Sascha Willems, walaber
void CustomPathFollow::SubmitConstraints (dFloat timestep, int threadIndex)
{
dVector lineSlope (1.0f, 2.0f, -3.0f, 0.0f);
lineSlope = lineSlope.Scale (1.0f / dSqrt (lineSlope % lineSlope));
dVector lineOrigin (0.0f, 10.0f, 0.0f, 0.0);
dMatrix matrix0;
// Get the global matrices of each rigid body.
NewtonBodyGetMatrix(m_body0, &matrix0[0][0]);
matrix0 = m_localMatrix0 * matrix0;
// Restrict the movement on the pivot along the infine line
const dVector& p0 = matrix0.m_posit;
const dVector& p1 = lineOrigin + lineSlope.Scale ((matrix0.m_posit - lineOrigin) % lineSlope);
dMatrix randomTangents = dgGrammSchmidt (lineSlope);
NewtonUserJointAddLinearRow (m_joint, &p0[0], &p1[0], &randomTangents.m_up[0]);
NewtonUserJointAddLinearRow (m_joint, &p0[0], &p1[0], &randomTangents.m_right[0]);
if (1) // constrain orientation so pivot x axis stays parallel to line slope
{
// get a point along the ping axis at some reasonable large distance from the pivot
dVector q0 (p0 + matrix0.m_front.Scale(MIN_JOINT_PIN_LENGTH));
dVector q1 (p1 + lineSlope.Scale(MIN_JOINT_PIN_LENGTH));
// two more constraints rows to inforce the normal and binormal
NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_up[0]);
NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_right[0]);
}
}
void CreatePathFollowTest ()
{
sMat4 m; m.Identity(); m.Reset4thColumn();
Shape *shape = world->CreateBoxShape (sVec3(2.0, 0.5, 0.5));
m[3] = sVec3 (0, 1.0, 0);
Body *bPathFollow = world->CreateRigidBody (2.0, m, shape);
world->ReleaseShape (shape);
//m.Identity(); pivot.Reset4thColumn(); // this makes an offset of 1 unit
CustomPathFollow *joint = new CustomPathFollow ((dMatrix&)m, bPathFollow);
}
void StepPathFollowTest ()
{
sVec3 lineOrigin (0.0f, 10.0f, 0.0f);
sVec3 lineSlope (1.0f, 2.0f, -3.0f);
lineSlope.Normalize();
RenderVector (lineOrigin, lineSlope, 1,1,0);
}
fst::mat4 m = fst::translate(fst::mat4(1.f), fst::vec3(0.f,1.f,0.f));
joint = new CustomPathFollow(dgMatrix(&m[0].x), b, dgVector(&point.x));//point is the point to go to, eg lineOrigin
#define dMatrix dgMatrix
#define dVector dgVector
#define GetIdentityMatrix dgGetIdentityMatrix
#define dAtan2 atan2f
#define dAbs abs
#define dCos cosf
#define dSin sinf
#define dAssert assert
#define dSqrt sqrtf
#define MIN_JOINT_PIN_LENGTH 50.0f
//dInitRtti(CustomPathFollow);
CustomPathFollow::CustomPathFollow (const dMatrix& pinAndPivotFrame, NewtonBody* const child, dgVector _point)
:CustomJoint(6, child, NULL)
{
// calculate the two local matrix of the pivot point
dMatrix tmp;
point = _point;
CalculateLocalMatrix (pinAndPivotFrame, m_localMatrix0, tmp);
}
CustomPathFollow::~CustomPathFollow()
{
}
void CustomPathFollow::GetInfo (NewtonJointRecord* const info) const
{
/*
strcpy (info->m_descriptionType, "slider");
info->m_attachBody_0 = m_body0;
info->m_attachBody_1 = m_body1;
if (m_limitsOn) {
dFloat dist;
dMatrix matrix0;
dMatrix matrix1;
// calculate the position of the pivot point and the Jacobian direction vectors, in global space.
CalculateGlobalMatrix (m_localMatrix0, m_localMatrix1, matrix0, matrix1);
dist = (matrix0.m_posit - matrix1.m_posit) % matrix0.m_front;
info->m_minLinearDof[0] = m_minDist - dist;
info->m_maxLinearDof[0] = m_maxDist - dist;
} else {
info->m_minLinearDof[0] = -FLT_MAX ;
info->m_maxLinearDof[0] = FLT_MAX ;
}
info->m_minLinearDof[1] = 0.0f;
info->m_maxLinearDof[1] = 0.0f;;
info->m_minLinearDof[2] = 0.0f;
info->m_maxLinearDof[2] = 0.0f;
info->m_minAngularDof[0] = 0.0f;
info->m_maxAngularDof[0] = 0.0f;
info->m_minAngularDof[1] = 0.0f;
info->m_maxAngularDof[1] = 0.0f;
info->m_minAngularDof[2] = 0.0f;
info->m_maxAngularDof[2] = 0.0f;
memcpy (info->m_attachmenMatrix_0, &m_localMatrix0, sizeof (dMatrix));
memcpy (info->m_attachmenMatrix_1, &m_localMatrix1, sizeof (dMatrix));
*/
}
void CustomPathFollow::SubmitConstraints (dFloat timestep, int threadIndex)
{
dVector lineSlope (1.0f, 2.0f, -3.0f, 0.0f);
lineSlope = lineSlope.Scale4(1.0f / dSqrt (lineSlope % lineSlope));
dVector lineOrigin (0.0f, 10.0f, 0.0f, 0.0);
dMatrix matrix0;
// Get the global matrices of each rigid body.
NewtonBodyGetMatrix(m_body0, &matrix0[0][0]);
matrix0 = m_localMatrix0 * matrix0;
// Restrict the movement on the pivot along the infine line
const dVector& p0 = matrix0.m_posit;
const dVector& p1 = lineOrigin + lineSlope.Scale4((matrix0.m_posit - lineOrigin) % lineSlope);
dMatrix randomTangents = dgGrammSchmidt (lineSlope);
NewtonUserJointAddLinearRow (m_joint, &p0[0], &p1[0], &randomTangents.m_up[0]);
NewtonUserJointAddLinearRow (m_joint, &p0[0], &p1[0], &randomTangents.m_right[0]);
if (1) // constrain orientation so pivot x axis stays parallel to line slope
{
// get a point along the ping axis at some reasonable large distance from the pivot
dVector q0 (p0 + matrix0.m_front.Scale4(MIN_JOINT_PIN_LENGTH));
dVector q1 (p1 + lineSlope.Scale4(MIN_JOINT_PIN_LENGTH));
// two more constraints rows to inforce the normal and binormal
NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_up[0]);
NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_right[0]);
}
}
dMatrix dgGrammSchmidt(const dVector& dir)
{
dVector up;
dVector right;
dVector front (dir);
front = front.Scale4(1.0f / dSqrt (front % front));
if (dAbs (front.m_z) > 0.577f) {
right = front * dVector (-front.m_y, front.m_z, 0.0f,0.f);
} else {
right = front * dVector (-front.m_y, front.m_x, 0.0f,0.f);
}
right = right.Scale4(1.0f / dSqrt (right % right));
up = right * front;
front.m_w = 0.0f;
up.m_w = 0.0f;
right.m_w = 0.0f;
return dMatrix (front, up, right, dVector (0.0f, 0.0f, 0.0f, 1.0f));
}
arkdemon wrote:Is it normal that the body makes loops
arkdemon wrote:how can we calculate lineSLope?
fst::mat4 m = fst::mat4(1.f);
m[POS] = fst::vec4(0.f,1.f,0.f,1.f);
joint = new CustomPathFollow(dgMatrix(&m[0].x), b);
fst::mat4 m = pl::BodyMatrix(b);
m[POS] = fst::vec4(0.f,1.f,0.f,1.f);
joint = new CustomPathFollow(dgMatrix(&m[0].x), b);
fst::mat4 m = pl::BodyMatrix(b);
m[POS].w = 1.f;
joint = new CustomPathFollow(dgMatrix(&m[0].x), b);
joint->SetPathTarget(dgVector(0.f,10.f,0.f,0.f), dgVector(1.f,0.f,0.f,0.f));
Users browsing this forum: No registered users and 3 guests