示例#1
0
 /**
  * Set the source matrix to be the identity matrix.
  *
  * @param src The matrix to set to the identity.
  * @return The source matrix
  */
 public static Matrix2f setIdentity(Matrix2f src) {
   src.m00 = 1.0f;
   src.m01 = 0.0f;
   src.m10 = 0.0f;
   src.m11 = 1.0f;
   return src;
 }
示例#2
0
 public static Matrix2f setZero(Matrix2f src) {
   src.m00 = 0.0f;
   src.m01 = 0.0f;
   src.m10 = 0.0f;
   src.m11 = 0.0f;
   return src;
 }
示例#3
0
  /**
   * Copy the source matrix to the destination matrix.
   *
   * @param src The source matrix
   * @param dest The destination matrix, or null if a new one should be created.
   * @return The copied matrix
   */
  public static Matrix2f load(Matrix2f src, Matrix2f dest) {
    if (dest == null) dest = new Matrix2f();

    dest.m00 = src.m00;
    dest.m01 = src.m01;
    dest.m10 = src.m10;
    dest.m11 = src.m11;

    return dest;
  }
示例#4
0
  /**
   * Subtract the right matrix from the left and place the result in a third matrix.
   *
   * @param left The left source matrix
   * @param right The right source matrix
   * @param dest The destination matrix, or null if a new one is to be created
   * @return the destination matrix
   */
  public static Matrix2f sub(Matrix2f left, Matrix2f right, Matrix2f dest) {
    if (dest == null) dest = new Matrix2f();

    dest.m00 = left.m00 - right.m00;
    dest.m01 = left.m01 - right.m01;
    dest.m10 = left.m10 - right.m10;
    dest.m11 = left.m11 - right.m11;

    return dest;
  }
示例#5
0
  /**
   * Add two matrices together and place the result in a third matrix.
   *
   * @param left The left source matrix
   * @param right The right source matrix
   * @param dest The destination matrix, or null if a new one is to be created
   * @return the destination matrix
   */
  public static Matrix2f add(Matrix2f left, Matrix2f right, Matrix2f dest) {
    if (dest == null) dest = new Matrix2f();

    dest.m00 = left.m00 + right.m00;
    dest.m01 = left.m01 + right.m01;
    dest.m10 = left.m10 + right.m10;
    dest.m11 = left.m11 + right.m11;

    return dest;
  }
示例#6
0
  /**
   * Transpose the source matrix and place the result in the destination matrix.
   *
   * @param src The source matrix or null if a new matrix is to be created
   * @param dest The destination matrix or null if a new matrix is to be created
   * @return the transposed matrix
   */
  public static Matrix2f transpose(Matrix2f src, Matrix2f dest) {
    if (dest == null) dest = new Matrix2f();

    float m01 = src.m10;
    float m10 = src.m01;

    dest.m01 = m01;
    dest.m10 = m10;

    return dest;
  }
示例#7
0
  /**
   * Multiply the right matrix by the left and place the result in a third matrix.
   *
   * @param left The left source matrix
   * @param right The right source matrix
   * @param dest The destination matrix, or null if a new one is to be created
   * @return the destination matrix
   */
  public static Matrix2f mul(Matrix2f left, Matrix2f right, Matrix2f dest) {
    if (dest == null) dest = new Matrix2f();

    float m00 = left.m00 * right.m00 + left.m10 * right.m01;
    float m01 = left.m01 * right.m00 + left.m11 * right.m01;
    float m10 = left.m00 * right.m10 + left.m10 * right.m11;
    float m11 = left.m01 * right.m10 + left.m11 * right.m11;

    dest.m00 = m00;
    dest.m01 = m01;
    dest.m10 = m10;
    dest.m11 = m11;

    return dest;
  }
示例#8
0
  /**
   * Invert the source matrix and place the result in the destination matrix.
   *
   * @param src The source matrix to be inverted
   * @param dest The destination matrix or null if a new matrix is to be created
   * @return The inverted matrix, or null if source can't be reverted.
   */
  public static Matrix2f invert(Matrix2f src, Matrix2f dest) {
    /*
     *inv(A) = 1/det(A) * adj(A);
     */

    float determinant = src.determinant();
    if (determinant != 0) {
      if (dest == null) dest = new Matrix2f();
      float determinant_inv = 1f / determinant;
      float t00 = src.m11 * determinant_inv;
      float t01 = -src.m01 * determinant_inv;
      float t11 = src.m00 * determinant_inv;
      float t10 = -src.m10 * determinant_inv;

      dest.m00 = t00;
      dest.m01 = t01;
      dest.m10 = t10;
      dest.m11 = t11;
      return dest;
    } else return null;
  }