示例#1
0
  /**
   * Multiply the vertex v for this Matrix and override v with the result. Return the omogeneus
   * component of the transformation
   */
  public float mult(Vertex3f v) {
    float x = v.getX();
    float y = v.getY();
    float z = v.getZ();

    v.setX(mM.A * x + mM.B * y + mM.C * z + mM.D);
    v.setY(mM.E * x + mM.F * y + mM.G * z + mM.H);
    v.setZ(mM.I * x + mM.L * y + mM.M * z + mM.N);

    return (mM.O * x + mM.P * y + mM.Q * z + mM.R);
  }
示例#2
0
  public static Transform3f GenerateProjectionToPlaneMatrix(
      Vertex3f f, Vertex3f pPos, Vertex3f pN) {

    Transform3f t = new Transform3f();

    /**
     * Proiezione sul piano...
     *
     * <p>P' e` l'intersezione del piano (P'-Q)N=0 con la retta P'=(F+t(P-F))
     *
     * <p>( F +t(P-F) -Q )N=0
     *
     * <p>-> t=(Q-F)N/(P-F)N
     *
     * <p>P'=F+(P-F)*t
     *
     * <p>Allora...
     *
     * <p>k=(Q-F)N
     *
     * <p>X'=(xf*W'+(x-xf)*k)/W' Y'=(yf*W'+(y-yf)*k)/W' Z'=(zf*W'+(z-zf)*k)/W' W'=P*N-F*N;
     *
     * <p>X'=(xf*(x+*xN+y*Yn+z*ZN-F*N)+(x-xf)*k)/W' Y'=(yf*(x+*xN+y*Yn+z*ZN-F*N)+(y-yf)*k)/W'
     * Z'=(zf*(x+*xN+y*Yn+z*ZN-F*N)+(z-zf)*k)/W'
     */
    float k =
        (pN.getX() * (pPos.getX() - f.getX())
            + pN.getY() * (pPos.getY() - f.getY())
            + pN.getZ() * (pPos.getZ() - f.getZ()));

    t.mM.O = pN.getX();
    t.mM.P = pN.getY();
    t.mM.Q = pN.getZ();
    t.mM.R = -(pN.getX() * f.getX() + pN.getY() * f.getY() + pN.getZ() * f.getZ());
    float fn = t.mM.R;

    // X'=(xf*(x+*xN+y*Yn+z*ZN-F*N)+(x-xf)*k)
    t.mM.A = f.getX() * (pN.getX()) + k;
    t.mM.B = f.getX() * (pN.getY());
    t.mM.C = f.getX() * (pN.getZ());
    t.mM.D = f.getX() * (fn - k);

    t.mM.E = f.getY() * (pN.getX());
    t.mM.F = f.getY() * (pN.getY()) + k;
    t.mM.G = f.getY() * (pN.getZ());
    t.mM.H = f.getY() * (fn - k);

    t.mM.I = f.getZ() * (pN.getX());
    t.mM.L = f.getZ() * (pN.getY());
    t.mM.M = f.getZ() * (pN.getZ()) + k;
    t.mM.N = f.getZ() * (fn - k);

    return (t);
  }
示例#3
0
  /**
   * Multiply this Matrix for a General Rotation: alpha is the rotation angle in radians and (x,y,z)
   * is the direction of the rotation ax
   */
  public void rotateGeneral(float alpha, float x, float y, float z) {
    // Direction3f dir=new Direction3f(x,y,z);
    Vertex3f dir = new Vertex3f(x, y, z);

    dir.normalize();
    // Direction3f A=dir.getNormalCandidate();
    Vertex3f A = dir.getNormalCandidate();

    A.normalize();
    Vertex3f B = dir.getVectorProduct(A);
    // Direction3f B=dir.getVectorProduct(A);

    // Construct a Third Vector B normal to Both V and A
    Transform3f t = new Transform3f();

    float cos = (float) (Math.cos(alpha));
    float sin = (float) (Math.sin(alpha));

    t.mM.A = dir.getX();
    t.mM.B = A.getX();
    t.mM.C = B.getX();
    t.mM.E = dir.getY();
    t.mM.F = A.getY();
    t.mM.G = B.getY();
    t.mM.I = dir.getZ();
    t.mM.L = A.getZ();
    t.mM.M = B.getZ();

    mult(t);

    t.mM.A = dir.getX();
    t.mM.B = dir.getY();
    t.mM.C = dir.getZ();
    t.mM.E = A.getX() * cos - B.getX() * sin;
    t.mM.F = A.getY() * cos - B.getY() * sin;
    t.mM.G = A.getZ() * cos - B.getZ() * sin;
    t.mM.I = A.getX() * sin + B.getX() * cos;
    t.mM.L = A.getY() * sin + B.getY() * cos;
    t.mM.M = A.getZ() * sin + B.getZ() * cos;

    mult(t);
  }