preSolve method

  1. @override
void preSolve(
  1. double timeStep,
  2. double invTimeStep
)
override

Prepare for solving the constraint

Implementation

@override
void preSolve(double timeStep,double invTimeStep ) {
  updateAnchorPoints();

  ax1..setFrom(localAxis1)..applyMatrix3Transpose(body1!.rotation );
  ax2..setFrom(localAxis2)..applyMatrix3Transpose(body2!.rotation );

  an1..setFrom(localAngle1)..applyMatrix3Transpose(body1!.rotation );
  an2..setFrom(localAngle2)..applyMatrix3Transpose(body2!.rotation );

  // normal tangent binormal

  nor..setValues(
    ax1.x*body2!.inverseMass + ax2.x*body1!.inverseMass,
    ax1.y*body2!.inverseMass + ax2.y*body1!.inverseMass,
    ax1.z*body2!.inverseMass + ax2.z*body1!.inverseMass
  )..normalize();

  tan.tangent(nor).normalize();

  bin.cross2(nor,tan);

  // calculate hinge angle

  double limite = Math.acosClamp(Math.dotVectors(an1, an2) );

  tmp.cross2(an1, an2);

  if(Math.dotVectors(nor, tmp) < 0){limitMotor.angle = -limite;}
  else{limitMotor.angle = limite;}

  tmp.cross2(ax1, ax2);

  r3.limitMotor2.angle = Math.dotVectors(tan, tmp);
  r3.limitMotor3.angle = Math.dotVectors(bin, tmp);

  // preSolve

  r3.preSolve(timeStep, invTimeStep);
  lc.preSolve(timeStep, invTimeStep);
}