Ejemplo n.º 1
0
 public boolean intersects(BoundingBox box) {
   final Vector3 rMax = box.getMax();
   if (rMax.getX() < min.getX() || rMax.getY() < min.getY() || rMax.getZ() < min.getZ()) {
     return false;
   }
   final Vector3 rMin = box.getMin();
   return !(rMin.getX() > max.getX() || rMin.getY() > max.getY() || rMin.getZ() > max.getZ());
 }
Ejemplo n.º 2
0
 /**
  * Returns true if the BoundingBox contains the BoundingSphere.
  *
  * @param a
  * @param b
  * @return
  */
 public static boolean contains(BoundingBox a, BoundingSphere b) {
   Vector3 zeroed = a.max.subtract(a.min);
   Vector3 newCenter = b.center.subtract(a.min);
   return newCenter.getX() - b.radius <= 0
       && zeroed.getX() <= newCenter.getX() + b.radius
       && newCenter.getY() - b.radius <= 0
       && zeroed.getY() <= newCenter.getY() + b.radius
       && newCenter.getZ() - b.radius <= 0
       && zeroed.getZ() <= newCenter.getZ() + b.radius;
 }
Ejemplo n.º 3
0
  /** Called when the tick is finished and collisions need to be resolved and move events fired */
  public void resolve() {
    if (Spout.debugMode()) {
      //	System.out.println("COLLISION DEBUGGING");
      //	System.out.println("Current Collision: " + this.collision.toString());
    }

    List<CollisionVolume> colliding =
        ((SpoutWorld) collisionPoint.getWorld()).getCollidingObject(this.collision);

    Vector3 offset = this.lastTransform.getPosition().subtract(collisionPoint);
    for (CollisionVolume box : colliding) {
      if (Spout.debugMode()) {
        //	System.out.println("Colliding box: " + box.toString());
      }
      Vector3 collision = this.collision.resolve(box);
      if (Spout.debugMode()) {
        //	System.out.println("Collision vector: " + collision.toString());
      }
      if (collision != null) {
        collision = collision.subtract(collisionPoint);
        if (Spout.debugMode()) {
          //	System.out.println("Collision point: " + collision.toString() + " Collision vector: " +
          // collision);
        }

        if (collision.getX() != 0F) {
          offset = new Vector3(collision.getX(), offset.getY(), offset.getZ());
        }
        if (collision.getY() != 0F) {
          offset = new Vector3(offset.getX(), collision.getY(), offset.getZ());
        }
        if (collision.getZ() != 0F) {
          offset = new Vector3(offset.getX(), offset.getY(), collision.getZ());
        }

        if (Spout.debugMode()) {
          //	System.out.println("Collision offset: " + offset.toString());
        }
        if (this.getCollision().getStrategy() == CollisionStrategy.SOLID
            && box.getStrategy() == CollisionStrategy.SOLID) {
          this.setPosition(collisionPoint.add(offset));
          if (Spout.debugMode()) {
            //	System.out.println("New Position: " + this.getPosition());
          }
        }

        controllerLive.get().onCollide(getWorld().getBlock(box.getPosition()));
      }
    }

    // Check to see if we should fire off a Move event
  }
Ejemplo n.º 4
0
 /**
  * Checks if 3 points are counterclockwise. (A helper for a helper method)
  *
  * @param a
  * @param b
  * @param c
  * @return
  */
 private static boolean ccw(Vector3 a, Vector3 b, Vector3 c) {
   // This is Java lisp
   return (c.getY() - a.getY()) * (b.getX() - a.getX())
           < (b.getY() - a.getY()) * (c.getX() - a.getX())
       || (c.getY() - a.getY()) * (b.getZ() - a.getZ())
           < (b.getY() - a.getY()) * (c.getZ() - a.getZ());
 }
Ejemplo n.º 5
0
  /**
   * Checks if a bounding box and a line segment collide. Based off of
   * people.csail.mit.edu/amy/papers/box-jgt.ps
   *
   * <p>There must be a better way to do this.
   *
   * @param a
   * @param b
   * @return
   */
  public static boolean checkCollision(BoundingBox a, Segment b) {
    Vector3 box = a.max.subtract(a.min);
    Vector3 seg = b.endpoint.subtract(b.origin);
    Vector3 m = b.origin.add(b.endpoint).subtract(a.max).subtract(a.min);

    // Try world coordinate axes as separating axes
    float adx = Math.abs(seg.getX());
    if (Math.abs(m.getX()) > box.getX() + adx) {
      return false;
    }
    float ady = Math.abs(seg.getY());
    if (Math.abs(m.getY()) > box.getY() + ady) {
      return false;
    }
    float adz = Math.abs(seg.getZ());
    if (Math.abs(m.getZ()) > box.getZ() + adz) {
      return false;
    }

    // Add in an epsilon term to counteract arithmetic errors when segment is
    // (near) parallel to a coordinate axis (see text for detail)
    adx += MathHelper.FLT_EPSILON;
    ady += MathHelper.FLT_EPSILON;
    adz += MathHelper.FLT_EPSILON;

    // Try cross products of segment direction vector with coordinate axes
    if (Math.abs(m.getY() * seg.getZ() - m.getZ() * seg.getY())
        > box.getY() * adz + box.getZ() * ady) {
      return false;
    }
    if (Math.abs(m.getZ() * seg.getX() - m.getX() * seg.getZ())
        > box.getX() * adz + box.getZ() * adx) {
      return false;
    }

    if (Math.abs(m.getX() * seg.getY() - m.getY() * seg.getX())
        > box.getX() * ady + box.getY() * adx) {
      return false;
    }

    // No separating axis found; segment must be overlapping AABB
    return true;
  }
Ejemplo n.º 6
0
 public static Vector3 getProtocolVelocity(Vector3 velocity) {
   final float x = velocity.getX() * 32000;
   final float y = velocity.getY() * 32000;
   final float z = velocity.getZ() * 32000;
   return new Vector3(x, y, z);
 }
Ejemplo n.º 7
0
 public ExplosionMessage(Vector3 position, float radius, byte[] coordinates) {
   this(position.getX(), position.getY(), position.getZ(), radius, coordinates);
 }
Ejemplo n.º 8
0
 @Override
 public SpoutBlock getBlock(Vector3 position) {
   return this.getBlock(position.getX(), position.getY(), position.getZ());
 }
Ejemplo n.º 9
0
 @Override
 public Block translate(Vector3 offset) {
   return this.translate((int) offset.getX(), (int) offset.getY(), (int) offset.getZ());
 }
Ejemplo n.º 10
0
 public EntityVelocityMessage(int id, Vector3 velocity) {
   this(id, (int) velocity.getX(), (int) velocity.getY(), (int) velocity.getZ());
 }
Ejemplo n.º 11
0
 public static Vector toVector(org.spout.api.math.Vector3 vector) {
   return new Vector(vector.getX(), vector.getY(), vector.getZ());
 }
Ejemplo n.º 12
0
 public static BlockVector toBlockVector(Vector3 vector) {
   return new BlockVector(vector.getX(), vector.getY(), vector.getZ());
 }
Ejemplo n.º 13
0
 public float getYSize() {
   return max.getY() - min.getY();
 }
Ejemplo n.º 14
0
 /**
  * Constructs a new Quaternion that represents a given rotation around an arbatrary axis
  *
  * @param angle Angle, in Degrees, to rotate the axis about by
  * @param axis
  */
 public Quaternion(float angle, Vector3 axis) {
   this(angle, axis.getX(), axis.getY(), axis.getZ());
 }