예제 #1
0
  private void addRigidBody(PhysicsRigidBody node) {
    if (physicsBodies.containsKey(node.getObjectId())) {
      logger.log(Level.WARNING, "RigidBody {0} already exists in PhysicsSpace, cannot add.", node);
      return;
    }
    physicsBodies.put(node.getObjectId(), node);

    // Workaround
    // It seems that adding a Kinematic RigidBody to the dynamicWorld prevent it from being non
    // kinematic again afterward.
    // so we add it non kinematic, then set it kinematic again.
    boolean kinematic = false;
    if (node.isKinematic()) {
      kinematic = true;
      node.setKinematic(false);
    }
    addRigidBody(physicsSpaceId, node.getObjectId());
    if (kinematic) {
      node.setKinematic(true);
    }

    logger.log(Level.FINE, "Adding RigidBody {0} to physics space.", node.getObjectId());
    if (node instanceof PhysicsVehicle) {
      logger.log(
          Level.FINE,
          "Adding vehicle constraint {0} to physics space.",
          Long.toHexString(((PhysicsVehicle) node).getVehicleId()));
      physicsVehicles.put(((PhysicsVehicle) node).getVehicleId(), (PhysicsVehicle) node);
      addVehicle(physicsSpaceId, ((PhysicsVehicle) node).getVehicleId());
    }
  }