Constraints Example

/*
** Example: RigidBodies_Constraints.kl
*/

require Util;
require Math;
require Geometry;
require BulletHelpers;


function Init_Constraints(io RigidBodySimulation sim, Integer count)
{
  sim.initPhysics();

  sim.createGround();

  sim.createGround();
  UInt32 seed = 1243;
  UInt32 gen = 0;

  Scalar radius = 1.0;
  BulletCollisionShape sphereShape = BulletSphereShape(radius);

  PolygonMesh sphereMesh(); 
  sphereMesh.addSphere(Xfo(), radius, 12, true, false);

  BulletRigidBody bodies[];
  for(Integer i=0; i<count; i++){
    Xfo xfo;
    xfo.tr = Vec3(mathRandomScalar(seed, gen++) * 0.1, 1.0 + Scalar(i) * 2.0, mathRandomScalar(seed, gen++) * 0.1);
    BulletRigidBody rbm = sim.addRigidBody(1.0, 0.5, 0.0, xfo, Vec3(), Vec3(), sphereShape);
    bodies.push(rbm);
  }

  // add the constraints
  for(Integer i=0; i<bodies.size - 1; i++){
    Vec3 pivotA(0.0,radius,0.0);
    Vec3 pivotB(0.0,-radius,0.0);
    BulletTypedConstraint constraint = BulletPoint2PointConstraint(bodies[i], bodies[i+1], pivotA, pivotB);

    sim.dynamicsWorld.addConstraint(constraint, false); 
  }
}

operator entry(){

  RigidBodySimulation sim();
  Init_Constraints(sim, 5);

  String reportedTransforms[];
  reportedTransforms.resize(sim.rigidBodies.size());

  for(Integer i=0; i<100; i++){
    sim.stepSimulation();

    if((i%60)==0){
      // Report X vertex positions;
      for(Integer k=0; k<sim.rigidBodies.size(); k++){
        BulletRigidBody rbm = sim.rigidBodies[k];
        reportedTransforms[k] = unitTestPrint(rbm.getWorldTransform());
      }
      report("i:"+i + " xfos:" + reportedTransforms);
    }
  }

  // Force the destruction of the sim object.
  sim = null;

  report("entry<<<<");
}

/*
** Output:
(stdin):37:20: error: must use parentheses to call methods


*/