ConeTwistConstraint constructor

ConeTwistConstraint(
  1. Body bodyA,
  2. Body bodyB, {
  3. Vec3? pivotA,
  4. Vec3? pivotB,
  5. Vec3? axisA,
  6. Vec3? axisB,
  7. double angle = 0,
  8. double twistAngle = 0,
  9. double maxForce = 1e6,
  10. bool collideConnected = false,
})

Implementation

ConeTwistConstraint(
  Body bodyA,
  Body bodyB,
  {
    Vec3? pivotA,
    Vec3? pivotB,
    Vec3? axisA,
    Vec3? axisB,
    this.angle = 0,
    this.twistAngle = 0,
    double maxForce = 1e6,
    bool collideConnected = false
  }
):super(bodyA, bodyB, pivotA, pivotB, maxForce){

  // Set pivot point in between
  this.pivotA = pivotA?.clone() ?? Vec3();
  this.pivotB = pivotB?.clone() ?? Vec3();

  this.axisA = axisA?.clone() ?? Vec3();
  this.axisB = axisB?.clone() ?? Vec3();

  coneEquation = ConeEquation(
    bodyA,
    bodyB,
    maxForce: 0,
    angle: angle,
    axisA: this.axisA,
    axisB: this.axisB
  );
  final c = coneEquation;
  twistEquation = RotationalEquation(
    bodyA,
    bodyB,
    maxAngle: twistAngle,
    maxForce: 0,
    axisA: this.axisA,
    axisB: this.axisB
  );
  final t = twistEquation;

  // Make the cone equation push the bodies toward the cone axis, not outward
  c.minForce = -maxForce;

  // Make the twist equation add torque toward the initial position
  t.minForce = -maxForce;

  equations.addAll([c,t]);
}