Example #1
0
  @Override
  public boolean intersectsSphere(final BoundingSphere bs) {
    if (!Vector3.isValid(_center) || !Vector3.isValid(bs._center)) {
      return false;
    }

    final Vector3 diff = _compVect1.set(getCenter()).subtractLocal(bs.getCenter());
    final double rsum = getRadius() + bs.getRadius();
    return (diff.dot(diff) <= rsum * rsum);
  }
Example #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;
  }
Example #3
0
  /**
   * Calculates the distance from a spatial to the camera. Distance is a squared distance.
   *
   * @param spat Spatial to check distance.
   * @return Distance from Spatial to current context's camera.
   */
  protected double distanceToCam(final Spatial spat) {
    if (spat._queueDistance != Double.NEGATIVE_INFINITY) {
      return spat._queueDistance;
    }

    final Camera cam = Camera.getCurrentCamera();

    if (spat.getWorldBound() != null && Vector3.isValid(spat.getWorldBound().getCenter())) {
      spat._queueDistance = spat.getWorldBound().distanceToEdge(cam.getLocation());
    } else {
      final ReadOnlyVector3 spatPosition = spat.getWorldTranslation();
      if (!Vector3.isValid(spatPosition)) {
        spat._queueDistance = Double.POSITIVE_INFINITY;
      } else {
        spat._queueDistance = cam.getLocation().distance(spatPosition);
      }
    }

    return spat._queueDistance;
  }
Example #4
0
  @Override
  public boolean intersects(final ReadOnlyRay3 ray) {
    if (!Vector3.isValid(_center)) {
      return false;
    }

    final Vector3 diff = ray.getOrigin().subtract(getCenter(), _compVect1);
    final double radiusSquared = getRadius() * getRadius();
    final double a = diff.dot(diff) - radiusSquared;
    if (a <= 0.0) {
      // in sphere
      return true;
    }

    // outside sphere
    final Vector3 dir = _compVect2.set(ray.getDirection());
    final double b = dir.dot(diff);
    if (b >= 0.0) {
      return false;
    }
    return b * b >= a;
  }