Example #1
0
  public List<CollisionVolume> getCollidingObject(CollisionModel model) {
    // TODO Make this more general
    final int minX = MathHelper.floor(model.getPosition().getX());
    final int minY = MathHelper.floor(model.getPosition().getY());
    final int minZ = MathHelper.floor(model.getPosition().getZ());
    final int maxX = minX + 1;
    final int maxY = minY + 1;
    final int maxZ = minZ + 1;

    final LinkedList<CollisionVolume> colliding = new LinkedList<CollisionVolume>();

    final BoundingBox mutable = new BoundingBox(0, 0, 0, 0, 0, 0);
    final BoundingBox position = new BoundingBox((BoundingBox) model.getVolume());
    position.offset(minX, minY, minZ);

    for (int dx = minX; dx < maxX; dx++) {
      for (int dy = minY - 1; dy < maxY; dy++) {
        for (int dz = minZ; dz < maxZ; dz++) {
          BlockMaterial material = this.getBlockMaterial(dx, dy, dz);
          mutable.set((BoundingBox) material.getBoundingArea());
          mutable.offset(dx, dy, dz);
          if (mutable.intersects(position)) {
            colliding.add(mutable.clone());
          }
        }
      }
    }

    // TODO: colliding entities
    return colliding;
  }
Example #2
0
 // TODO - needs to be made thread safe
 @Override
 public void setCollision(CollisionModel model) {
   collision = model;
   if (collision != null) {
     collision.setPosition(this.transform.getPosition());
   }
 }