示例#1
1
  /** Query the texture for the colour at the given intersection (in 3D space). */
  private Colour queryTexture(Vector3 intersection) {
    Vector3 Vn = mNorth;
    Vector3 Ve = Vector3.pool.borrow().reset(Vn.y, -Vn.x, 0.0); // (AKA Vn.cross(0, 0, 1))
    Vector3 Vp = Vector3.pool.borrow().reset(intersection);
    Vp.subtract(mPlanetOrigin);

    Ve.normalize();
    Vp.normalize();

    double phi = Math.acos(-1.0 * Vector3.dot(Vn, Vp));
    double v = phi / Math.PI;

    double theta = (Math.acos(Vector3.dot(Vp, Ve) / Math.sin(phi))) / (Math.PI * 2.0);
    double u;

    Vector3 c = Vector3.cross(Vn, Ve);
    if (Vector3.dot(c, Vp) > 0) {
      u = theta;
    } else {
      u = 1.0 - theta;
    }

    Vector3.pool.release(c);
    Vector3.pool.release(Ve);
    Vector3.pool.release(Vp);

    return mTexture.getTexel(u, v);
  }
示例#2
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;
  }
示例#3
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);
 }