diff options
Diffstat (limited to 'src')
5 files changed, 409 insertions, 187 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java b/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java index f793629d6..9ffa3bba6 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java @@ -919,27 +919,27 @@ public final class FloatUtil { final float m44 = + a11*(a22*a33 - a23*a32) - a12*(a21*a33 - a23*a31) + a13*(a21*a32 - a22*a31); final float det = (a11*m11 + a12*m12 + a13*m13 + a14*m14)/scale; - if( 0 == det ) { return null; } - - mres[0+4*0+mres_offset] = m11 / det; - mres[1+4*0+mres_offset] = m12 / det; - mres[2+4*0+mres_offset] = m13 / det; - mres[3+4*0+mres_offset] = m14 / det; - mres[0+4*1+mres_offset] = m21 / det; - mres[1+4*1+mres_offset] = m22 / det; - mres[2+4*1+mres_offset] = m23 / det; - mres[3+4*1+mres_offset] = m24 / det; - mres[0+4*2+mres_offset] = m31 / det; - mres[1+4*2+mres_offset] = m32 / det; - mres[2+4*2+mres_offset] = m33 / det; - mres[3+4*2+mres_offset] = m34 / det; - mres[0+4*3+mres_offset] = m41 / det; - mres[1+4*3+mres_offset] = m42 / det; - mres[2+4*3+mres_offset] = m43 / det; - mres[3+4*3+mres_offset] = m44 / det; + final float invdet = 1.0f / det; + + mres[0+4*0+mres_offset] = m11 * invdet; + mres[1+4*0+mres_offset] = m12 * invdet; + mres[2+4*0+mres_offset] = m13 * invdet; + mres[3+4*0+mres_offset] = m14 * invdet; + mres[0+4*1+mres_offset] = m21 * invdet; + mres[1+4*1+mres_offset] = m22 * invdet; + mres[2+4*1+mres_offset] = m23 * invdet; + mres[3+4*1+mres_offset] = m24 * invdet; + mres[0+4*2+mres_offset] = m31 * invdet; + mres[1+4*2+mres_offset] = m32 * invdet; + mres[2+4*2+mres_offset] = m33 * invdet; + mres[3+4*2+mres_offset] = m34 * invdet; + mres[0+4*3+mres_offset] = m41 * invdet; + mres[1+4*3+mres_offset] = m42 * invdet; + mres[2+4*3+mres_offset] = m43 * invdet; + mres[3+4*3+mres_offset] = m44 * invdet; return mres; } @@ -1004,27 +1004,27 @@ public final class FloatUtil { final float m44 = + a11*(a22*a33 - a23*a32) - a12*(a21*a33 - a23*a31) + a13*(a21*a32 - a22*a31); final float det = (a11*m11 + a12*m12 + a13*m13 + a14*m14)/scale; - if( 0 == det ) { return null; } - - mres[0+4*0] = m11 / det; - mres[1+4*0] = m12 / det; - mres[2+4*0] = m13 / det; - mres[3+4*0] = m14 / det; - mres[0+4*1] = m21 / det; - mres[1+4*1] = m22 / det; - mres[2+4*1] = m23 / det; - mres[3+4*1] = m24 / det; - mres[0+4*2] = m31 / det; - mres[1+4*2] = m32 / det; - mres[2+4*2] = m33 / det; - mres[3+4*2] = m34 / det; - mres[0+4*3] = m41 / det; - mres[1+4*3] = m42 / det; - mres[2+4*3] = m43 / det; - mres[3+4*3] = m44 / det; + final float invdet = 1.0f / det; + + mres[0+4*0] = m11 * invdet; + mres[1+4*0] = m12 * invdet; + mres[2+4*0] = m13 * invdet; + mres[3+4*0] = m14 * invdet; + mres[0+4*1] = m21 * invdet; + mres[1+4*1] = m22 * invdet; + mres[2+4*1] = m23 * invdet; + mres[3+4*1] = m24 * invdet; + mres[0+4*2] = m31 * invdet; + mres[1+4*2] = m32 * invdet; + mres[2+4*2] = m33 * invdet; + mres[3+4*2] = m34 * invdet; + mres[0+4*3] = m41 * invdet; + mres[1+4*3] = m42 * invdet; + mres[2+4*3] = m43 * invdet; + mres[3+4*3] = m44 * invdet; return mres; } diff --git a/src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java b/src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java index 5951c7d98..6f4b2f38d 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java +++ b/src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java @@ -328,8 +328,9 @@ public class Matrix4f { * * @param dst float[16] array storage in column major order * @param dst_off offset + * @return {@code dst} for chaining */ - public void get(final float[] dst, final int dst_off) { + public float[] get(final float[] dst, final int dst_off) { dst[dst_off+0+0*4] = m00; dst[dst_off+1+0*4] = m10; dst[dst_off+2+0*4] = m20; @@ -346,14 +347,16 @@ public class Matrix4f { dst[dst_off+1+3*4] = m13; dst[dst_off+2+3*4] = m23; dst[dst_off+3+3*4] = m33; + return dst; } /** * Get this matrix into the given float[16] array in column major order. * * @param dst float[16] array storage in column major order + * @return {@code dst} for chaining */ - public void get(final float[] dst) { + public float[] get(final float[] dst) { dst[0+0*4] = m00; dst[1+0*4] = m10; dst[2+0*4] = m20; @@ -370,6 +373,7 @@ public class Matrix4f { dst[1+3*4] = m13; dst[2+3*4] = m23; dst[3+3*4] = m33; + return dst; } /** @@ -380,8 +384,9 @@ public class Matrix4f { * </p> * * @param dst {@link FloatBuffer} array storage in column major order + * @return {@code dst} for chaining */ - public void get(final FloatBuffer dst) { + public FloatBuffer get(final FloatBuffer dst) { dst.put( m00 ); dst.put( m10 ); dst.put( m20 ); @@ -398,6 +403,7 @@ public class Matrix4f { dst.put( m13 ); dst.put( m23 ); dst.put( m33 ); + return dst; } // @@ -490,35 +496,11 @@ public class Matrix4f { */ public boolean invert() { final float scale; - { - float a = Math.abs(m00); - float max = a; - - a = Math.abs(m01); if( a > max ) max = a; - a = Math.abs(m02); if( a > max ) max = a; - a = Math.abs(m03); if( a > max ) max = a; - - a = Math.abs(m10); if( a > max ) max = a; - a = Math.abs(m11); if( a > max ) max = a; - a = Math.abs(m12); if( a > max ) max = a; - a = Math.abs(m13); if( a > max ) max = a; - - a = Math.abs(m20); if( a > max ) max = a; - a = Math.abs(m21); if( a > max ) max = a; - a = Math.abs(m22); if( a > max ) max = a; - a = Math.abs(m23); if( a > max ) max = a; - - a = Math.abs(m30); if( a > max ) max = a; - a = Math.abs(m31); if( a > max ) max = a; - a = Math.abs(m32); if( a > max ) max = a; - a = Math.abs(m33); if( a > max ) max = a; - - if( 0 == max ) { - return false; - } - scale = 1.0f/max; + try { + scale = mulScale(); + } catch(final ArithmeticException aex) { + return false; // max was 0 } - final float a00 = m00*scale; final float a10 = m10*scale; final float a20 = m20*scale; @@ -560,30 +542,30 @@ public class Matrix4f { final float b33 = + a00*(a11*a22 - a12*a21) - a01*(a10*a22 - a12*a20) + a02*(a10*a21 - a11*a20); final float det = (a00*b00 + a01*b01 + a02*b02 + a03*b03) / scale; - if( 0 == det ) { return false; } - - m00 = b00 / det; - m10 = b01 / det; - m20 = b02 / det; - m30 = b03 / det; - - m01 = b10 / det; - m11 = b11 / det; - m21 = b12 / det; - m31 = b13 / det; - - m02 = b20 / det; - m12 = b21 / det; - m22 = b22 / det; - m32 = b23 / det; - - m03 = b30 / det; - m13 = b31 / det; - m23 = b32 / det; - m33 = b33 / det; + final float invdet = 1.0f / det; + + m00 = b00 * invdet; + m10 = b01 * invdet; + m20 = b02 * invdet; + m30 = b03 * invdet; + + m01 = b10 * invdet; + m11 = b11 * invdet; + m21 = b12 * invdet; + m31 = b13 * invdet; + + m02 = b20 * invdet; + m12 = b21 * invdet; + m22 = b22 * invdet; + m32 = b23 * invdet; + + m03 = b30 * invdet; + m13 = b31 * invdet; + m23 = b32 * invdet; + m33 = b33 * invdet; return true; } @@ -593,7 +575,113 @@ public class Matrix4f { * @return false if {@code src} matrix is singular and inversion not possible, otherwise true */ public boolean invert(final Matrix4f src) { - return load(src).invert(); + final float scale; + try { + scale = src.mulScale(); + } catch(final ArithmeticException aex) { + return false; // max was 0 + } + final float a00 = src.m00*scale; + final float a10 = src.m10*scale; + final float a20 = src.m20*scale; + final float a30 = src.m30*scale; + + final float a01 = src.m01*scale; + final float a11 = src.m11*scale; + final float a21 = src.m21*scale; + final float a31 = src.m31*scale; + + final float a02 = src.m02*scale; + final float a12 = src.m12*scale; + final float a22 = src.m22*scale; + final float a32 = src.m32*scale; + + final float a03 = src.m03*scale; + final float a13 = src.m13*scale; + final float a23 = src.m23*scale; + final float a33 = src.m33*scale; + + final float b00 = + a11*(a22*a33 - a23*a32) - a12*(a21*a33 - a23*a31) + a13*(a21*a32 - a22*a31); + final float b01 = -( + a10*(a22*a33 - a23*a32) - a12*(a20*a33 - a23*a30) + a13*(a20*a32 - a22*a30)); + final float b02 = + a10*(a21*a33 - a23*a31) - a11*(a20*a33 - a23*a30) + a13*(a20*a31 - a21*a30); + final float b03 = -( + a10*(a21*a32 - a22*a31) - a11*(a20*a32 - a22*a30) + a12*(a20*a31 - a21*a30)); + + final float b10 = -( + a01*(a22*a33 - a23*a32) - a02*(a21*a33 - a23*a31) + a03*(a21*a32 - a22*a31)); + final float b11 = + a00*(a22*a33 - a23*a32) - a02*(a20*a33 - a23*a30) + a03*(a20*a32 - a22*a30); + final float b12 = -( + a00*(a21*a33 - a23*a31) - a01*(a20*a33 - a23*a30) + a03*(a20*a31 - a21*a30)); + final float b13 = + a00*(a21*a32 - a22*a31) - a01*(a20*a32 - a22*a30) + a02*(a20*a31 - a21*a30); + + final float b20 = + a01*(a12*a33 - a13*a32) - a02*(a11*a33 - a13*a31) + a03*(a11*a32 - a12*a31); + final float b21 = -( + a00*(a12*a33 - a13*a32) - a02*(a10*a33 - a13*a30) + a03*(a10*a32 - a12*a30)); + final float b22 = + a00*(a11*a33 - a13*a31) - a01*(a10*a33 - a13*a30) + a03*(a10*a31 - a11*a30); + final float b23 = -( + a00*(a11*a32 - a12*a31) - a01*(a10*a32 - a12*a30) + a02*(a10*a31 - a11*a30)); + + final float b30 = -( + a01*(a12*a23 - a13*a22) - a02*(a11*a23 - a13*a21) + a03*(a11*a22 - a12*a21)); + final float b31 = + a00*(a12*a23 - a13*a22) - a02*(a10*a23 - a13*a20) + a03*(a10*a22 - a12*a20); + final float b32 = -( + a00*(a11*a23 - a13*a21) - a01*(a10*a23 - a13*a20) + a03*(a10*a21 - a11*a20)); + final float b33 = + a00*(a11*a22 - a12*a21) - a01*(a10*a22 - a12*a20) + a02*(a10*a21 - a11*a20); + + final float det = (a00*b00 + a01*b01 + a02*b02 + a03*b03) / scale; + + if( 0 == det ) { + return false; + } + final float invdet = 1.0f / det; + + m00 = b00 * invdet; + m10 = b01 * invdet; + m20 = b02 * invdet; + m30 = b03 * invdet; + + m01 = b10 * invdet; + m11 = b11 * invdet; + m21 = b12 * invdet; + m31 = b13 * invdet; + + m02 = b20 * invdet; + m12 = b21 * invdet; + m22 = b22 * invdet; + m32 = b23 * invdet; + + m03 = b30 * invdet; + m13 = b31 * invdet; + m23 = b32 * invdet; + m33 = b33 * invdet; + return true; + } + + private final float mulScale() { + /** + // No Hotspot intrinsic Math.* optimization for at least Math.max(), + // hence this chunk is slower. + float max = Math.abs(m00); + + max = Math.max(max, Math.abs(m01)); + max = Math.max(max, Math.abs(m02)); + ... etc + */ + float a = Math.abs(m00); + float max = a; + a = Math.abs(m01); if( a > max ) max = a; + a = Math.abs(m02); if( a > max ) max = a; + a = Math.abs(m03); if( a > max ) max = a; + + a = Math.abs(m10); if( a > max ) max = a; + a = Math.abs(m11); if( a > max ) max = a; + a = Math.abs(m12); if( a > max ) max = a; + a = Math.abs(m13); if( a > max ) max = a; + + a = Math.abs(m20); if( a > max ) max = a; + a = Math.abs(m21); if( a > max ) max = a; + a = Math.abs(m22); if( a > max ) max = a; + a = Math.abs(m23); if( a > max ) max = a; + + a = Math.abs(m30); if( a > max ) max = a; + a = Math.abs(m31); if( a > max ) max = a; + a = Math.abs(m32); if( a > max ) max = a; + a = Math.abs(m33); if( a > max ) max = a; + + return 1.0f/max; } /** diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/math/Matrix4fb.java b/src/test/com/jogamp/opengl/test/junit/jogl/math/Matrix4fb.java index fb4c11b7c..28e748d24 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/math/Matrix4fb.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/math/Matrix4fb.java @@ -264,18 +264,22 @@ public class Matrix4fb { * * @param dst float[16] array storage in column major order * @param dst_off offset + * @return {@code dst} for chaining */ - public void get(final float[] dst, final int dst_off) { + public float[] get(final float[] dst, final int dst_off) { System.arraycopy(m, 0, dst, dst_off, 16); + return dst; } /** * Get this matrix into the given float[16] array in column major order. * * @param dst float[16] array storage in column major order + * @return {@code dst} for chaining */ - public void get(final float[] dst) { + public float[] get(final float[] dst) { System.arraycopy(m, 0, dst, 0, 16); + return dst; } /** @@ -286,9 +290,11 @@ public class Matrix4fb { * </p> * * @param dst {@link FloatBuffer} array storage in column major order + * @return {@code dst} for chaining */ - public void get(final FloatBuffer dst) { + public FloatBuffer get(final FloatBuffer dst) { dst.put(m, 0, 16); + return dst; } // @@ -381,18 +387,18 @@ public class Matrix4fb { */ public boolean invert() { final float scale; - { - float max = Math.abs(m[0]); - - for( int i = 1; i < 16; i++ ) { - final float a = Math.abs(m[i]); - if( a > max ) max = a; - } - if( 0 == max ) { - return false; - } - scale = 1.0f/max; - } + { + float max = Math.abs(m[0]); + + for( int i = 1; i < 16; i++ ) { + final float a = Math.abs(m[i]); + if( a > max ) max = a; + } + if( 0 == max ) { + return false; + } + scale = 1.0f/max; + } final float a00 = m[0+0*4]*scale; final float a10 = m[1+0*4]*scale; @@ -435,30 +441,30 @@ public class Matrix4fb { final float b33 = + a00*(a11*a22 - a12*a21) - a01*(a10*a22 - a12*a20) + a02*(a10*a21 - a11*a20); final float det = (a00*b00 + a01*b01 + a02*b02 + a03*b03) / scale; - if( 0 == det ) { return false; } - - m[0+0*4] = b00 / det; - m[1+0*4] = b01 / det; - m[2+0*4] = b02 / det; - m[3+0*4] = b03 / det; - - m[0+1*4] = b10 / det; - m[1+1*4] = b11 / det; - m[2+1*4] = b12 / det; - m[3+1*4] = b13 / det; - - m[0+2*4] = b20 / det; - m[1+2*4] = b21 / det; - m[2+2*4] = b22 / det; - m[3+2*4] = b23 / det; - - m[0+3*4] = b30 / det; - m[1+3*4] = b31 / det; - m[2+3*4] = b32 / det; - m[3+3*4] = b33 / det; + final float invdet = 1.0f / det; + + m[0+0*4] = b00 * invdet; + m[1+0*4] = b01 * invdet; + m[2+0*4] = b02 * invdet; + m[3+0*4] = b03 * invdet; + + m[0+1*4] = b10 * invdet; + m[1+1*4] = b11 * invdet; + m[2+1*4] = b12 * invdet; + m[3+1*4] = b13 * invdet; + + m[0+2*4] = b20 * invdet; + m[1+2*4] = b21 * invdet; + m[2+2*4] = b22 * invdet; + m[3+2*4] = b23 * invdet; + + m[0+3*4] = b30 * invdet; + m[1+3*4] = b31 * invdet; + m[2+3*4] = b32 * invdet; + m[3+3*4] = b33 * invdet; return true; } @@ -468,7 +474,86 @@ public class Matrix4fb { * @return false if {@code src} matrix is singular and inversion not possible, otherwise true */ public boolean invert(final Matrix4fb src) { - return load(src).invert(); + final float scale; + { + float max = Math.abs(src.m[0]); + + for( int i = 1; i < 16; i++ ) { + final float a = Math.abs(src.m[i]); + if( a > max ) max = a; + } + if( 0 == max ) { + return false; + } + scale = 1.0f/max; + } + + final float a00 = src.m[0+0*4]*scale; + final float a10 = src.m[1+0*4]*scale; + final float a20 = src.m[2+0*4]*scale; + final float a30 = src.m[3+0*4]*scale; + + final float a01 = src.m[0+1*4]*scale; + final float a11 = src.m[1+1*4]*scale; + final float a21 = src.m[2+1*4]*scale; + final float a31 = src.m[3+1*4]*scale; + + final float a02 = src.m[0+2*4]*scale; + final float a12 = src.m[1+2*4]*scale; + final float a22 = src.m[2+2*4]*scale; + final float a32 = src.m[3+2*4]*scale; + + final float a03 = src.m[0+3*4]*scale; + final float a13 = src.m[1+3*4]*scale; + final float a23 = src.m[2+3*4]*scale; + final float a33 = src.m[3+3*4]*scale; + + final float b00 = + a11*(a22*a33 - a23*a32) - a12*(a21*a33 - a23*a31) + a13*(a21*a32 - a22*a31); + final float b01 = -( + a10*(a22*a33 - a23*a32) - a12*(a20*a33 - a23*a30) + a13*(a20*a32 - a22*a30)); + final float b02 = + a10*(a21*a33 - a23*a31) - a11*(a20*a33 - a23*a30) + a13*(a20*a31 - a21*a30); + final float b03 = -( + a10*(a21*a32 - a22*a31) - a11*(a20*a32 - a22*a30) + a12*(a20*a31 - a21*a30)); + + final float b10 = -( + a01*(a22*a33 - a23*a32) - a02*(a21*a33 - a23*a31) + a03*(a21*a32 - a22*a31)); + final float b11 = + a00*(a22*a33 - a23*a32) - a02*(a20*a33 - a23*a30) + a03*(a20*a32 - a22*a30); + final float b12 = -( + a00*(a21*a33 - a23*a31) - a01*(a20*a33 - a23*a30) + a03*(a20*a31 - a21*a30)); + final float b13 = + a00*(a21*a32 - a22*a31) - a01*(a20*a32 - a22*a30) + a02*(a20*a31 - a21*a30); + + final float b20 = + a01*(a12*a33 - a13*a32) - a02*(a11*a33 - a13*a31) + a03*(a11*a32 - a12*a31); + final float b21 = -( + a00*(a12*a33 - a13*a32) - a02*(a10*a33 - a13*a30) + a03*(a10*a32 - a12*a30)); + final float b22 = + a00*(a11*a33 - a13*a31) - a01*(a10*a33 - a13*a30) + a03*(a10*a31 - a11*a30); + final float b23 = -( + a00*(a11*a32 - a12*a31) - a01*(a10*a32 - a12*a30) + a02*(a10*a31 - a11*a30)); + + final float b30 = -( + a01*(a12*a23 - a13*a22) - a02*(a11*a23 - a13*a21) + a03*(a11*a22 - a12*a21)); + final float b31 = + a00*(a12*a23 - a13*a22) - a02*(a10*a23 - a13*a20) + a03*(a10*a22 - a12*a20); + final float b32 = -( + a00*(a11*a23 - a13*a21) - a01*(a10*a23 - a13*a20) + a03*(a10*a21 - a11*a20)); + final float b33 = + a00*(a11*a22 - a12*a21) - a01*(a10*a22 - a12*a20) + a02*(a10*a21 - a11*a20); + + final float det = (a00*b00 + a01*b01 + a02*b02 + a03*b03) / scale; + if( 0 == det ) { + return false; + } + final float invdet = 1.0f / det; + + m[0+0*4] = b00 * invdet; + m[1+0*4] = b01 * invdet; + m[2+0*4] = b02 * invdet; + m[3+0*4] = b03 * invdet; + + m[0+1*4] = b10 * invdet; + m[1+1*4] = b11 * invdet; + m[2+1*4] = b12 * invdet; + m[3+1*4] = b13 * invdet; + + m[0+2*4] = b20 * invdet; + m[1+2*4] = b21 * invdet; + m[2+2*4] = b22 * invdet; + m[3+2*4] = b23 * invdet; + + m[0+3*4] = b30 * invdet; + m[1+3*4] = b31 * invdet; + m[2+3*4] = b32 * invdet; + m[3+3*4] = b33 * invdet; + return true; } /** diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestMatrix4f02MulNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestMatrix4f02MulNOUI.java index 5180451a1..510a437f3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestMatrix4f02MulNOUI.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestMatrix4f02MulNOUI.java @@ -154,15 +154,17 @@ public class TestMatrix4f02MulNOUI extends JunitTracer { }
tI4a = Platform.currentTimeMillis() - t_0;
+ res_m.load(m1);
+
// warm-up
for(int i=0; i<warmups; i++) {
- res_m.load(m1).mul(m2);
- res_m.load(m2).mul(m1);
+ res_m.mul(m2);
+ res_m.mul(m1);
}
t_0 = Platform.currentTimeMillis();
for(int i=0; i<loops; i++) {
- res_m.load(m1).mul(m2);
- res_m.load(m2).mul(m1);
+ res_m.mul(m2);
+ res_m.mul(m1);
}
tI4b = Platform.currentTimeMillis() - t_0;
@@ -182,15 +184,17 @@ public class TestMatrix4f02MulNOUI extends JunitTracer { }
tI5a = Platform.currentTimeMillis() - t_0;
+ res_n.load(n1);
+
// warm-up
for(int i=0; i<warmups; i++) {
- res_n.load(n1).mul(n2);
- res_n.load(n2).mul(n1);
+ res_n.mul(n2);
+ res_n.mul(n1);
}
t_0 = Platform.currentTimeMillis();
for(int i=0; i<loops; i++) {
- res_n.load(n1).mul(n2);
- res_n.load(n2).mul(n1);
+ res_n.mul(n2);
+ res_n.mul(n1);
}
tI5b = Platform.currentTimeMillis() - t_0;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestMatrix4f03InversionNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestMatrix4f03InversionNOUI.java index fee38bb54..f5b1a3151 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestMatrix4f03InversionNOUI.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestMatrix4f03InversionNOUI.java @@ -53,9 +53,9 @@ public class TestMatrix4f03InversionNOUI extends JunitTracer { 0, 0, 0, 1 };
FloatUtil.invertMatrix(identity, 0, res1, 0);
- System.err.println(FloatUtil.matrixToString(null, "inv-1: ", "%10.7f", res1, 0, 4, 4, false /* rowMajorOrder */));
+ // System.err.println(FloatUtil.matrixToString(null, "inv-1: ", "%10.7f", res1, 0, 4, 4, false /* rowMajorOrder */));
invertMatrix(identity, 0, res2, 0, temp);
- System.err.println(FloatUtil.matrixToString(null, "inv-2: ", "%10.7f", res2, 0, 4, 4, false /* rowMajorOrder */));
+ // System.err.println(FloatUtil.matrixToString(null, "inv-2: ", "%10.7f", res2, 0, 4, 4, false /* rowMajorOrder */));
Assert.assertArrayEquals("I1/I2 failure", res1, res2, FloatUtil.INV_DEVIANCE);
Assert.assertArrayEquals("I2 failure", identity, res2, FloatUtil.INV_DEVIANCE);
@@ -63,13 +63,13 @@ public class TestMatrix4f03InversionNOUI extends JunitTracer { final Matrix4f res3 = new Matrix4f(identity);
Assert.assertTrue( res3.invert() );
- System.err.println(res3.toString(null, "inv-4: ", "%10.7f"));
+ // System.err.println(res3.toString(null, "inv-4: ", "%10.7f"));
Assert.assertEquals(new Matrix4f(res1), res3);
Assert.assertEquals(new Matrix4f(), res3);
final Matrix4fb res4 = new Matrix4fb(identity);
Assert.assertTrue( res4.invert() );
- System.err.println(res4.toString(null, "inv-5: ", "%10.7f"));
+ // System.err.println(res4.toString(null, "inv-5: ", "%10.7f"));
Assert.assertEquals(new Matrix4fb(res1), res4);
Assert.assertEquals(new Matrix4fb(), res4);
}
@@ -83,19 +83,19 @@ public class TestMatrix4f03InversionNOUI extends JunitTracer { final float[] inv2_2 = new float[16];
final float[] temp = new float[16];
- System.err.println(FloatUtil.matrixToString(null, "orig : ", "%10.7f", matrix, 0, 4, 4, false /* rowMajorOrder */));
+ // System.err.println(FloatUtil.matrixToString(null, "orig : ", "%10.7f", matrix, 0, 4, 4, false /* rowMajorOrder */));
invertMatrix(matrix, 0, inv1_0, 0, temp);
invertMatrix(inv1_0, 0, inv2_0, 0, temp);
- System.err.println(FloatUtil.matrixToString(null, "inv1_0: ", "%10.7f", inv1_0, 0, 4, 4, false /* rowMajorOrder */));
- System.err.println(FloatUtil.matrixToString(null, "inv2_0: ", "%10.7f", inv2_0, 0, 4, 4, false /* rowMajorOrder */));
+ // System.err.println(FloatUtil.matrixToString(null, "inv1_0: ", "%10.7f", inv1_0, 0, 4, 4, false /* rowMajorOrder */));
+ // System.err.println(FloatUtil.matrixToString(null, "inv2_0: ", "%10.7f", inv2_0, 0, 4, 4, false /* rowMajorOrder */));
FloatUtil.invertMatrix(matrix, 0, inv1_1, 0);
FloatUtil.invertMatrix(inv1_1, 0, inv2_1, 0);
- System.err.println(FloatUtil.matrixToString(null, "inv1_1: ", "%10.7f", inv1_1, 0, 4, 4, false /* rowMajorOrder */));
- System.err.println(FloatUtil.matrixToString(null, "inv2_1: ", "%10.7f", inv2_1, 0, 4, 4, false /* rowMajorOrder */));
+ // System.err.println(FloatUtil.matrixToString(null, "inv1_1: ", "%10.7f", inv1_1, 0, 4, 4, false /* rowMajorOrder */));
+ // System.err.println(FloatUtil.matrixToString(null, "inv2_1: ", "%10.7f", inv2_1, 0, 4, 4, false /* rowMajorOrder */));
FloatUtil.invertMatrix(matrix, inv1_2);
FloatUtil.invertMatrix(inv1_2, inv2_2);
- System.err.println(FloatUtil.matrixToString(null, "inv1_2: ", "%10.7f", inv1_2, 0, 4, 4, false /* rowMajorOrder */));
- System.err.println(FloatUtil.matrixToString(null, "inv2_2: ", "%10.7f", inv2_2, 0, 4, 4, false /* rowMajorOrder */));
+ // System.err.println(FloatUtil.matrixToString(null, "inv1_2: ", "%10.7f", inv1_2, 0, 4, 4, false /* rowMajorOrder */));
+ // System.err.println(FloatUtil.matrixToString(null, "inv2_2: ", "%10.7f", inv2_2, 0, 4, 4, false /* rowMajorOrder */));
Assert.assertArrayEquals("I1_1/I1_2 failure", inv1_1, inv1_2, FloatUtil.INV_DEVIANCE);
Assert.assertArrayEquals("I2_1/I2_2 failure", inv2_1, inv2_2, FloatUtil.INV_DEVIANCE);
@@ -107,30 +107,39 @@ public class TestMatrix4f03InversionNOUI extends JunitTracer { Assert.assertArrayEquals("I2 failure", matrix, inv2_2, FloatUtil.INV_DEVIANCE);
Assert.assertArrayEquals("I2 failure", matrix, inv2_1, FloatUtil.INV_DEVIANCE);
+ //
+ // Matrix4f
+ //
+
final Matrix4f matrix_m = new Matrix4f(matrix);
final Matrix4f inv1_4a = new Matrix4f(matrix_m);
Assert.assertTrue( inv1_4a.invert() );
final Matrix4f inv2_4a = new Matrix4f(inv1_4a);
Assert.assertTrue( inv2_4a.invert() );
- System.err.println(inv1_4a.toString(null, "inv1_4a: ", "%10.7f"));
- System.err.println(inv2_4a.toString(null, "inv2_4a: ", "%10.7f"));
+ // System.err.println(inv1_4a.toString(null, "inv1_4a: ", "%10.7f"));
+ // System.err.println(inv2_4a.toString(null, "inv2_4a: ", "%10.7f"));
- Assert.assertEquals(new Matrix4f(inv1_2), inv1_4a);
- Assert.assertEquals(new Matrix4f(inv2_2), inv2_4a);
+ // Assert.assertEquals(new Matrix4f(inv1_2), inv1_4a);
+ // Assert.assertEquals(new Matrix4f(inv2_2), inv2_4a);
+ Assert.assertArrayEquals("I5 failure", inv1_2, inv1_4a.get(temp), FloatUtil.INV_DEVIANCE);
+ Assert.assertArrayEquals("I5 failure", inv2_2, inv2_4a.get(temp), FloatUtil.INV_DEVIANCE);
Assert.assertTrue("I4 failure: "+matrix_m+" != "+inv2_4a, matrix_m.isEqual(inv2_4a, FloatUtil.INV_DEVIANCE));
final Matrix4f inv1_4b = new Matrix4f();
Assert.assertTrue( inv1_4b.invert(matrix_m) );
final Matrix4f inv2_4b = new Matrix4f();
Assert.assertTrue( inv2_4b.invert(inv1_4b) );
- System.err.println(inv1_4b.toString(null, "inv1_4b: ", "%10.7f"));
- System.err.println(inv2_4b.toString(null, "inv2_4b: ", "%10.7f"));
+ // System.err.println(inv1_4b.toString(null, "inv1_4b: ", "%10.7f"));
+ // System.err.println(inv2_4b.toString(null, "inv2_4b: ", "%10.7f"));
- Assert.assertEquals(new Matrix4f(inv1_2), inv1_4b);
- Assert.assertEquals(new Matrix4f(inv2_2), inv2_4b);
+ // Assert.assertEquals(new Matrix4f(inv1_2), inv1_4b);
+ // Assert.assertEquals(new Matrix4f(inv2_2), inv2_4b);
+ Assert.assertArrayEquals("I5 failure", inv1_2, inv1_4b.get(temp), FloatUtil.INV_DEVIANCE);
+ Assert.assertArrayEquals("I5 failure", inv2_2, inv2_4b.get(temp), FloatUtil.INV_DEVIANCE);
Assert.assertTrue("I4 failure: "+matrix_m+" != "+inv2_4b, matrix_m.isEqual(inv2_4b, FloatUtil.INV_DEVIANCE));
//
+ // Matrix4fb
//
final Matrix4fb matrix_n = new Matrix4fb(matrix);
@@ -138,22 +147,26 @@ public class TestMatrix4f03InversionNOUI extends JunitTracer { Assert.assertTrue( inv1_5a.invert() );
final Matrix4fb inv2_5a = new Matrix4fb(inv1_5a);
Assert.assertTrue( inv2_5a.invert() );
- System.err.println(inv1_5a.toString(null, "inv1_5a: ", "%10.7f"));
- System.err.println(inv2_5a.toString(null, "inv2_5a: ", "%10.7f"));
+ // System.err.println(inv1_5a.toString(null, "inv1_5a: ", "%10.7f"));
+ // System.err.println(inv2_5a.toString(null, "inv2_5a: ", "%10.7f"));
- Assert.assertEquals(new Matrix4fb(inv1_2), inv1_5a);
- Assert.assertEquals(new Matrix4fb(inv2_2), inv2_5a);
+ // Assert.assertEquals(new Matrix4fb(inv1_2), inv1_5a);
+ // Assert.assertEquals(new Matrix4fb(inv2_2), inv2_5a);
+ Assert.assertArrayEquals("I5 failure", inv1_2, inv1_5a.get(temp), FloatUtil.INV_DEVIANCE);
+ Assert.assertArrayEquals("I5 failure", inv2_2, inv2_5a.get(temp), FloatUtil.INV_DEVIANCE);
Assert.assertTrue("I5 failure: "+matrix_n+" != "+inv2_5a, matrix_n.isEqual(inv2_5a, FloatUtil.INV_DEVIANCE));
final Matrix4fb inv1_5b = new Matrix4fb();
Assert.assertTrue( inv1_5b.invert(matrix_n) );
final Matrix4fb inv2_5b = new Matrix4fb();
Assert.assertTrue( inv2_5b.invert(inv1_5b) );
- System.err.println(inv1_5b.toString(null, "inv1_5b: ", "%10.7f"));
- System.err.println(inv2_5b.toString(null, "inv2_5b: ", "%10.7f"));
+ // System.err.println(inv1_5b.toString(null, "inv1_5b: ", "%10.7f"));
+ // System.err.println(inv2_5b.toString(null, "inv2_5b: ", "%10.7f"));
- Assert.assertEquals(new Matrix4fb(inv1_2), inv1_5b);
- Assert.assertEquals(new Matrix4fb(inv2_2), inv2_5b);
+ // Assert.assertEquals(new Matrix4fb(inv1_2), inv1_5b);
+ // Assert.assertEquals(new Matrix4fb(inv2_2), inv2_5b);
+ Assert.assertArrayEquals("I5 failure", inv1_2, inv1_5b.get(temp), FloatUtil.INV_DEVIANCE);
+ Assert.assertArrayEquals("I5 failure", inv2_2, inv2_5b.get(temp), FloatUtil.INV_DEVIANCE);
Assert.assertTrue("I5 failure: "+matrix_n+" != "+inv2_5b, matrix_n.isEqual(inv2_5b, FloatUtil.INV_DEVIANCE));
}
@@ -271,18 +284,6 @@ public class TestMatrix4f03InversionNOUI extends JunitTracer { // warm-up
for(int i=0; i<warmups; i++) {
- res_m.load(p1_m).invert();
- res_m.load(p2_m).invert();
- }
- t_0 = Platform.currentTimeMillis();
- for(int i=0; i<loops; i++) {
- res_m.load(p1_m).invert();
- res_m.load(p2_m).invert();
- }
- tI4a = Platform.currentTimeMillis() - t_0;
-
- // warm-up
- for(int i=0; i<warmups; i++) {
res_m.invert(p1_m);
res_m.invert(p2_m);
}
@@ -291,7 +292,35 @@ public class TestMatrix4f03InversionNOUI extends JunitTracer { res_m.invert(p1_m);
res_m.invert(p2_m);
}
- tI4b = Platform.currentTimeMillis() - t_0;
+ tI4a = Platform.currentTimeMillis() - t_0;
+
+ if( false ) {
+ // warm-up
+ for(int i=0; i<warmups; i++) {
+ res_m.load(p1_m).invert();
+ res_m.load(p2_m).invert();
+ }
+ t_0 = Platform.currentTimeMillis();
+ for(int i=0; i<loops; i++) {
+ res_m.load(p1_m).invert();
+ res_m.load(p2_m).invert();
+ }
+ tI4b = Platform.currentTimeMillis() - t_0;
+ } else {
+ res_m.load(p1_m);
+
+ // warm-up
+ for(int i=0; i<warmups; i++) {
+ res_m.invert();
+ res_m.invert();
+ }
+ t_0 = Platform.currentTimeMillis();
+ for(int i=0; i<loops; i++) {
+ res_m.invert();
+ res_m.invert();
+ }
+ tI4b = Platform.currentTimeMillis() - t_0;
+ }
//
// Matrix4fb
@@ -299,18 +328,6 @@ public class TestMatrix4f03InversionNOUI extends JunitTracer { // warm-up
for(int i=0; i<warmups; i++) {
- res_n.load(p1_n).invert();
- res_n.load(p2_n).invert();
- }
- t_0 = Platform.currentTimeMillis();
- for(int i=0; i<loops; i++) {
- res_n.load(p1_n).invert();
- res_n.load(p2_n).invert();
- }
- tI5a = Platform.currentTimeMillis() - t_0;
-
- // warm-up
- for(int i=0; i<warmups; i++) {
res_n.invert(p1_n);
res_n.invert(p2_n);
}
@@ -319,7 +336,35 @@ public class TestMatrix4f03InversionNOUI extends JunitTracer { res_n.invert(p1_n);
res_n.invert(p2_n);
}
- tI5b = Platform.currentTimeMillis() - t_0;
+ tI5a = Platform.currentTimeMillis() - t_0;
+
+ if( false ) {
+ // warm-up
+ for(int i=0; i<warmups; i++) {
+ res_n.load(p1_n).invert();
+ res_n.load(p2_n).invert();
+ }
+ t_0 = Platform.currentTimeMillis();
+ for(int i=0; i<loops; i++) {
+ res_n.load(p1_n).invert();
+ res_n.load(p2_n).invert();
+ }
+ tI5b = Platform.currentTimeMillis() - t_0;
+ } else {
+ res_n.load(p1_n);
+
+ // warm-up
+ for(int i=0; i<warmups; i++) {
+ res_n.invert();
+ res_n.invert();
+ }
+ t_0 = Platform.currentTimeMillis();
+ for(int i=0; i<loops; i++) {
+ res_n.invert();
+ res_n.invert();
+ }
+ tI5b = Platform.currentTimeMillis() - t_0;
+ }
System.err.printf("Summary loops %6d: I0 %6d ms total, %f us/inv%n", loops, tI0, tI0*1e3/loops);
System.err.printf("Summary loops %6d: I1 %6d ms total, %f us/inv, I1 / I0 %f%%%n", loops, tI1, tI1*1e3/2.0/loops, (double)tI1/(double)tI0*100.0);
|