Пример #1
0
  /**
   * Gets the collision point between a BoundingSphere and a Segment.
   *
   * <p>Taken from Real-Time Collision Detection.
   *
   * @param a
   * @param b
   * @return
   */
  public static Vector3 getCollision(BoundingSphere a, Segment b) {
    Vector3 m = b.origin.subtract(a.center);
    Vector3 l = b.endpoint.subtract(b.origin);
    Vector3 d = l.multiply(1f / l.fastLength());

    float e = m.dot(d);
    float f = (float) (m.dot(m) - a.radius * a.radius);

    // Exit if r’s origin outside s (c > 0) and r pointing away from s (b > 0)
    if (f > 0.0f && e > 0.0f) {
      return null;
    }
    float discr = e * e - f;

    // A negative discriminant corresponds to ray missing sphere
    if (discr < 0.0f) {
      return null;
    }

    // Ray now found to intersect sphere, compute smallest t value of intersection
    float t = (float) (-e - MathHelper.sqrt(discr));

    // If t is negative, ray started inside sphere so clamp t to zero
    if (t < 0.0f) {
      t = 0.0f;
    }
    return b.origin.add(d.multiply(t));
  }
Пример #2
0
 /**
  * Gets the collision point between two BoundingBoxes.
  *
  * @param a
  * @param b
  * @return
  */
 public static Vector3 getCollision(BoundingBox a, BoundingBox b) {
   BoundingBox intersection = getIntersection(a, b);
   if (intersection == null) {
     return null;
   }
   Vector3 ret = new Vector3(intersection.min);
   ret.add(intersection.max);
   ret.multiply(0.5f);
   return ret;
 }
Пример #3
0
  /**
   * Checks the collision between a BoundingSphere and a Segment.
   *
   * @param a
   * @param b
   * @return
   */
  public static boolean checkCollision(BoundingSphere a, Segment b) {
    Vector3 m = b.origin.subtract(a.center);
    Vector3 l = b.endpoint.subtract(b.origin);
    float lnorm = l.fastLength();
    Vector3 d = l.multiply(1f / lnorm);

    float e = m.dot(d);
    float f = (float) (m.dot(m) - a.radius * a.radius);

    // Exit if r’s origin outside s (c > 0) and r pointing away from s (b > 0)
    if (f > 0.0f && e > 0.0f) {
      return false;
    }
    float discr = e * e - f;

    // A negative discriminant corresponds to ray missing sphere
    if (discr < 0.0f) {
      return false;
    }

    // Check that the intersection is not past the segment
    return -e - MathHelper.sqrt(discr) <= lnorm;
  }
Пример #4
0
  @Override
  public Point[] generatePoints(Point center, int number) {

    float angle = 0;
    float distance = 1;

    Point[] points = new Point[number];

    points[0] = center;

    for (int i = 1; i < number; i++) {
      distance = (float) Math.sqrt(i);

      Vector3 offset = Point.FORWARD.transform(MathHelper.rotateY(angle));
      offset = offset.multiply(distance).multiply(scaleRadius);

      points[i] = center.add(offset);

      angle += scaleCircumference * 360.0 / (Math.PI * distance);
    }

    return points;
  }