Skip to content

Commit

Permalink
Expose generic Matrix4.mul() as mul0()
Browse files Browse the repository at this point in the history
  • Loading branch information
httpdigest committed May 22, 2020
1 parent be76b05 commit 279d153
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 4 deletions.
25 changes: 23 additions & 2 deletions src/org/joml/Matrix4d.java
Original file line number Diff line number Diff line change
Expand Up @@ -1207,9 +1207,30 @@ else if ((properties & PROPERTY_PERSPECTIVE) != 0 && (right.properties() & PROPE
return mulPerspectiveAffine(right, dest);
else if ((right.properties() & PROPERTY_AFFINE) != 0)
return mulAffineR(right, dest);
return mulGeneric(right, dest);
return mul0(right, dest);
}
private Matrix4d mulGeneric(Matrix4dc right, Matrix4d dest) {

/**
* Multiply this matrix by the supplied <code>right</code> matrix.
* <p>
* If <code>M</code> is <code>this</code> matrix and <code>R</code> the <code>right</code> matrix,
* then the new matrix will be <code>M * R</code>. So when transforming a
* vector <code>v</code> with the new matrix by using <code>M * R * v</code>, the
* transformation of the right matrix will be applied first!
* <p>
* This method neither assumes nor checks for any matrix properties of <code>this</code> or <code>right</code>
* and will always perform a complete 4x4 matrix multiplication. This method should only be used whenever the
* multiplied matrices do not have any properties for which there are optimized multiplication methods available.
*
* @param right
* the right operand of the matrix multiplication
* @return this
*/
public Matrix4d mul0(Matrix4dc right) {
return mul0(right, this);
}

public Matrix4d mul0(Matrix4dc right, Matrix4d dest) {
double nm00 = Math.fma(m00, right.m00(), Math.fma(m10, right.m01(), Math.fma(m20, right.m02(), m30 * right.m03())));
double nm01 = Math.fma(m01, right.m00(), Math.fma(m11, right.m01(), Math.fma(m21, right.m02(), m31 * right.m03())));
double nm02 = Math.fma(m02, right.m00(), Math.fma(m12, right.m01(), Math.fma(m22, right.m02(), m32 * right.m03())));
Expand Down
20 changes: 20 additions & 0 deletions src/org/joml/Matrix4dc.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,26 @@ public interface Matrix4dc {
*/
Matrix4d mul(Matrix4dc right, Matrix4d dest);

/**
* Multiply this matrix by the supplied <code>right</code> matrix and store the result in <code>dest</code>.
* <p>
* If <code>M</code> is <code>this</code> matrix and <code>R</code> the <code>right</code> matrix,
* then the new matrix will be <code>M * R</code>. So when transforming a
* vector <code>v</code> with the new matrix by using <code>M * R * v</code>, the
* transformation of the right matrix will be applied first!
* <p>
* This method neither assumes nor checks for any matrix properties of <code>this</code> or <code>right</code>
* and will always perform a complete 4x4 matrix multiplication. This method should only be used whenever the
* multiplied matrices do not have any properties for which there are optimized multiplication methods available.
*
* @param right
* the right operand of the matrix multiplication
* @param dest
* the destination matrix, which will hold the result
* @return dest
*/
Matrix4d mul0(Matrix4dc right, Matrix4d dest);

/**
* Multiply this matrix by the matrix with the supplied elements and store the result in <code>dest</code>.
* <p>
Expand Down
25 changes: 23 additions & 2 deletions src/org/joml/Matrix4f.java
Original file line number Diff line number Diff line change
Expand Up @@ -1150,9 +1150,30 @@ else if ((properties & PROPERTY_PERSPECTIVE) != 0 && (right.properties() & PROPE
return mulPerspectiveAffine(right, dest);
else if ((right.properties() & PROPERTY_AFFINE) != 0)
return mulAffineR(right, dest);
return mulGeneric(right, dest);
return mul0(right, dest);
}

/**
* Multiply this matrix by the supplied <code>right</code> matrix.
* <p>
* If <code>M</code> is <code>this</code> matrix and <code>R</code> the <code>right</code> matrix,
* then the new matrix will be <code>M * R</code>. So when transforming a
* vector <code>v</code> with the new matrix by using <code>M * R * v</code>, the
* transformation of the right matrix will be applied first!
* <p>
* This method neither assumes nor checks for any matrix properties of <code>this</code> or <code>right</code>
* and will always perform a complete 4x4 matrix multiplication. This method should only be used whenever the
* multiplied matrices do not have any properties for which there are optimized multiplication methods available.
*
* @param right
* the right operand of the matrix multiplication
* @return this
*/
public Matrix4f mul0(Matrix4fc right) {
return mul0(right, this);
}
private Matrix4f mulGeneric(Matrix4fc right, Matrix4f dest) {

public Matrix4f mul0(Matrix4fc right, Matrix4f dest) {
float nm00 = Math.fma(m00, right.m00(), Math.fma(m10, right.m01(), Math.fma(m20, right.m02(), m30 * right.m03())));
float nm01 = Math.fma(m01, right.m00(), Math.fma(m11, right.m01(), Math.fma(m21, right.m02(), m31 * right.m03())));
float nm02 = Math.fma(m02, right.m00(), Math.fma(m12, right.m01(), Math.fma(m22, right.m02(), m32 * right.m03())));
Expand Down
20 changes: 20 additions & 0 deletions src/org/joml/Matrix4fc.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,26 @@ public interface Matrix4fc {
*/
Matrix4f mul(Matrix4fc right, Matrix4f dest);

/**
* Multiply this matrix by the supplied <code>right</code> matrix and store the result in <code>dest</code>.
* <p>
* If <code>M</code> is <code>this</code> matrix and <code>R</code> the <code>right</code> matrix,
* then the new matrix will be <code>M * R</code>. So when transforming a
* vector <code>v</code> with the new matrix by using <code>M * R * v</code>, the
* transformation of the right matrix will be applied first!
* <p>
* This method neither assumes nor checks for any matrix properties of <code>this</code> or <code>right</code>
* and will always perform a complete 4x4 matrix multiplication. This method should only be used whenever the
* multiplied matrices do not have any properties for which there are optimized multiplication methods available.
*
* @param right
* the right operand of the matrix multiplication
* @param dest
* the destination matrix, which will hold the result
* @return dest
*/
Matrix4f mul0(Matrix4fc right, Matrix4f dest);

/**
* Multiply this matrix by the matrix with the supplied elements and store the result in <code>dest</code>.
* <p>
Expand Down

0 comments on commit 279d153

Please sign in to comment.