/**
   * <code>mergeLocal</code> combines this sphere with a second bounding sphere locally. Altering
   * this sphere to contain both the original and the additional sphere volumes;
   *
   * @param volume the sphere to combine with this sphere.
   * @return this
   */
  public BoundingVolume mergeLocal(BoundingVolume volume) {
    if (volume == null) {
      return this;
    }

    switch (volume.getType()) {
      case Sphere:
        {
          BoundingSphere sphere = (BoundingSphere) volume;
          float temp_radius = sphere.getRadius();
          Vector3f temp_center = sphere.center;
          return merge(temp_radius, temp_center, this);
        }

      case AABB:
        {
          BoundingBox box = (BoundingBox) volume;
          Vector3f radVect = Vector3f.newInstance();
          radVect.set(box.xExtent, box.yExtent, box.zExtent);
          Vector3f temp_center = box.center;
          float len = radVect.length();
          Vector3f.recycle(radVect);
          return merge(len, temp_center, this);
        }

        // case OBB: {
        // return mergeOBB((OrientedBoundingBox) volume);
        // }
      default:
        return null;
    }
  }
  /**
   * <code>merge</code> combines this sphere with a second bounding sphere. This new sphere contains
   * both bounding spheres and is returned.
   *
   * @param volume the sphere to combine with this sphere.
   * @return a new sphere
   */
  public BoundingVolume merge(BoundingVolume volume) {
    if (volume == null) {
      return this;
    }

    switch (volume.getType()) {
      case Sphere:
        {
          BoundingSphere sphere = (BoundingSphere) volume;
          float temp_radius = sphere.getRadius();
          Vector3f temp_center = sphere.center;
          BoundingSphere rVal = new BoundingSphere();
          return merge(temp_radius, temp_center, rVal);
        }

      case AABB:
        {
          BoundingBox box = (BoundingBox) volume;
          Vector3f radVect = new Vector3f(box.xExtent, box.yExtent, box.zExtent);
          Vector3f temp_center = box.center;
          BoundingSphere rVal = new BoundingSphere();
          return merge(radVect.length(), temp_center, rVal);
        }

        // case OBB: {
        // OrientedBoundingBox box = (OrientedBoundingBox) volume;
        // BoundingSphere rVal = (BoundingSphere) this.clone(null);
        // return rVal.mergeOBB(box);
        // }
      default:
        return null;
    }
  }
  /**
   * <code>clone</code> creates a new BoundingSphere object containing the same data as this one.
   *
   * @param store where to store the cloned information. if null or wrong class, a new store is
   *     created.
   * @return the new BoundingSphere
   */
  public BoundingVolume clone(BoundingVolume store) {
    if (store != null && store.getType() == Type.Sphere) {
      BoundingSphere rVal = (BoundingSphere) store;
      if (null == rVal.center) {
        rVal.center = new Vector3f();
      }
      rVal.center.set(center);
      rVal.radius = radius;
      rVal.checkPlane = checkPlane;
      return rVal;
    }

    return new BoundingSphere(radius, (center != null ? (Vector3f) center.clone() : null));
  }
  public BoundingVolume transform(Matrix4f trans, BoundingVolume store) {
    BoundingSphere sphere;
    if (store == null || store.getType() != BoundingVolume.Type.Sphere) {
      sphere = new BoundingSphere(1, new Vector3f(0, 0, 0));
    } else {
      sphere = (BoundingSphere) store;
    }

    trans.mult(center, sphere.center);
    Vector3f axes = new Vector3f(1, 1, 1);
    trans.mult(axes, axes);
    float ax = getMaxAxis(axes);
    sphere.radius = FastMath.abs(ax * radius) + RADIUS_EPSILON - 1f;
    return sphere;
  }
Exemple #5
0
 public final boolean fullContains(BoundingVolume that) {
   return that.fullContainedInBox(this);
 }
Exemple #6
0
 public final BoundingVolume mergedWith(BoundingVolume that) {
   if (that == null) {
     return null;
   }
   return that.mergedWithBox(this);
 }
Exemple #7
0
 public final boolean touches(BoundingVolume that) {
   if (that == null) {
     return false;
   }
   return that.touchesBox(this);
 }
 /*
  * (non-Javadoc)
  * @see com.jme.bounding.BoundingVolume#intersects(com.jme.bounding.BoundingVolume)
  */
 public boolean intersects(BoundingVolume bv) {
   return bv.intersectsSphere(this);
 }