Skip to content

Commit

Permalink
Add Matrix4/4x3.translationRotateInvert()
Browse files Browse the repository at this point in the history
same as translationRotateScaleInvert() with
a scale factor of 1.
  • Loading branch information
httpdigest committed Jan 12, 2022
1 parent 4d3a4f3 commit aad9dfc
Show file tree
Hide file tree
Showing 4 changed files with 534 additions and 2 deletions.
108 changes: 107 additions & 1 deletion src/org/joml/Matrix4d.java
Original file line number Diff line number Diff line change
Expand Up @@ -7214,7 +7214,7 @@ public Matrix4d translationRotateScaleInvert(double tx, double ty, double tz,
double sx, double sy, double sz) {
boolean one = Math.absEqualsOne(sx) && Math.absEqualsOne(sy) && Math.absEqualsOne(sz);
if (one)
return translationRotateScale(tx, ty, tz, qx, qy, qz, qw, sx, sy, sz).invertOrthonormal(this);
return translationRotateInvert(tx, ty, tz, qx, qy, qz, qw);
double nqx = -qx, nqy = -qy, nqz = -qz;
double dqx = nqx + nqx;
double dqy = nqy + nqy;
Expand Down Expand Up @@ -7563,6 +7563,112 @@ public Matrix4d translationRotate(double tx, double ty, double tz, Quaterniondc
return translationRotate(tx, ty, tz, quat.x(), quat.y(), quat.z(), quat.w());
}

/**
* Set <code>this</code> matrix to <code>T * R</code>, where <code>T</code> is the given <code>translation</code> and
* <code>R</code> is a rotation transformation specified by the given quaternion.
* <p>
* When transforming a vector by the resulting matrix the scaling transformation will be applied first, then the rotation and
* at last the translation.
* <p>
* When used with a right-handed coordinate system, the produced rotation will rotate a vector
* counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.
* When used with a left-handed coordinate system, the rotation is clockwise.
* <p>
* This method is equivalent to calling: <code>translation(translation).rotate(quat)</code>
*
* @see #translation(Vector3dc)
* @see #rotate(Quaterniondc)
*
* @param translation
* the translation
* @param quat
* the quaternion representing a rotation
* @return this
*/
public Matrix4d translationRotate(Vector3dc translation,
Quaterniondc quat) {
return translationRotate(translation.x(), translation.y(), translation.z(), quat.x(), quat.y(), quat.z(), quat.w());
}

/**
* Set <code>this</code> matrix to <code>(T * R)<sup>-1</sup></code>, where <code>T</code> is a translation by the given <code>(tx, ty, tz)</code> and
* <code>R</code> is a rotation transformation specified by the quaternion <code>(qx, qy, qz, qw)</code>.
* <p>
* This method is equivalent to calling: <code>translationRotate(...).invert()</code>
*
* @see #translationRotate(double, double, double, double, double, double, double)
* @see #invert()
*
* @param tx
* the number of units by which to translate the x-component
* @param ty
* the number of units by which to translate the y-component
* @param tz
* the number of units by which to translate the z-component
* @param qx
* the x-coordinate of the vector part of the quaternion
* @param qy
* the y-coordinate of the vector part of the quaternion
* @param qz
* the z-coordinate of the vector part of the quaternion
* @param qw
* the scalar part of the quaternion
* @return this
*/
public Matrix4d translationRotateInvert(double tx, double ty, double tz, double qx, double qy, double qz, double qw) {
double nqx = -qx, nqy = -qy, nqz = -qz;
double dqx = nqx + nqx;
double dqy = nqy + nqy;
double dqz = nqz + nqz;
double q00 = dqx * nqx;
double q11 = dqy * nqy;
double q22 = dqz * nqz;
double q01 = dqx * nqy;
double q02 = dqx * nqz;
double q03 = dqx * qw;
double q12 = dqy * nqz;
double q13 = dqy * qw;
double q23 = dqz * qw;
return this
._m00(1.0 - q11 - q22)
._m01(q01 + q23)
._m02(q02 - q13)
._m03(0.0)
._m10(q01 - q23)
._m11(1.0 - q22 - q00)
._m12(q12 + q03)
._m13(0.0)
._m20(q02 + q13)
._m21(q12 - q03)
._m22(1.0 - q11 - q00)
._m23(0.0)
._m30(-m00 * tx - m10 * ty - m20 * tz)
._m31(-m01 * tx - m11 * ty - m21 * tz)
._m32(-m02 * tx - m12 * ty - m22 * tz)
._m33(1.0)
._properties(PROPERTY_AFFINE | PROPERTY_ORTHONORMAL);
}

/**
* Set <code>this</code> matrix to <code>(T * R)<sup>-1</sup></code>, where <code>T</code> is the given <code>translation</code> and
* <code>R</code> is a rotation transformation specified by the given quaternion.
* <p>
* This method is equivalent to calling: <code>translationRotate(...).invert()</code>
*
* @see #translationRotate(Vector3dc, Quaterniondc)
* @see #invert()
*
* @param translation
* the translation
* @param quat
* the quaternion representing a rotation
* @return this
*/
public Matrix4d translationRotateInvert(Vector3fc translation,
Quaternionfc quat) {
return translationRotateInvert(translation.x(), translation.y(), translation.z(), quat.x(), quat.y(), quat.z(), quat.w());
}

/**
* Apply the rotation - and possibly scaling - transformation of the given {@link Quaterniondc} to this matrix and store
* the result in <code>dest</code>.
Expand Down
108 changes: 107 additions & 1 deletion src/org/joml/Matrix4f.java
Original file line number Diff line number Diff line change
Expand Up @@ -4185,7 +4185,7 @@ public Matrix4f translationRotateScaleInvert(float tx, float ty, float tz,
float sx, float sy, float sz) {
boolean one = Math.absEqualsOne(sx) && Math.absEqualsOne(sy) && Math.absEqualsOne(sz);
if (one)
return translationRotateScale(tx, ty, tz, qx, qy, qz, qw, sx, sy, sz).invertOrthonormal(this);
return translationRotateInvert(tx, ty, tz, qx, qy, qz, qw);
float nqx = -qx, nqy = -qy, nqz = -qz;
float dqx = nqx + nqx;
float dqy = nqy + nqy;
Expand Down Expand Up @@ -4485,6 +4485,112 @@ public Matrix4f translationRotate(float tx, float ty, float tz, Quaternionfc qua
return translationRotate(tx, ty, tz, quat.x(), quat.y(), quat.z(), quat.w());
}

/**
* Set <code>this</code> matrix to <code>T * R</code>, where <code>T</code> is the given <code>translation</code> and
* <code>R</code> is a rotation transformation specified by the given quaternion.
* <p>
* When transforming a vector by the resulting matrix the scaling transformation will be applied first, then the rotation and
* at last the translation.
* <p>
* When used with a right-handed coordinate system, the produced rotation will rotate a vector
* counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.
* When used with a left-handed coordinate system, the rotation is clockwise.
* <p>
* This method is equivalent to calling: <code>translation(translation).rotate(quat)</code>
*
* @see #translation(Vector3fc)
* @see #rotate(Quaternionfc)
*
* @param translation
* the translation
* @param quat
* the quaternion representing a rotation
* @return this
*/
public Matrix4f translationRotate(Vector3fc translation,
Quaternionfc quat) {
return translationRotate(translation.x(), translation.y(), translation.z(), quat.x(), quat.y(), quat.z(), quat.w());
}

/**
* Set <code>this</code> matrix to <code>(T * R)<sup>-1</sup></code>, where <code>T</code> is a translation by the given <code>(tx, ty, tz)</code> and
* <code>R</code> is a rotation transformation specified by the quaternion <code>(qx, qy, qz, qw)</code>.
* <p>
* This method is equivalent to calling: <code>translationRotate(...).invert()</code>
*
* @see #translationRotate(float, float, float, float, float, float, float)
* @see #invert()
*
* @param tx
* the number of units by which to translate the x-component
* @param ty
* the number of units by which to translate the y-component
* @param tz
* the number of units by which to translate the z-component
* @param qx
* the x-coordinate of the vector part of the quaternion
* @param qy
* the y-coordinate of the vector part of the quaternion
* @param qz
* the z-coordinate of the vector part of the quaternion
* @param qw
* the scalar part of the quaternion
* @return this
*/
public Matrix4f translationRotateInvert(float tx, float ty, float tz, float qx, float qy, float qz, float qw) {
float nqx = -qx, nqy = -qy, nqz = -qz;
float dqx = nqx + nqx;
float dqy = nqy + nqy;
float dqz = nqz + nqz;
float q00 = dqx * nqx;
float q11 = dqy * nqy;
float q22 = dqz * nqz;
float q01 = dqx * nqy;
float q02 = dqx * nqz;
float q03 = dqx * qw;
float q12 = dqy * nqz;
float q13 = dqy * qw;
float q23 = dqz * qw;
return this
._m00(1.0f - q11 - q22)
._m01(q01 + q23)
._m02(q02 - q13)
._m03(0.0f)
._m10(q01 - q23)
._m11(1.0f - q22 - q00)
._m12(q12 + q03)
._m13(0.0f)
._m20(q02 + q13)
._m21(q12 - q03)
._m22(1.0f - q11 - q00)
._m23(0.0f)
._m30(-m00 * tx - m10 * ty - m20 * tz)
._m31(-m01 * tx - m11 * ty - m21 * tz)
._m32(-m02 * tx - m12 * ty - m22 * tz)
._m33(1.0f)
._properties(PROPERTY_AFFINE | PROPERTY_ORTHONORMAL);
}

/**
* Set <code>this</code> matrix to <code>(T * R)<sup>-1</sup></code>, where <code>T</code> is the given <code>translation</code> and
* <code>R</code> is a rotation transformation specified by the given quaternion.
* <p>
* This method is equivalent to calling: <code>translationRotate(...).invert()</code>
*
* @see #translationRotate(Vector3fc, Quaternionfc)
* @see #invert()
*
* @param translation
* the translation
* @param quat
* the quaternion representing a rotation
* @return this
*/
public Matrix4f translationRotateInvert(Vector3fc translation,
Quaternionfc quat) {
return translationRotateInvert(translation.x(), translation.y(), translation.z(), quat.x(), quat.y(), quat.z(), quat.w());
}

/**
* Set the upper left 3x3 submatrix of this {@link Matrix4f} to the given {@link Matrix3fc} and don't change the other elements.
*
Expand Down
Loading

0 comments on commit aad9dfc

Please sign in to comment.