Exemplo n.º 1
0
  @Override
  public void create() {
    Bullet.init();

    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(3f, 7f, 10f);
    cam.lookAt(0, 4f, 0);
    cam.update();

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);

    ModelBuilder mb = new ModelBuilder();
    mb.begin();
    mb.node().id = "ground";
    mb.part(
            "box",
            GL20.GL_TRIANGLES,
            Usage.Position | Usage.Normal,
            new Material(ColorAttribute.createDiffuse(Color.RED)))
        .box(5f, 1f, 5f);
    mb.node().id = "ball";
    mb.part(
            "sphere",
            GL20.GL_TRIANGLES,
            Usage.Position | Usage.Normal,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)))
        .sphere(1f, 1f, 1f, 10, 10);
    model = mb.end();

    ground = new ModelInstance(model, "ground");
    ball = new ModelInstance(model, "ball");
    ball.transform.setToTranslation(0, 9f, 0);

    instances = new Array<ModelInstance>();
    instances.add(ground);
    instances.add(ball);

    ballShape = new btSphereShape(0.5f);
    groundShape = new btBoxShape(new Vector3(2.5f, 0.5f, 2.5f));

    groundObject = new btCollisionObject();
    groundObject.setCollisionShape(groundShape);
    groundObject.setWorldTransform(ground.transform);

    ballObject = new btCollisionObject();
    ballObject.setCollisionShape(ballShape);
    ballObject.setWorldTransform(ball.transform);

    collisionConfig = new btDefaultCollisionConfiguration();
    dispatcher = new btCollisionDispatcher(collisionConfig);
  }
Exemplo n.º 2
0
 @Override
 public BulletEntity construct(final Matrix4 transform) {
   if (bodyInfo == null && shape != null) {
     btCollisionObject obj = new btCollisionObject();
     obj.setCollisionShape(shape);
     return new BulletEntity(model, obj, transform);
   } else return new BulletEntity(model, bodyInfo, transform);
 }
Exemplo n.º 3
0
 @Override
 public BulletEntity construct(float x, float y, float z) {
   if (bodyInfo == null && shape != null) {
     btCollisionObject obj = new btCollisionObject();
     obj.setCollisionShape(shape);
     return new BulletEntity(model, obj, x, y, z);
   } else return new BulletEntity(model, bodyInfo, x, y, z);
 }
Exemplo n.º 4
0
  public Projectile(
      Vector3 startingPosition, Vector3 direction, float msSpeed, btCollisionWorld world) {
    btCollisionShape sphere = new btSphereShape(0.5f);
    collisionObject = new btCollisionObject();
    collisionObject.setCollisionShape(sphere);
    collisionObject.userData = this;
    world.addCollisionObject(collisionObject);

    position = new Vector3(startingPosition);
    /*
    acceleration = new Vector3(direction);
    acceleration.nor().scl(msSpeed);*/

    velocity = new Vector3(direction);
    velocity.nor().scl(msSpeed);
    transform = new Matrix4();
    transform.setTranslation(position);
    collisionObject.setWorldTransform(transform);
  }