addBody method

void addBody(
  1. Body body
)

Add a rigid body to the simulation. @todo If the simulation has not yet started, why recrete and copy arrays for each body? Accumulate in dynamic arrays in this case. @todo Adding an array of bodies should be possible. This would save some loops too

Implementation

void addBody(Body body) {
  if (bodies.contains(body)) {
    return;
  }
  body.index = bodies.length;
  bodies.add(body);
  body.world = this;
  body.initPosition.copy(body.position);
  body.initVelocity.copy(body.velocity);
  body.timeLastSleepy = time;
  //if (body is Body) {
    body.initAngularVelocity.copy(body.angularVelocity);
    body.initQuaternion.copy(body.quaternion);
  //}
  collisionMatrix.setNumObjects(bodies.length);
  addBodyEvent.target = body;
  idToBodyMap[body.id] = body;
  dispatchEvent(addBodyEvent);
}