ConstantVolumeJoint constructor

ConstantVolumeJoint(World argWorld, ConstantVolumeJointDef def)

Implementation

ConstantVolumeJoint(World argWorld, ConstantVolumeJointDef def)
    : _bodies = def.bodies.toList(growable: false),
      super(argWorld.getPool(), def) {
  _world = argWorld;
  if (def.bodies.length <= 2) {
    throw "You cannot create a constant volume joint with less than three _bodies.";
  }

  _targetLengths = new Float64List(_bodies.length);
  for (int i = 0; i < _targetLengths.length; ++i) {
    final int next = (i == _targetLengths.length - 1) ? 0 : i + 1;
    double dist = (_bodies[i].worldCenter - _bodies[next].worldCenter).length;
    _targetLengths[i] = dist;
  }
  _targetVolume = getBodyArea();

  if (def.joints != null && def.joints.length != def.bodies.length) {
    throw "Incorrect joint definition.  Joints have to correspond to the _bodies";
  }
  if (def.joints == null) {
    final DistanceJointDef djd = new DistanceJointDef();
    _distanceJoints = new List<DistanceJoint>(_bodies.length);
    for (int i = 0; i < _targetLengths.length; ++i) {
      final int next = (i == _targetLengths.length - 1) ? 0 : i + 1;
      djd.frequencyHz = def.frequencyHz; // 20.0;
      djd.dampingRatio = def.dampingRatio; // 50.0;
      djd.collideConnected = def.collideConnected;
      djd.initialize(_bodies[i], _bodies[next], _bodies[i].worldCenter,
          _bodies[next].worldCenter);
      _distanceJoints[i] = _world.createJoint(djd) as DistanceJoint;
    }
  } else {
    _distanceJoints = def.joints.toList();
  }

  _normals = new List<Vector2>(_bodies.length);
  for (int i = 0; i < _normals.length; ++i) {
    _normals[i] = new Vector2.zero();
  }
}