@Override
 public void dispose() {
   // Don't rely on the GC
   if (worldTransform != null) worldTransform.dispose();
   if (body != null) body.delete();
   // And remove the reference
   worldTransform = null;
   body = null;
 }
 public Entity(
     final Mesh mesh,
     final btRigidBodyConstructionInfo bodyInfo,
     final float x,
     final float y,
     final float z) {
   this.mesh = mesh;
   worldTransform = new WorldTransform();
   worldTransform.transform.idt().translate(x, y, z);
   body = new btRigidBody(bodyInfo);
   body.setMotionState(worldTransform);
 }
Beispiel #3
0
  @Override
  public boolean tap(float x, float y, int count, int button) {
    Ray ray = camera.getPickRay(x, y);
    rayFrom.set(ray.origin);
    rayTo.set(ray.direction).mul(50f).add(rayFrom); // 50 meters max from the origin

    // Because we reuse the ClosestRayResultCallback, we need reset it's values
    rayTestCB.setM_collisionObject(null);
    rayTestCB.setM_closestHitFraction(1f);
    rayTestCB.getM_rayFromWorld().setValue(rayFrom.x, rayFrom.y, rayFrom.z);
    rayTestCB.getM_rayToWorld().setValue(rayTo.x, rayTo.y, rayTo.z);

    world.collisionWorld.rayTest(rayFrom, rayTo, rayTestCB);

    if (rayTestCB.hasHit()) {
      final btCollisionObject obj = rayTestCB.getM_collisionObject();
      if (!obj.isStaticOrKinematicObject()) {
        final btRigidBody body = btRigidBody.upcast(obj);
        body.activate();
        body.applyCentralImpulse(Vector3.tmp2.set(ray.direction).mul(20f));
      }
    }
    return true;
  }