Skip to content

Commit 5e99633

Browse files
authored
add some caveats to the com.jme3.math javadoc (#2156)
1 parent 2073697 commit 5e99633

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

jme3-core/src/main/java/com/jme3/math/Matrix4f.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,9 @@ public Vector3f toTranslationVector(Vector3f vector) {
18021802
/**
18031803
* Determine the rotation component of this 3-D coordinate transform.
18041804
*
1805+
* <p>Assumes (but does not verify) that the transform consists entirely of
1806+
* translation, rotation, and positive scaling -- no reflection or shear.
1807+
*
18051808
* @return a new rotation Quaternion
18061809
*/
18071810
public Quaternion toRotationQuat() {
@@ -1813,6 +1816,9 @@ public Quaternion toRotationQuat() {
18131816
/**
18141817
* Returns the rotation component of the coordinate transform.
18151818
*
1819+
* <p>Assumes (but does not verify) that the transform consists entirely of
1820+
* translation, rotation, and positive scaling -- no reflection or shear.
1821+
*
18161822
* @param q storage for the result (not null, modified)
18171823
* @return the rotation component (in {@code q}) for chaining
18181824
*/
@@ -1824,7 +1830,10 @@ public Quaternion toRotationQuat(Quaternion q) {
18241830
/**
18251831
* Determine the rotation component of this 3-D coordinate transform.
18261832
*
1827-
* @return a new rotation Matrix3f
1833+
* <p>If the transform includes scaling or reflection or shear, the result
1834+
* might not be a valid rotation matrix.
1835+
*
1836+
* @return a new Matrix3f
18281837
*/
18291838
public Matrix3f toRotationMatrix() {
18301839
return new Matrix3f(m00, m01, m02, m10, m11, m12, m20, m21, m22);
@@ -1833,6 +1842,9 @@ public Matrix3f toRotationMatrix() {
18331842
/**
18341843
* Determines the rotation component of the coordinate transform.
18351844
*
1845+
* <p>If the transform includes scaling or reflection or shear, the result
1846+
* might not be a valid rotation matrix.
1847+
*
18361848
* @param mat storage for the result (not null, modified)
18371849
*/
18381850
public void toRotationMatrix(Matrix3f mat) {
@@ -1850,6 +1862,9 @@ public void toRotationMatrix(Matrix3f mat) {
18501862
/**
18511863
* Determine the scale component of this 3-D coordinate transform.
18521864
*
1865+
* <p>All components of the result will be non-negative, even if the
1866+
* coordinate transform includes reflection.
1867+
*
18531868
* @return a new Vector3f
18541869
*/
18551870
public Vector3f toScaleVector() {
@@ -1861,6 +1876,9 @@ public Vector3f toScaleVector() {
18611876
/**
18621877
* Determines the scale component of the coordinate transform.
18631878
*
1879+
* <p>All components of the result will be non-negative, even if the
1880+
* coordinate transform includes reflection.
1881+
*
18641882
* @param store storage for the result (not null, modified)
18651883
* @return the scale factors (in {@code store}) for chaining
18661884
*/

jme3-core/src/main/java/com/jme3/math/Quaternion.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,10 @@ public float[] toAngles(float[] angles) {
356356
}
357357

358358
/**
359-
* Sets the quaternion from the specified rotation matrix. Does not verify
360-
* that the argument is a valid rotation matrix.
359+
* Sets the quaternion from the specified rotation matrix.
360+
*
361+
* <p>Does not verify that the argument is a valid rotation matrix.
362+
* Positive scaling is compensated for, but not reflection or shear.
361363
*
362364
* @param matrix the input matrix (not null, unaffected)
363365
* @return the (modified) current instance (for chaining)
@@ -369,7 +371,9 @@ public Quaternion fromRotationMatrix(Matrix3f matrix) {
369371

370372
/**
371373
* Sets the quaternion from a rotation matrix with the specified elements.
372-
* Does not verify that the arguments form a valid rotation matrix.
374+
*
375+
* <p>Does not verify that the arguments form a valid rotation matrix.
376+
* Positive scaling is compensated for, but not reflection or shear.
373377
*
374378
* @param m00 the matrix element in row 0, column 0
375379
* @param m01 the matrix element in row 0, column 1
@@ -385,7 +389,7 @@ public Quaternion fromRotationMatrix(Matrix3f matrix) {
385389
public Quaternion fromRotationMatrix(float m00, float m01, float m02,
386390
float m10, float m11, float m12, float m20, float m21, float m22) {
387391
// first normalize the forward (F), up (U) and side (S) vectors of the rotation matrix
388-
// so that the scale does not affect the rotation
392+
// so that positive scaling does not affect the rotation
389393
float lengthSquared = m00 * m00 + m10 * m10 + m20 * m20;
390394
if (lengthSquared != 1f && lengthSquared != 0f) {
391395
lengthSquared = 1.0f / FastMath.sqrt(lengthSquared);
@@ -564,7 +568,7 @@ public Matrix4f toTransformMatrix(Matrix4f store) {
564568
* current instance is unaffected.
565569
*
566570
* <p>Note: preserves the translation and scaling components of
567-
* {@code result}.
571+
* {@code result} unless {@code result} includes reflection.
568572
*
569573
* <p>Note: the result is created from a normalized version of the current
570574
* instance.
@@ -1013,6 +1017,9 @@ public Quaternion mult(Quaternion q, Quaternion storeResult) {
10131017
/**
10141018
* Applies the rotation represented by the argument to the current instance.
10151019
*
1020+
* <p>Does not verify that {@code matrix} is a valid rotation matrix.
1021+
* Positive scaling is compensated for, but not reflection or shear.
1022+
*
10161023
* @param matrix the rotation matrix to apply (not null, unaffected)
10171024
*/
10181025
public void apply(Matrix3f matrix) {

jme3-core/src/main/java/com/jme3/math/Transform.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,13 @@ public Matrix4f toTransformMatrix(Matrix4f store) {
389389
}
390390

391391
/**
392-
* Sets the current instance from a transform matrix. Any shear in the
392+
* Sets the current instance from a transform matrix. Any reflection or shear in the
393393
* matrix is lost -- in other words, it may not be possible to recreate the
394394
* original matrix from the result.
395395
*
396+
* <p>After this method is invoked, all components of {@code scale} will be
397+
* non-negative, even if {@code mat} includes reflection.
398+
*
396399
* @param mat the input matrix (not null, unaffected)
397400
*/
398401
public void fromTransformMatrix(Matrix4f mat) {
@@ -406,6 +409,10 @@ public void fromTransformMatrix(Matrix4f mat) {
406409
/**
407410
* Returns the inverse. The current instance is unaffected.
408411
*
412+
* <p>Assumes (but does not verify) that the scale factors are all positive.
413+
* If any component of {@code scale} is negative or zero, the result is
414+
* undefined.
415+
*
409416
* @return a new Transform
410417
*/
411418
public Transform invert() {

0 commit comments

Comments
 (0)