예제 #1
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);
 }
예제 #2
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);
 }
예제 #3
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);
  }
예제 #4
0
  @Override
  public void dispose() {
    groundObject.dispose();
    groundShape.dispose();

    ballObject.dispose();
    ballShape.dispose();

    dispatcher.dispose();
    collisionConfig.dispose();

    modelBatch.dispose();
    model.dispose();
  }
예제 #5
0
 @Override
 public void onContactEnded(
     btCollisionObject colObj0, boolean match0, btCollisionObject colObj1, boolean match1) {
   final int userValue0 = colObj0.getUserValue();
   final int userValue1 = colObj1.getUserValue();
   if (match0) {
     final BulletEntity e = (BulletEntity) (entities.get(userValue0));
     e.setColor(Color.BLUE);
     Gdx.app.log(Float.toString(time), "Contact ended " + userValue0);
   }
   if (match1) {
     final BulletEntity e = (BulletEntity) (entities.get(userValue1));
     e.setColor(Color.BLUE);
     Gdx.app.log(Float.toString(time), "Contact ended " + userValue1);
   }
 }
예제 #6
0
  @Override
  public void dispose() {
    characterController.dispose();
    ghostObject.dispose();
    actionZone.dispose();

    leftweapon.dispose();
    rightweapon.dispose();
  }
예제 #7
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);
  }
예제 #8
0
 @Override
 protected synchronized void delete() {
   if (swigCPtr != 0) {
     if (swigCMemOwn) {
       swigCMemOwn = false;
       DynamicsJNI.delete_btRigidBody(swigCPtr);
     }
     swigCPtr = 0;
   }
   super.delete();
 }
예제 #9
0
 @Override
 protected synchronized void delete() {
   if (swigCPtr != 0) {
     if (swigCMemOwn) {
       swigCMemOwn = false;
       SoftbodyJNI.delete_btSoftBody(swigCPtr);
     }
     swigCPtr = 0;
   }
   super.delete();
 }
예제 #10
0
  public void update(float delta) {
    // tmp.set(acceleration);
    // tmp.scl(delta);
    // velocity.add(tmp);
    // velocity = velocity.scl(0.95f);
    tmp.set(velocity);
    tmp.scl(delta);
    position.add(tmp);

    transform.setTranslation(position);
    collisionObject.setWorldTransform(transform);
  }
예제 #11
0
  @Override
  public void render() {
    final float delta = Math.min(1f / 30f, Gdx.graphics.getDeltaTime());

    if (!collision) {
      ball.transform.translate(0f, -delta, 0f);
      ballObject.setWorldTransform(ball.transform);

      collision = checkCollision();
    }

    camController.update();

    Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1.f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    modelBatch.begin(cam);
    modelBatch.render(instances, environment);
    modelBatch.end();
  }
예제 #12
0
 @Override
 protected void finalize() throws Throwable {
   if (!destroyed) destroy();
   super.finalize();
 }
예제 #13
0
 @Override
 protected void reset(long cPtr, boolean cMemoryOwn) {
   if (!destroyed) destroy();
   super.reset(DynamicsJNI.btRigidBody_SWIGUpcast(swigCPtr = cPtr), cMemoryOwn);
 }
예제 #14
0
 @Override
 public void dispose() {
   if (motionState != null) motionState.release();
   motionState = null;
   super.dispose();
 }
예제 #15
0
 @Override
 protected void reset(long cPtr, boolean cMemoryOwn) {
   if (!destroyed) destroy();
   super.reset(SoftbodyJNI.btSoftBody_SWIGUpcast(swigCPtr = cPtr), cMemoryOwn);
 }