Ejemplo n.º 1
0
 /**
  * Method responsible for sphere mesh (player) movement.
  *
  * @param body loads current RigidBody body that is used.
  */
 public void sphereMovement(RigidBody body) {
   spherex = Gdx.input.getAccelerometerX();
   spherey = Gdx.input.getAccelerometerY();
   position.add(-spherex / 10, spherey / 10, 0);
   movement1.x = -spherex / 10;
   movement1.z = spherey / 10;
   physics.applyCentralImpulse(body, movement1);
 }
Ejemplo n.º 2
0
  /**
   * Method initializes physics, creates collision body from: -mesh shape -mesh geometry -mesh
   * motion state
   */
  public void initPhysics() {
    float spheremass = 5.0f, wallmass = 0.0f, offset = 3.5f;

    physics.createPhysicsWorld(
        new org.siprop.bullet.util.Vector3(-60.0f, -60.0f, -60.0f),
        new org.siprop.bullet.util.Vector3(60.0f, 60.0f, 60.0f),
        200,
        new org.siprop.bullet.util.Vector3(0.0f, -10.0f, 0.0f));

    groundShape = new StaticPlaneShape(new org.siprop.bullet.util.Vector3(0.0f, 1.0f, 0.0f), 0.0f);
    groundGeom =
        physics.createGeometry(
            groundShape, 0.0f, new org.siprop.bullet.util.Vector3(0.0f, 0.0f, 0.0f));
    groundState = new MotionState();
    groundState.worldTransform = new Transform(new Point3(12f, -10.0f, 11.5f));

    sphereShape = new SphereShape(1.5f);
    sphereGeom = physics.createGeometry(sphereShape, spheremass, origin);
    sphereState = new MotionState();
    org.siprop.bullet.util.Vector3 spherelocalInertia =
        new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
    sphereGeom.localInertia = spherelocalInertia;
    sphereState.worldTransform = new Transform(new Point3(pozx, pozy, pozz));

    physics.createAndAddRigidBody(sphereGeom, sphereState);
    physics.createAndAddRigidBody(groundGeom, groundState);

    for (int i = 0; i < 17; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(40.0f, -10.0f, -17.0f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 16; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(36.3f - offset * j, -10.0f, 39.5f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 16; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(36.3f - offset * j, -10.0f, -17.0f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 17; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(-20.0f, -10.0f, -17.0f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 3; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(-6.0f - offset * j, -10.0f, -13.5f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 3; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(-9.5f - offset * j, -10.0f, -6.5f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 6; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(-2.0f, -10.0f, -14.0f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 3; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(-2.5f - offset * j, -10.0f, 6.0f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 2; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(-9.5f - offset * j, -10.0f, 2.5f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 4; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(-9.5f, -10.0f, 8.5f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 4; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(-9.5f, -10.0f, 26.5f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 1; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(-16.5f - offset * j, -10.0f, 11.5f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 1; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(-13f - offset * j, -10.0f, 18.5f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 1; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(-16.5f - offset * j, -10.0f, 28.5f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 4; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(4.5f - offset * j, -10.0f, 19.0f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 3; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(1.0f - offset * j, -10.0f, 26.5f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 3; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(1.0f, -10.0f, 30.0f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 2; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(8.5f, -10.0f, 26.5f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 5; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(22.5f - offset * j, -10.0f, 33.0f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 10; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(12.0f, -10.0f, -6.0f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 3; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(11.0f - offset * j, -10.0f, 12.0f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 1; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(-6.0f, -10.0f, 12.0f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 5; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(5.0f, -10.0f, -9.5f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 4; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(18.5f - offset * j, -10.0f, -9.5f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 3; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(25.5f, -10.0f, -9.5f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 4; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(18.5f, -10.0f, -6.0f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 3; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(29.0f - offset * j, -10.0f, 4.5f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 3; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(36.5f - offset * j, -10.0f, -10.0f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 6; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(32.5f, -10.0f, -1.5f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 5; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(36.5f - offset * j, -10.0f, 24.0f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 4; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(29.5f, -10.0f, 27.5f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 2; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(19.0f - offset * j, -10.0f, 15.5f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int j = 0; j < 2; j++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(30.0f - offset * j, -10.0f, 15.5f));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 2; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(26.5f, -10.0f, 8.5f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    for (int i = 0; i < 2; i++) {
      wallShapeZ = new BoxShape(wallSizeZ);
      wallGeomZ = physics.createGeometry(wallShapeZ, wallmass, origin);
      wallStateZ = new MotionState();
      org.siprop.bullet.util.Vector3 walllocalInertiaZ =
          new org.siprop.bullet.util.Vector3(0.026f, 0.026f, 0.026f);
      wallShapeZ.calculateLocalInertia(wallmass, walllocalInertiaZ);
      wallGeomZ.localInertia = walllocalInertiaZ;
      wallStateZ.worldTransform = new Transform(new Point3(19.0f, -10.0f, 8.5f + offset * i));
      physics.createAndAddRigidBody(wallGeomZ, wallStateZ);
    }

    // 170 obj
  }
Ejemplo n.º 3
0
  /**
   * This method is responsible for OpenGL rendering mechanism. Adds lighting to the world. Checks
   * rigidBody map for proper collisionshapes (like SphereShape or BoxShape).
   */
  public void render(float delta) {
    float[] light_ambient = new float[] {1.5f, 1.5f, 1.5f, 1.5f};
    float[] light_diffuse = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
    float[] light_specular = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
    float[] light_position0 = new float[] {1.0f, 10.0f, 1.0f, 0.0f};
    light_position0[0] = position.x + 10;
    light_position0[1] = position.y;
    light_position0[2] = position.z;
    float x = 0.0f, z = 0.0f;

    GL10 gl = Gdx.graphics.getGL10();
    deltaTime = Gdx.graphics.getDeltaTime();

    Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, light_ambient, 0);
    Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, light_diffuse, 0);
    Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, light_specular, 0);
    Gdx.graphics.getGL11().glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, light_position0, 0);

    Gdx.graphics.getGL11().glEnable(GL10.GL_LIGHTING);
    Gdx.graphics.getGL11().glEnable(GL10.GL_LIGHT0);

    Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);

    Gdx.gl.glEnable(GL10.GL_CULL_FACE);
    Gdx.gl.glEnable(GL10.GL_TEXTURE_2D);

    startTime = System.nanoTime();
    rigidBody = physics.doSimulation(deltaTime, 1);
    endTime = (System.nanoTime() - startTime) / 1000000000.0f;

    for (RigidBody body : rigidBody.values()) {

      if (body.geometry.shape.getType() == ShapeType.BOX_SHAPE_PROXYTYPE) {
        gl.glPushMatrix();

        body.motionState.resultSimulation.getOpenGLMatrix(glMat);
        gl.glMultMatrixf(glMat, 0);

        wallShapeZ = (BoxShape) body.geometry.shape;

        wood.bind();
        gl.glRotatef(270, 1, 0, 0);
        gl.glScalef(7, 7, 7);
        wall.render(GL10.GL_TRIANGLES);
        gl.glPopMatrix();
      }

      if (body.geometry.shape.getType() == ShapeType.STATIC_PLANE_PROXYTYPE) {
        gl.glPushMatrix();

        body.motionState.resultSimulation.getOpenGLMatrix(glMat);
        gl.glMultMatrixf(glMat, 0);

        groundShape = (StaticPlaneShape) body.geometry.shape;

        stone.bind();
        gl.glRotatef(270, 1, 0, 0);
        gl.glScalef(6f, 6f, 6f);
        plane.render(GL10.GL_TRIANGLES);
        gl.glPopMatrix();
      }

      if (body.geometry.shape.getType() == ShapeType.SPHERE_SHAPE_PROXYTYPE) {

        gl.glPushMatrix();

        sphereMovement(body);

        body.motionState.resultSimulation.getOpenGLMatrix(glMat);
        gl.glMultMatrixf(glMat, 0);

        x = body.motionState.resultSimulation.originPoint.x;
        z = body.motionState.resultSimulation.originPoint.z;

        if ((x >= 19.0 && x <= 26.5) && (z >= 8.4 && z <= 8.6)) {
          Gdx.app.log("Zwyciestwo", "lolol");
        }

        if (indexior == 0) black.bind();
        else if (indexior == 1) green.bind();
        else if (indexior == 2) pink.bind();
        else if (indexior == 3) steel.bind();
        else if (indexior == 4) maja.bind();

        sphere.render(GL10.GL_TRIANGLES);
        gl.glPopMatrix();
        cameraSetup(body);
      }
    }

    if (Gdx.input.justTouched()) {
      FileHandle fh = Gdx.files.local("ala.txt");
      fh.writeString(
          String.valueOf(x) + " " + String.valueOf(z) + " " + String.valueOf(indexior), false);
      game.setScreen(new MenuScreen(game));
    }

    gl.glPushMatrix();
    gl.glTranslatef(22.0f, -10.0f, 8.5f);
    gl.glScalef(1.0f, 1.0f, 1.0f);
    gl.glRotatef(270, 1, 0, 0);
    aim.bind();
    target.render(GL10.GL_TRIANGLES);
    gl.glPopMatrix();

    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_DEPTH_TEST);
  }