Esempio n. 1
0
 /**
  * Sets the minimum and maximum vector to positive and negative infinity.
  *
  * @return This bounding box for chaining.
  */
 public Bounds inf() {
   min.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
   max.set(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
   cnt.set(0, 0, 0);
   dim.set(0, 0, 0);
   return this;
 }
Esempio n. 2
0
 /**
  * Extends this bounding box by the given sphere.
  *
  * @param center Sphere center
  * @param radius Sphere radius
  * @return This bounding box for chaining.
  */
 public Bounds ext(Vector3 center, double radius) {
   return this.set(
       min.set(
           min(min.x, center.x - radius),
           min(min.y, center.y - radius),
           min(min.z, center.z - radius)),
       max.set(
           max(max.x, center.x + radius),
           max(max.y, center.y + radius),
           max(max.z, center.z + radius)));
 }
Esempio n. 3
0
 /**
  * Sets the given minimum and maximum vector.
  *
  * @param minimum The minimum vector
  * @param maximum The maximum vector
  * @return This bounding box for chaining.
  */
 public Bounds set(Vector3 minimum, Vector3 maximum) {
   min.set(
       minimum.x < maximum.x ? minimum.x : maximum.x,
       minimum.y < maximum.y ? minimum.y : maximum.y,
       minimum.z < maximum.z ? minimum.z : maximum.z);
   max.set(
       minimum.x > maximum.x ? minimum.x : maximum.x,
       minimum.y > maximum.y ? minimum.y : maximum.y,
       minimum.z > maximum.z ? minimum.z : maximum.z);
   cnt.set(min).add(max).scl(0.5f);
   dim.set(max).sub(min);
   return this;
 }
Esempio n. 4
0
 @Override // from IBox
 public Vector3 vertex(int code, Vector3 result) {
   return result.set(
       ((code & (1 << 2)) == 0) ? _minExtent.x : _maxExtent.x,
       ((code & (1 << 1)) == 0) ? _minExtent.y : _maxExtent.y,
       ((code & (1 << 0)) == 0) ? _minExtent.z : _maxExtent.z);
 }
Esempio n. 5
0
 @Override // from IBox
 public boolean intersection(IRay3 ray, Vector3 result) {
   IVector3 origin = ray.origin();
   if (contains(origin)) {
     result.set(origin);
     return true;
   }
   IVector3 dir = ray.direction();
   double t = Float.MAX_VALUE;
   if (Math.abs(dir.x()) > MathUtil.EPSILON) {
     t = Math.min(t, intersectionX(ray, _minExtent.x));
     t = Math.min(t, intersectionX(ray, _maxExtent.x));
   }
   if (Math.abs(dir.y()) > MathUtil.EPSILON) {
     t = Math.min(t, intersectionY(ray, _minExtent.y));
     t = Math.min(t, intersectionY(ray, _maxExtent.y));
   }
   if (Math.abs(dir.z()) > MathUtil.EPSILON) {
     t = Math.min(t, intersectionZ(ray, _minExtent.z));
     t = Math.min(t, intersectionZ(ray, _maxExtent.z));
   }
   if (t == Float.MAX_VALUE) {
     return false;
   }
   origin.addScaled(dir, t, result);
   return true;
 }
 public Vector3 getDirection() {
   Matrix.setIdentityM(matrix, 0);
   Matrix.rotateM(matrix, 0, yaw, 0, 1, 0);
   Matrix.rotateM(matrix, 0, pitch, 1, 0, 0);
   Matrix.multiplyMV(outVex, 0, matrix, 0, inVex, 0);
   direction.set(outVex[0], outVex[1], outVex[2]);
   return direction;
 }
Esempio n. 7
0
  /**
   * Definiert die Plane über einen Punkt und eine Normake
   *
   * @param distance Die Distantz zum Koordinatenursprung
   * @param normal Die Normale
   * @return Diese Instanz für method chaining
   */
  @NotNull
  public Plane3 set(@NotNull final Vector3 normal, final float distance) {
    assert !normal.isEmpty();

    _normal.set(normal.getNormalized());
    _distanceToOrigin = -distance;
    return this;
  }
Esempio n. 8
0
  /**
   * Definiert die Plane über einen Punkt und eine Normake
   *
   * @param center Der Punkt
   * @param normal Die Normale
   * @return Diese Instanz für method chaining
   */
  @NotNull
  public Plane3 set(@NotNull final Vector3 normal, @NotNull final Vector3 center) {
    assert !normal.isEmpty();

    // Normale setzen
    _normal.set(normal.getNormalized());

    // Entfernung berechnen
    _distanceToOrigin = normal.dotWithInversion(center);
    return this;
  }
Esempio n. 9
0
  /**
   * Definiert die Plane über drei Punkte.
   *
   * @param a Erster Punkt
   * @param b Zweiter Punkt
   * @param c Dritter Punkt
   * @return Diese Instanz für method chaining
   */
  @NotNull
  public Plane3 set(@NotNull final Vector3 a, @NotNull final Vector3 b, @NotNull final Vector3 c) {
    assert !a.equals(b) && !b.equals(c); // TODO: Dürfen nicht auf einer Geraden liegen!

    // Normale berechnen: _normal = a.sub(b).cross(a.sub(c));
    final Vector3 aSubB = a.sub(b);
    Vector3 aSubC = a.sub(c);

    _normal.set(aSubB.cross(aSubC));
    _normal.normalize();

    // aSubB freigeben.
    // aSubC wird noch nicht freigegeben, da wir den Wert in Kürze weiterverwenden werden
    aSubB.recycle();

    // Entfernung berechnen
    final Vector3 invNormal = aSubC;
    invNormal.set(_normal).invert();
    _distanceToOrigin = invNormal.dot(a);
    invNormal.recycle();
    return this;
  }
Esempio n. 10
0
 public static Vector3 getScaledVector(Vector3 unitVector, double scale) {
   Vector3 vector = new Vector3();
   vector.set(unitVector);
   vector.scale(scale);
   return vector;
 }
Esempio n. 11
0
 public Vector3 getCorner100(final Vector3 out) {
   return out.set(max.x, min.y, min.z);
 }
Esempio n. 12
0
 /**
  * Extends the bounding box to incorporate the given {@link Vector3}.
  *
  * @param point The vector
  * @return This bounding box for chaining.
  */
 public Bounds ext(Vector3 point) {
   return this.set(
       min.set(min(min.x, point.x), min(min.y, point.y), min(min.z, point.z)),
       max.set(Math.max(max.x, point.x), Math.max(max.y, point.y), Math.max(max.z, point.z)));
 }
Esempio n. 13
0
 /**
  * Dreht den Strahl um, so dass er in die entgegengesetzte Richtung zeigt
  *
  * @return Diese Instanz für method chaining
  */
 @NotNull
 public Ray3 invert() {
   direction.invert();
   invDirection.set(1.0f / direction.x, 1.0f / direction.y, 1.0f / direction.z);
   return this;
 }
Esempio n. 14
0
 /**
  * Extends this bounding box by the given bounding box.
  *
  * @param a_bounds The bounding box
  * @return This bounding box for chaining.
  */
 public Bounds ext(Bounds a_bounds) {
   return this.set(
       min.set(min(min.x, a_bounds.min.x), min(min.y, a_bounds.min.y), min(min.z, a_bounds.min.z)),
       max.set(
           max(max.x, a_bounds.max.x), max(max.y, a_bounds.max.y), max(max.z, a_bounds.max.z)));
 }
Esempio n. 15
0
 /**
  * Sets the minimum and maximum vector to zeros.
  *
  * @return This bounding box for chaining.
  */
 public Bounds clr() {
   return this.set(min.set(0, 0, 0), max.set(0, 0, 0));
 }
Esempio n. 16
0
 public static Vector3 cross(float x1, float y1, float z1, float x2, float y2, float z2) {
   temp3.set(x1, y1, z1);
   return temp3.cross(x2, y2, z2);
 }
Esempio n. 17
0
 public static float dot(float x1, float y1, float z1, float x2, float y2, float z2) {
   temp3.set(x1, y1, z1);
   return temp3.dot(x2, y2, z2);
 }
Esempio n. 18
0
 /**
  * @param out The {@link Vector3} to receive the dimensions of this bounding box on all three
  *     axis.
  * @return The vector specified with the out argument
  */
 public Vector3 getDimensions(final Vector3 out) {
   return out.set(dim);
 }
Esempio n. 19
0
 /**
  * @param out The {@link Vector3} to receive the maximum values.
  * @return The vector specified with the out argument
  */
 public Vector3 getMax(final Vector3 out) {
   return out.set(max);
 }
Esempio n. 20
0
 /**
  * Extends the bounding box by the given vector.
  *
  * @param x The x-coordinate
  * @param y The y-coordinate
  * @param z The z-coordinate
  * @return This bounding box for chaining.
  */
 public Bounds ext(double x, double y, double z) {
   return this.set(
       min.set(min(min.x, x), min(min.y, y), min(min.z, z)),
       max.set(max(max.x, x), max(max.y, y), max(max.z, z)));
 }
Esempio n. 21
0
 public Vector3 getCorner010(final Vector3 out) {
   return out.set(min.x, max.y, min.z);
 }
Esempio n. 22
0
 /**
  * @param out The {@link Vector3} to receive the center of the bounding box.
  * @return The vector specified with the out argument.
  */
 public Vector3 getCenter(Vector3 out) {
   return out.set(cnt);
 }
Esempio n. 23
0
 public Vector3 getCorner111(final Vector3 out) {
   return out.set(max.x, max.y, max.z);
 }
Esempio n. 24
0
 /**
  * @param out The {@link Vector3} to receive the minimum values.
  * @return The vector specified with the out argument
  */
 public Vector3 getMin(final Vector3 out) {
   return out.set(min);
 }