예제 #1
0
  /**
   * <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
   */
  @Override
  public BoundingVolume mergeLocal(final BoundingVolume volume) {
    if (volume == null) {
      return this;
    }

    switch (volume.getType()) {
      case Sphere:
        {
          final BoundingSphere sphere = (BoundingSphere) volume;
          final double temp_radius = sphere.getRadius();
          final ReadOnlyVector3 temp_center = sphere.getCenter();
          return merge(temp_radius, temp_center, this);
        }

      case AABB:
        {
          final BoundingBox box = (BoundingBox) volume;
          final Vector3 temp_center = box._center;
          _compVect1.set(box.getXExtent(), box.getYExtent(), box.getZExtent());
          final double radius = _compVect1.length();
          return merge(radius, temp_center, this);
        }

      case OBB:
        {
          return mergeLocalOBB((OrientedBoundingBox) volume);
        }

      default:
        return null;
    }
  }
예제 #2
0
  @Override
  public boolean intersectsBoundingBox(final BoundingBox bb) {
    if (!Vector3.isValid(_center) || !Vector3.isValid(bb._center)) {
      return false;
    }

    if (Math.abs(bb._center.getX() - getCenter().getX()) < getRadius() + bb.getXExtent()
        && Math.abs(bb._center.getY() - getCenter().getY()) < getRadius() + bb.getYExtent()
        && Math.abs(bb._center.getZ() - getCenter().getZ()) < getRadius() + bb.getZExtent()) {
      return true;
    }

    return false;
  }
예제 #3
0
  /**
   * <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
   */
  @Override
  public BoundingVolume merge(final BoundingVolume volume) {
    if (volume == null) {
      return this;
    }

    switch (volume.getType()) {
      case Sphere:
        {
          final BoundingSphere sphere = (BoundingSphere) volume;
          final double temp_radius = sphere.getRadius();
          final ReadOnlyVector3 tempCenter = sphere.getCenter();
          final BoundingSphere rVal = new BoundingSphere();
          return merge(temp_radius, tempCenter, rVal);
        }

      case AABB:
        {
          final BoundingBox box = (BoundingBox) volume;
          final Vector3 radVect = new Vector3(box.getXExtent(), box.getYExtent(), box.getZExtent());
          final Vector3 tempCenter = box._center;
          final BoundingSphere rVal = new BoundingSphere();
          return merge(radVect.length(), tempCenter, rVal);
        }

      case OBB:
        {
          final OrientedBoundingBox box = (OrientedBoundingBox) volume;
          final BoundingSphere rVal = (BoundingSphere) this.clone(null);
          return rVal.mergeLocalOBB(box);
        }

      default:
        return null;
    }
  }