예제 #1
0
  @Override
  public void create() {
    super.create();
    instructions = "Tap a box to ray cast\nLong press to toggle debug mode\nSwipe for next test";

    // Create the entities
    world
        .add("ground", -7f, 0f, -7f)
        .color
        .set(
            0.25f + 0.5f * (float) Math.random(),
            0.25f + 0.5f * (float) Math.random(),
            0.25f + 0.5f * (float) Math.random(),
            1f);

    for (int x = 0; x < BOXCOUNT_X; x++) {
      for (int y = 0; y < BOXCOUNT_Y; y++) {
        for (int z = 0; z < BOXCOUNT_Z; z++) {
          world
              .add("box", BOXOFFSET_X + x, BOXOFFSET_Y + y, BOXOFFSET_Z + z)
              .color
              .set(
                  0.5f + 0.5f * (float) Math.random(),
                  0.5f + 0.5f * (float) Math.random(),
                  0.5f + 0.5f * (float) Math.random(),
                  1f);
        }
      }
    }

    rayTestCB = new ClosestRayResultCallback(Vector3.Zero, Vector3.Z);
  }
예제 #2
0
 @Override
 public void update() {
   float delta = Gdx.graphics.getRawDeltaTime();
   time += delta;
   super.update();
   if (contactCache != null) contactCache.update(delta);
 }
예제 #3
0
  @Override
  public void dispose() {
    // Deleting the active contact listener, also disables that particular type of contact listener.
    if (contactListener != null) contactListener.dispose();
    contactListener = null;

    super.dispose();
  }
예제 #4
0
 @Override
 public void dispose() {
   if (rayTestCB != null) rayTestCB.delete();
   rayTestCB = null;
   super.dispose();
 }
예제 #5
0
  @Override
  public void create() {
    super.create();

    final Model sphereModel =
        modelBuilder.createSphere(
            1f,
            1f,
            1f,
            8,
            8,
            new Material(
                ColorAttribute.createDiffuse(Color.WHITE),
                ColorAttribute.createSpecular(Color.WHITE)),
            Usage.Position | Usage.Normal);
    disposables.add(sphereModel);
    final BulletConstructor sphereConstructor =
        new BulletConstructor(sphereModel, 0.5f, new btSphereShape(0.5f));
    sphereConstructor.bodyInfo.setRestitution(1f);
    world.addConstructor("sphere", sphereConstructor);

    final Model sceneModel = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
    disposables.add(sceneModel);
    final BulletConstructor sceneConstructor =
        new BulletConstructor(sceneModel, 0f, new btBvhTriangleMeshShape(sceneModel.meshParts));
    sceneConstructor.bodyInfo.setRestitution(0.25f);
    world.addConstructor("scene", sceneConstructor);

    final BulletEntity scene =
        world.add("scene", (new Matrix4()).setToTranslation(0f, 2f, 0f).rotate(Vector3.Y, -90));
    scene.setColor(
        0.25f + 0.5f * (float) Math.random(),
        0.25f + 0.5f * (float) Math.random(),
        0.25f + 0.5f * (float) Math.random(),
        1f);
    scene.body.setContactCallbackFlag(2);

    world
        .add("ground", 0f, 0f, 0f)
        .setColor(
            0.25f + 0.5f * (float) Math.random(),
            0.25f + 0.5f * (float) Math.random(),
            0.25f + 0.5f * (float) Math.random(),
            1f);

    for (int x = 0; x < SPHERECOUNT_X; x++) {
      for (int y = 0; y < SPHERECOUNT_Y; y++) {
        for (int z = 0; z < SPHERECOUNT_Z; z++) {
          final BulletEntity e =
              (BulletEntity)
                  world.add(
                      "sphere",
                      SPHEREOFFSET_X + x * 3f,
                      SPHEREOFFSET_Y + y * 3f,
                      SPHEREOFFSET_Z + z * 3f);
          e.setColor(
              0.5f + 0.5f * (float) Math.random(),
              0.5f + 0.5f * (float) Math.random(),
              0.5f + 0.5f * (float) Math.random(),
              1f);

          e.body.setContactCallbackFilter(2);
        }
      }
    }

    if (USE_CONTACT_CACHE) {
      contactCache = new TestContactCache();
      contactCache.entities = world.entities;
      contactCache.setCacheTime(0.5f);
    } else {
      contactListener = new TestContactListener();
      contactListener.entities = world.entities;
    }
    time = 0;
  }