@Override public void computeNormalMatrix(final boolean modelIsUniformScale) { final Matrix3 normal = Matrix3.fetchTempInstance(); final FloatBuffer dst = _matrixStore.get(RenderMatrixType.Normal); dst.clear(); final Matrix4 model = Matrix4.fetchTempInstance(); final FloatBuffer modelBuff = _matrixStore.get(RenderMatrixType.Model); modelBuff.clear(); model.fromFloatBuffer(modelBuff); if (modelIsUniformScale) { // normal matrix is just the 3x3 of the model matrix model.toMatrix3(normal); } else { // normal matrix is the inverse transpose of the 3x3 model matrix model.toMatrix3(normal); try { normal.invertLocal().transposeLocal(); } catch (final ArithmeticException ex) { // silently ignore for now - non invertable } } normal.toFloatBuffer(dst); } }
@Test public void testTranspose() { final Matrix3 mat3A = new Matrix3( // 0.01, 0.1, 0.2, // 1.0, 1.1, 1.2, // 2.0, 2.1, 2.2); final Matrix3 result = mat3A.transpose(null); assertEquals(new Matrix3( // 0.01, 1.0, 2.0, // 0.1, 1.1, 2.1, // 0.2, 1.2, 2.2), result); assertEquals(new Matrix3( // 0.01, 0.1, 0.2, // 1.0, 1.1, 1.2, // 2.0, 2.1, 2.2), result.transposeLocal()); // coverage final Matrix3 result2 = result.transposeLocal().transpose(new Matrix3()); assertEquals(mat3A, result2); }
if (_uniformScale) { final double sx = _scale.getX(); newMatrix.transposeLocal(); if (sx != 1.0) { newMatrix.multiplyLocal(1.0 / sx);
if (_uniformScale) { final double sx = _scale.getX(); newMatrix.transposeLocal(); if (sx != 1.0) { newMatrix.multiplyLocal(1.0 / sx);