Skip to content

Commit

Permalink
Addressing issue Rajawali#1784:
Browse files Browse the repository at this point in the history
- adding throws IllegalStateException to Matrix4.setToNormal() as it depends on Matrix4.inverse()
- putting call to setToNormal() in Material.setModelMatrix() in try/catch block, thus enabling continued rendering of degenerate/zero-scale Object3Ds (which have singular model matrices)
  • Loading branch information
rpicolet committed Oct 4, 2016
1 parent 000826a commit 30553f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Expand Up @@ -1073,7 +1073,12 @@ public void setModelMatrix(Matrix4 modelMatrix) {
mModelMatrix = modelMatrix;//.getFloatValues();
mVertexShader.setModelMatrix(mModelMatrix);

mNormalMatrix.setAll(modelMatrix).setToNormalMatrix();
mNormalMatrix.setAll(modelMatrix);
try {
mNormalMatrix.setToNormalMatrix();
} catch (IllegalStateException exception) {
// modelMatrix is degenerate (zero scale)
}
float[] matrix = mNormalMatrix.getFloatValues();

mNormalFloats[0] = matrix[0];
Expand Down
6 changes: 4 additions & 2 deletions rajawali/src/main/java/org/rajawali3d/math/Matrix4.java
Expand Up @@ -339,7 +339,7 @@ public double determinant() {
*
* @return A reference to this {@link Matrix4} to facilitate chaining.
*
* @throws IllegalStateException if this matrix is singular and cannot be in
* @throws IllegalStateException if this matrix is singular and cannot be inverted
*/
@NonNull
public Matrix4 inverse() throws IllegalStateException {
Expand Down Expand Up @@ -717,9 +717,11 @@ public Matrix4 lerp(@NonNull Matrix4 matrix, double t) {
* Removes the translational component, inverts and transposes the matrix.
*
* @return A reference to this {@link Matrix4} to facilitate chaining.
*
* @throws IllegalStateException if this matrix is singular and cannot be inverted
*/
@NonNull
public Matrix4 setToNormalMatrix() {
public Matrix4 setToNormalMatrix() throws IllegalStateException {
m[M03] = 0;
m[M13] = 0;
m[M23] = 0;
Expand Down

0 comments on commit 30553f9

Please sign in to comment.