From a60e3b1a894c53abe7ab3a19f1f30cfa96886464 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 9 Jun 2013 06:07:15 +0200 Subject: Unit Tests: Group *math* tests in own test package --- .../acore/TestFloatUtil01MatrixMatrixMultNOUI.java | 113 ----- .../test/junit/jogl/acore/TestPMVMatrix01NEWT.java | 466 --------------------- .../test/junit/jogl/acore/TestPMVMatrix02NEWT.java | 109 ----- .../junit/jogl/glu/TestGluUnprojectDoubleNOUI.java | 57 --- .../junit/jogl/glu/TestGluUnprojectFloatNOUI.java | 103 ----- .../math/TestFloatUtil01MatrixMatrixMultNOUI.java | 113 +++++ .../jogl/math/TestGluUnprojectDoubleNOUI.java | 57 +++ .../junit/jogl/math/TestGluUnprojectFloatNOUI.java | 103 +++++ .../test/junit/jogl/math/TestPMVMatrix01NEWT.java | 466 +++++++++++++++++++++ .../test/junit/jogl/math/TestPMVMatrix02NOUI.java | 109 +++++ 10 files changed, 848 insertions(+), 848 deletions(-) delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFloatUtil01MatrixMatrixMultNOUI.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPMVMatrix01NEWT.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPMVMatrix02NEWT.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectDoubleNOUI.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectFloatNOUI.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/math/TestFloatUtil01MatrixMatrixMultNOUI.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/math/TestGluUnprojectDoubleNOUI.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/math/TestGluUnprojectFloatNOUI.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/math/TestPMVMatrix01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/math/TestPMVMatrix02NOUI.java (limited to 'src') diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFloatUtil01MatrixMatrixMultNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFloatUtil01MatrixMatrixMultNOUI.java deleted file mode 100644 index adeb700d7..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFloatUtil01MatrixMatrixMultNOUI.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * Copyright 2012 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.opengl.test.junit.jogl.acore; - -import org.junit.Assert; -import org.junit.Test; - -import com.jogamp.opengl.math.FloatUtil; - -public class TestFloatUtil01MatrixMatrixMultNOUI { - - final float[] m1 = new float[]{ 1, 3, 4, 0, - 6, 7, 8, 5, - 98, 7, 6, 9, - 54, 3, 2, 5 }; - - final float[] m2 = new float[]{ 1, 6, 98, 54, - 3, 7, 7, 3, - 4, 8, 6, 2, - 0, 5, 9, 5 }; - - final float[] m1xm2_RM = // m2xm1_CM - new float[]{ 26, 59, 143, 71, - 59, 174, 730, 386, - 143, 730, 9770, 5370, - 71, 386, 5370, 2954 }; - - final float[] m2xm1_RM = // m1xm2_CM - new float[]{12557, 893, 748, 1182, - 893, 116, 116, 113, - 748, 116, 120, 104, - 1182, 113, 104, 131 }; - - public static final void multMatrixf_RM(final float[] a, int a_off, final float[] b, int b_off, float[] d, int d_off) { - for (int i = 0; i < 4; i++) { - final float ai0=a[a_off+i*4+0], ai1=a[a_off+i*4+1], ai2=a[a_off+i*4+2], ai3=a[a_off+i*4+3]; - d[d_off+i*4+0] = ai0 * b[b_off+0*4+0] + ai1 * b[b_off+1*4+0] + ai2 * b[b_off+2*4+0] + ai3 * b[b_off+3*4+0] ; - d[d_off+i*4+1] = ai0 * b[b_off+0*4+1] + ai1 * b[b_off+1*4+1] + ai2 * b[b_off+2*4+1] + ai3 * b[b_off+3*4+1] ; - d[d_off+i*4+2] = ai0 * b[b_off+0*4+2] + ai1 * b[b_off+1*4+2] + ai2 * b[b_off+2*4+2] + ai3 * b[b_off+3*4+2] ; - d[d_off+i*4+3] = ai0 * b[b_off+0*4+3] + ai1 * b[b_off+1*4+3] + ai2 * b[b_off+2*4+3] + ai3 * b[b_off+3*4+3] ; - } - } - - @Test - public void testCM_m1xm2(){ - - float[] r = new float[16]; - - FloatUtil.multMatrixf(m1, 0, m2, 0, r, 0); - - Assert.assertArrayEquals(m2xm1_RM, r, 0f); - } - - @Test - public void testCM_m2xm1(){ - - float[] r = new float[16]; - - FloatUtil.multMatrixf(m2, 0, m1, 0, r, 0); - - Assert.assertArrayEquals(m1xm2_RM, r, 0f); - } - - @Test - public void testRM_m1xm2(){ - - float[] r = new float[16]; - - multMatrixf_RM(m1, 0, m2, 0, r, 0); - - Assert.assertArrayEquals(m1xm2_RM, r, 0f); - } - - @Test - public void testRM_m2xm1(){ - - float[] r = new float[16]; - - multMatrixf_RM(m2, 0, m1, 0, r, 0); - - Assert.assertArrayEquals(m2xm1_RM, r, 0f); - } - - public static void main(String args[]) { - org.junit.runner.JUnitCore.main(TestFloatUtil01MatrixMatrixMultNOUI.class.getName()); - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPMVMatrix01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPMVMatrix01NEWT.java deleted file mode 100644 index c99bac9a4..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPMVMatrix01NEWT.java +++ /dev/null @@ -1,466 +0,0 @@ -/** - * Copyright 2012 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.opengl.test.junit.jogl.acore; - -import java.nio.FloatBuffer; - -import javax.media.opengl.GL2ES1; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLContext; -import javax.media.opengl.GLDrawable; -import javax.media.opengl.GLDrawableFactory; -import javax.media.opengl.GLProfile; -import javax.media.opengl.fixedfunc.GLMatrixFunc; - -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.jogamp.common.os.Platform; -import com.jogamp.opengl.math.FloatUtil; -import com.jogamp.opengl.math.geom.Frustum; -import com.jogamp.opengl.test.junit.util.MiscUtils; -import com.jogamp.opengl.test.junit.util.UITestCase; -import com.jogamp.opengl.util.PMVMatrix; - -public class TestPMVMatrix01NEWT extends UITestCase { - - static final float epsilon = 0.00001f; - - // matrix 2 rows x 3 columns - In row major order - static FloatBuffer matrix2x3R = FloatBuffer.wrap( new float[] { 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f } ); - - // matrix 2 rows x 3 columns - In column major order - static FloatBuffer matrix2x3C = FloatBuffer.wrap( new float[] { 1.0f, 4.0f, - 2.0f, 5.0f, - 3.0f, 6.0f } ); - - // matrix 3 rows x 2 columns - In row major order - static FloatBuffer matrix3x2R = FloatBuffer.wrap( new float[] { 1.0f, 2.0f, - 3.0f, 4.0f, - 5.0f, 6.0f } ); - - // matrix 3 rows x 2 columns - In column major order - static FloatBuffer matrix3x2C = FloatBuffer.wrap( new float[] { 1.0f, 3.0f, 5.0f, - 2.0f, 4.0f, 6.0f } ); - - // Translated xyz 123 - Row - In row major order ! - static FloatBuffer translated123R = FloatBuffer.wrap( new float[] { 1.0f, 0.0f, 0.0f, 1.0f, - 0.0f, 1.0f, 0.0f, 2.0f, - 0.0f, 0.0f, 1.0f, 3.0f, - 0.0f, 0.0f, 0.0f, 1.0f } ); - - // Translated xyz 123 - Column - In column major order ! - static FloatBuffer translated123C = FloatBuffer.wrap( new float[] { 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 1.0f, 2.0f, 3.0f, 1.0f } ); - - // Translated xyz 123 - Inverse - In column major order ! - static FloatBuffer translated123I = FloatBuffer.wrap( new float[] { 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - -1.0f, -2.0f, -3.0f, 1.0f } ); - - // Translated xyz 123 - Inverse and Transposed - In column major order ! - static FloatBuffer translated123IT = FloatBuffer.wrap( new float[] { 1.0f, 0.0f, 0.0f, -1.0f, - 0.0f, 1.0f, 0.0f, -2.0f, - 0.0f, 0.0f, 1.0f, -3.0f, - 0.0f, 0.0f, 0.0f, 1.0f } ); - - @Test - public void test00MatrixToString() { - final String s4x4Cpmv = PMVMatrix.matrixToString(null, "%10.5f", translated123C).toString(); - final String s4x4Cflu = FloatUtil.matrixToString(null, null, "%10.5f", translated123C, 0, 4, 4, false).toString(); - final String s4x4Rflu = FloatUtil.matrixToString(null, null, "%10.5f", translated123R, 0, 4, 4, true).toString(); - System.err.println("PMV-C-O 4x4: "); - System.err.println(s4x4Cpmv); - System.err.println(); - System.err.println("FLU-C-O 4x4: "); - System.err.println(s4x4Cflu); - System.err.println(); - System.err.println("FLU-R-O 4x4: "); - System.err.println(s4x4Rflu); - System.err.println(); - Assert.assertEquals(s4x4Cpmv, s4x4Cflu); - Assert.assertEquals(s4x4Cflu, s4x4Rflu); - - final String s2x3Rflu = FloatUtil.matrixToString(null, null, "%10.5f", matrix2x3R, 0, 2, 3, true).toString(); - final String s2x3Cflu = FloatUtil.matrixToString(null, null, "%10.5f", matrix2x3C, 0, 2, 3, false).toString(); - System.err.println("FLU-R-O 2x3: "); - System.err.println(s2x3Rflu); - System.err.println(); - System.err.println("FLU-C-O 2x3: "); - System.err.println(s2x3Cflu); - System.err.println(); - Assert.assertEquals(s2x3Cflu, s2x3Rflu); - - final String s3x2Rflu = FloatUtil.matrixToString(null, null, "%10.5f", matrix3x2R, 0, 3, 2, true).toString(); - final String s3x2Cflu = FloatUtil.matrixToString(null, null, "%10.5f", matrix3x2C, 0, 3, 2, false).toString(); - System.err.println("FLU-R-O 3x2: "); - System.err.println(s3x2Rflu); - System.err.println(); - System.err.println("FLU-C-O 3x2: "); - System.err.println(s3x2Cflu); - System.err.println(); - Assert.assertEquals(s3x2Cflu, s3x2Rflu); - } - - /** - * Test using traditional access workflow, i.e. 1) operation 2) get-matrix references - *

- * The Mvi, Mvit and Frustum dirty-bits and request-mask will be validated. - *

- */ - @SuppressWarnings("deprecation") - @Test - public void test01MviUpdateTraditionalAccess() { - FloatBuffer p, mv, mvi, mvit; - Frustum frustum; - boolean b; - final PMVMatrix pmv = new PMVMatrix(true); - // System.err.println("P0: "+pmv.toString()); - - Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); - Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); - Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); - - // - // Action #0 - // - final FloatBuffer ident; - { - pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - pmv.glLoadIdentity(); - ident = pmv.glGetPMatrixf(); - - pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - pmv.glLoadIdentity(); - } - Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test - Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); - Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); - Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); - - // - // Action #1 - // - pmv.glTranslatef(1f, 2f, 3f); // all dirty ! - Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test - Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); - Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); - Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); - // System.err.println("P1: "+pmv.toString()); - - b = pmv.update(); // will not clean dirty bits, since no request has been made -> false - Assert.assertEquals("Update has been perfomed, but non requested", false, b); - Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); - Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); - Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); - // System.err.println("P2: "+pmv.toString()); - - // - // Get - // - p = pmv.glGetPMatrixf(); - MiscUtils.assertFloatBufferEquals("P not identity, "+pmv.toString(), ident, p, epsilon); - mv = pmv.glGetMvMatrixf(); - MiscUtils.assertFloatBufferEquals("Mv not translated123, "+pmv.toString(), translated123C, mv, epsilon); - mvi = pmv.glGetMviMatrixf(); - MiscUtils.assertFloatBufferEquals("Mvi not translated123, "+pmv.toString(), translated123I, mvi, epsilon); - Assert.assertEquals("Request bit Mvi not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW, pmv.getRequestMask()); - Assert.assertEquals("Remaining dirty bits not Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); - - frustum = pmv.glGetFrustum(); - Assert.assertNotNull("Frustum is null"+pmv.toString(), frustum); // FIXME: Test Frustum value! - Assert.assertEquals("Remaining dirty bits not Mvit, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW, pmv.getDirtyBits()); - Assert.assertEquals("Request bits Mvi|Frustum not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getRequestMask()); - // System.err.println("P3: "+pmv.toString()); - - mvit = pmv.glGetMvitMatrixf(); - MiscUtils.assertFloatBufferEquals("Mvit not translated123, "+pmv.toString()+pmv.toString(), translated123IT, mvit, epsilon); - Assert.assertTrue("Dirty bits not clean, "+pmv.toString(), 0 == pmv.getDirtyBits()); - Assert.assertEquals("Request bits Mvi|Mvit|Frustum not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getRequestMask()); - // System.err.println("P4: "+pmv.toString()); - - // - // Action #2 - // - pmv.glLoadIdentity(); // all dirty - Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test - Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); - Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); - Assert.assertEquals("Request bits Mvi|Mvit|Frustum not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getRequestMask()); - MiscUtils.assertFloatBufferEquals("P not identity, "+pmv.toString(), ident, p, epsilon); - MiscUtils.assertFloatBufferEquals("Mv not identity, "+pmv.toString(), ident, mv, epsilon); - MiscUtils.assertFloatBufferNotEqual("Mvi already identity w/o update, "+pmv.toString(), ident, mvi, epsilon); - MiscUtils.assertFloatBufferNotEqual("Mvit already identity w/o update, "+pmv.toString(), ident, mvit, epsilon); - MiscUtils.assertFloatBufferEquals("Mvi not translated123, "+pmv.toString()+pmv.toString(), translated123I, mvi, epsilon); - MiscUtils.assertFloatBufferEquals("Mvit not translated123, "+pmv.toString()+pmv.toString(), translated123IT, mvit, epsilon); - Assert.assertNotNull("Frustum is null"+pmv.toString(), frustum); // FIXME: Test Frustum value! - - b = pmv.update(); // will clean dirty bits, since request has been made -> true - Assert.assertEquals("Update has not been perfomed, but requested", true, b); - Assert.assertTrue("Dirty bits not clean, "+pmv.toString(), 0 == pmv.getDirtyBits()); - Assert.assertEquals("Request bits Mvi|Mvit|Frustum not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getRequestMask()); - MiscUtils.assertFloatBufferEquals("Mvi not identity after update, "+pmv.toString(), ident, mvi, epsilon); - MiscUtils.assertFloatBufferEquals("Mvit not identity after update, "+pmv.toString(), ident, mvit, epsilon); - Assert.assertNotNull("Frustum is null"+pmv.toString(), frustum); // FIXME: Test Frustum value! - } - - /** - * Test using shader access workflow, i.e. 1) get-matrix references 2) operations - *

- * The Mvi, Mvit and Frustum dirty-bits and request-mask will be validated. - *

- */ - @SuppressWarnings("deprecation") - @Test - public void test02MviUpdateShaderAccess() { - final FloatBuffer p, mv, mvi, mvit; - Frustum frustum; - boolean b; - final PMVMatrix pmv = new PMVMatrix(true); - // System.err.println("P0: "+pmv.toString()); - - Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); - Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); - Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); - - // - // Action #0 - // - final FloatBuffer ident; - { - pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - pmv.glLoadIdentity(); - ident = pmv.glGetPMatrixf(); - - pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - pmv.glLoadIdentity(); - } - // System.err.println("P0: "+pmv.toString()); - Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test - Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); - Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); - Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); - // System.err.println("P1: "+pmv.toString()); - - // - // Get - // - p = pmv.glGetPMatrixf(); - MiscUtils.assertFloatBufferEquals("P not identity, "+pmv.toString(), ident, p, epsilon); - mv = pmv.glGetMvMatrixf(); - MiscUtils.assertFloatBufferEquals("Mv not identity, "+pmv.toString(), ident, mv, epsilon); - Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); - Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); - - mvi = pmv.glGetMviMatrixf(); - MiscUtils.assertFloatBufferEquals("Mvi not identity, "+pmv.toString(), ident, mvi, epsilon); - Assert.assertEquals("Remaining dirty bits not Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); - Assert.assertEquals("Request bit Mvi not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW, pmv.getRequestMask()); - - mvit = pmv.glGetMvitMatrixf(); - MiscUtils.assertFloatBufferEquals("Mvi not identity, "+pmv.toString(), ident, mvit, epsilon); - Assert.assertEquals("Remaining dirty bits not Frustum, "+pmv.toString(), PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); - Assert.assertEquals("Request bits Mvi and Mvit not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW, pmv.getRequestMask()); - - frustum = pmv.glGetFrustum(); - Assert.assertNotNull("Frustum is null"+pmv.toString(), frustum); // FIXME: Test Frustum value! - Assert.assertTrue("Dirty bits not clean, "+pmv.toString(), 0 == pmv.getDirtyBits()); - Assert.assertEquals("Request bits Mvi|Mvit|Frustum not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getRequestMask()); - - // - // Action #1 - // - pmv.glTranslatef(1f, 2f, 3f); // all dirty ! - Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test - Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); - Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); - MiscUtils.assertFloatBufferEquals("P not identity, "+pmv.toString()+pmv.toString(), ident, p, epsilon); - MiscUtils.assertFloatBufferEquals("Mv not translated123, "+pmv.toString()+pmv.toString(), translated123C, mv, epsilon); - MiscUtils.assertFloatBufferNotEqual("Mvi already translated123 w/o update, "+pmv.toString()+pmv.toString(), translated123I, mvi, epsilon); - MiscUtils.assertFloatBufferNotEqual("Mvit already translated123 w/o update, "+pmv.toString()+pmv.toString(), translated123IT, mvit, epsilon); - MiscUtils.assertFloatBufferEquals("Mvi not identity, "+pmv.toString()+pmv.toString(), ident, mvi, epsilon); - MiscUtils.assertFloatBufferEquals("Mvit not identity, "+pmv.toString()+pmv.toString(), ident, mvit, epsilon); - Assert.assertNotNull("Frustum is null"+pmv.toString(), frustum); // FIXME: Test Frustum value! - - b = pmv.update(); // will clean dirty bits, since all requests has been made -> true - Assert.assertEquals("Update has not been perfomed, but requested", true, b); - Assert.assertTrue("Dirty bits not clean, "+pmv.toString(), 0 == pmv.getDirtyBits()); - Assert.assertEquals("Request bits Mvi|Mvit|Frustum not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getRequestMask()); - MiscUtils.assertFloatBufferEquals("Mvi not translated123, "+pmv.toString()+pmv.toString(), translated123I, mvi, epsilon); - MiscUtils.assertFloatBufferEquals("Mvit not translated123, "+pmv.toString()+pmv.toString(), translated123IT, mvit, epsilon); - // System.err.println("P2: "+pmv.toString()); - } - - @SuppressWarnings("unused") - @Test - public void test03MvTranslate() { - final FloatBuffer pmvMv, pmvMvi, pmvMvit; - { - final PMVMatrix pmv = new PMVMatrix(true); - pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - pmv.glLoadIdentity(); - pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - pmv.glLoadIdentity(); - pmv.glTranslatef(5f, 6f, 7f); - - pmvMv = pmv.glGetMvMatrixf(); - pmvMvi = pmv.glGetMviMatrixf(); - pmvMvit = pmv.glGetMvitMatrixf(); - } - - final FloatBuffer glMv = FloatBuffer.allocate(16); - { - GL2ES1 gl = dc.glc.getGL().getGL2ES1(); - gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - gl.glLoadIdentity(); - gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - gl.glLoadIdentity(); - gl.glTranslatef(5f, 6f, 7f); - - gl.glGetFloatv(GLMatrixFunc.GL_MODELVIEW_MATRIX, glMv); - } - // System.err.println(PMVMatrix.matrixToString(null, "%10.5f", glMv, pmvMv).toString()); - - MiscUtils.assertFloatBufferEquals("Arrays not equal, expected"+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", glMv).toString()+ - ", actual"+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMv).toString(), - glMv, pmvMv, epsilon); - - // System.err.println("pmvMvi: "+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMvi)); - // System.err.println("pmvMvit: "+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMvit)); - } - - @SuppressWarnings("unused") - @Test - public void test04MvTranslateRotate() { - final FloatBuffer pmvMv, pmvMvi, pmvMvit; - { - final PMVMatrix pmv = new PMVMatrix(true); - pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - pmv.glLoadIdentity(); - pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - pmv.glLoadIdentity(); - pmv.glTranslatef(5f, 6f, 7f); - pmv.glRotatef(90f, 1f, 0f, 0f); - - pmvMv = pmv.glGetMvMatrixf(); - pmvMvi = pmv.glGetMviMatrixf(); - pmvMvit = pmv.glGetMvitMatrixf(); - } - - final FloatBuffer glMv = FloatBuffer.allocate(16); - { - GL2ES1 gl = dc.glc.getGL().getGL2ES1(); - gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - gl.glLoadIdentity(); - gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - gl.glLoadIdentity(); - gl.glTranslatef(5f, 6f, 7f); - gl.glRotatef(90f, 1f, 0f, 0f); - - gl.glGetFloatv(GLMatrixFunc.GL_MODELVIEW_MATRIX, glMv); - } - // System.err.println(PMVMatrix.matrixToString(null, "%10.5f", glMv, pmvMv).toString()); - - MiscUtils.assertFloatBufferEquals("Arrays not equal, expected"+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", glMv).toString()+ - ", actual"+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMv).toString(), - glMv, pmvMv, epsilon); - - // System.err.println("pmvMvi: "+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMvi)); - // System.err.println("pmvMvit: "+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMvit)); - } - - static DrawableContext dc; - - @BeforeClass - public static void setup() throws Throwable { - try { - dc = createOffscreenDrawableAndCurrentFFPContext(); - } catch (Throwable t) { - setTestSupported(false); - throw t; - } - } - - @AfterClass - public static void cleanup() { - destroyDrawableContext(dc); - } - - static class DrawableContext { - DrawableContext(GLDrawable d, GLContext glc) { - this.d = d; - this.glc = glc; - } - GLDrawable d; - GLContext glc; - } - - private static DrawableContext createOffscreenDrawableAndCurrentFFPContext() throws Throwable { - GLProfile glp = GLProfile.getMaxFixedFunc(true); - GLCapabilities glCaps = new GLCapabilities(glp); - glCaps.setOnscreen(false); - glCaps.setPBuffer(true); - GLDrawableFactory factory = GLDrawableFactory.getFactory(glp); - GLDrawable d = factory.createOffscreenDrawable(null, glCaps, null, 64, 64); - d.setRealized(true); - GLContext glc = null; - try { - glc = d.createContext(null); - Assert.assertTrue("Context could not be made current", GLContext.CONTEXT_NOT_CURRENT < glc.makeCurrent()); - return new DrawableContext(d, glc); - } catch (Throwable t) { - if(null != glc) { - glc.destroy(); - } - d.setRealized(false); - throw t; - } - } - - private static void destroyDrawableContext(DrawableContext dc) { - if(null != dc.glc) { - dc.glc.destroy(); - dc.glc = null; - } - if(null != dc.d) { - dc.d.setRealized(false); - dc.d = null; - } - } - - public static void main(String args[]) { - org.junit.runner.JUnitCore.main(TestPMVMatrix01NEWT.class.getName()); - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPMVMatrix02NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPMVMatrix02NEWT.java deleted file mode 100644 index 4e959d460..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPMVMatrix02NEWT.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * Copyright 2012 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.opengl.test.junit.jogl.acore; - -import org.junit.Before; -import org.junit.Test; - -import com.jogamp.opengl.util.PMVMatrix; - -import javax.media.opengl.fixedfunc.GLMatrixFunc; -import java.nio.FloatBuffer; - -import static org.junit.Assert.assertArrayEquals; - -/** - * @author Thomas De Bodt - */ -public class TestPMVMatrix02NEWT { - - private PMVMatrix fMat; - - @Before - public void setUp() throws Exception { - fMat = new PMVMatrix(); - } - - @Test - public void testLookAtNegZIsNoOp() throws Exception { - fMat.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - // Look towards -z - fMat.gluLookAt( - 0, 0, 0, - 0, 0, -1, - 0, 1, 0 - ); - FloatBuffer mvMatrix = fMat.glGetMvMatrixf(); - float[] mvMatrixArr = new float[16]; - mvMatrix.asReadOnlyBuffer().get(mvMatrixArr); - assertArrayEquals( - /** - * The 3 rows of the matrix (= the 3 columns of the array/buffer) should be: side, up, -forward. - */ - new float[] { - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - }, - mvMatrixArr, - 1e-6f - ); - } - @Test - public void testLookAtPosY() throws Exception { - fMat.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - // Look towards +y - fMat.gluLookAt( - 0, 0, 0, - 0, 1, 0, - 0, 0, 1 - ); - FloatBuffer mvMatrix = fMat.glGetMvMatrixf(); - float[] mvMatrixArr = new float[16]; - mvMatrix.asReadOnlyBuffer().get(mvMatrixArr); - assertArrayEquals( - /** - * The 3 rows of the matrix (= the 3 columns of the array/buffer) should be: side, up, -forward. - */ - new float[] { - 1, 0, 0, 0, - 0, 0, -1, 0, - 0, 1, 0, 0, - 0, 0, 0, 1 - }, - mvMatrixArr, - 1e-6f - ); - } - - public static void main(String args[]) { - org.junit.runner.JUnitCore.main(TestPMVMatrix02NEWT.class.getName()); - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectDoubleNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectDoubleNOUI.java deleted file mode 100644 index 34b30f04e..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectDoubleNOUI.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.opengl.test.junit.jogl.glu; - -import javax.media.opengl.glu.GLU; - -import org.junit.Assert; -import org.junit.Test; - -/** - * @author Julien Gouesse - */ -public class TestGluUnprojectDoubleNOUI { - - @Test - public void test(){ - final GLU glu = new GLU(); - final int[] pickedPoint = new int[]{400,300}; - final double pickedPointDepth = 0; - final double[] sceneModelViewValues = new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; - final double[] projectionValues = new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; - final int[] viewport = new int[]{0,0,800,600}; - final double[] objCoords = new double[]{Double.NaN,Double.NaN,Double.NaN}; - glu.gluUnProject(pickedPoint[0], pickedPoint[1], pickedPointDepth, sceneModelViewValues, 0, projectionValues, 0, viewport, 0, objCoords, 0); - Assert.assertTrue(!Double.isNaN(objCoords[0])&&!Double.isNaN(objCoords[1])&&!Double.isNaN(objCoords[2])); - } - - public static void main(String args[]) { - org.junit.runner.JUnitCore.main(TestGluUnprojectDoubleNOUI.class.getName()); - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectFloatNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectFloatNOUI.java deleted file mode 100644 index 717d5e4b8..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectFloatNOUI.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package com.jogamp.opengl.test.junit.jogl.glu; - -import javax.media.opengl.glu.GLU; - -import org.junit.Assert; -import org.junit.Test; - -public class TestGluUnprojectFloatNOUI { - - @Test - public void testNaN(){ - final GLU glu = new GLU(); - final int[] pickedPoint = new int[]{400,300}; - final float pickedPointDepth = 0; - final float[] sceneModelViewValues = new float[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; - final float[] projectionValues = new float[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; - final int[] viewport = new int[]{0,0,800,600}; - final float[] objCoords = new float[]{Float.NaN,Float.NaN,Float.NaN}; - glu.gluUnProject(pickedPoint[0], pickedPoint[1], pickedPointDepth, sceneModelViewValues, 0, projectionValues, 0, viewport, 0, objCoords, 0); - Assert.assertTrue(!Double.isNaN(objCoords[0])&&!Double.isNaN(objCoords[1])&&!Double.isNaN(objCoords[2])); - } - - @Test - public void test01(){ - float[] mv = new float[] { 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 }; - - float[] p = new float[] { 2.3464675f, 0, 0, 0, - 0, 2.4142134f, 0, 0, - 0, 0, -1.0002f, -1, - 0, 0, -20.002f, 0 }; - - int[] v = new int[] { 0, 0, 1000, 1000 }; - - float[] s = new float[] { 250, 250, 0.5f }; - - float[] expected = new float[] { -4.2612f, -4.1417f, -19.9980f }; - float[] result = new float[] { 0, 0, 0 }; - - final GLU glu = new GLU(); - glu.gluUnProject(s[0], s[1], s[2], mv, 0, p, 0, v, 0, result, 0); - - Assert.assertArrayEquals(expected, result, 0.0001f); - } - - @Test - public void test02(){ - float[] mv = new float[] { 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, -200, 1 } ; - - float[] p = new float[] { 2.3464675f, 0, 0, 0, - 0, 2.4142134f, 0, 0, - 0, 0, -1.0002f, -1, - 0, 0, -20.002f, 0 }; - - int[] v = new int[] { 0, 0, 1000, 1000 }; - - float[] s = new float[] { 250, 250, 0.5f }; - float[] expected = new float[] { -4.2612f, -4.1417f, 180.002f }; - float[] result = new float[] { 0, 0, 0 }; - - final GLU glu = new GLU(); - glu.gluUnProject(s[0], s[1], s[2], mv, 0, p, 0, v, 0, result, 0); - - Assert.assertArrayEquals(expected, result, 0.0001f); - } - - public static void main(String args[]) { - org.junit.runner.JUnitCore.main(TestGluUnprojectFloatNOUI.class.getName()); - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestFloatUtil01MatrixMatrixMultNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestFloatUtil01MatrixMatrixMultNOUI.java new file mode 100644 index 000000000..83a1be456 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestFloatUtil01MatrixMatrixMultNOUI.java @@ -0,0 +1,113 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.math; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.opengl.math.FloatUtil; + +public class TestFloatUtil01MatrixMatrixMultNOUI { + + final float[] m1 = new float[]{ 1, 3, 4, 0, + 6, 7, 8, 5, + 98, 7, 6, 9, + 54, 3, 2, 5 }; + + final float[] m2 = new float[]{ 1, 6, 98, 54, + 3, 7, 7, 3, + 4, 8, 6, 2, + 0, 5, 9, 5 }; + + final float[] m1xm2_RM = // m2xm1_CM + new float[]{ 26, 59, 143, 71, + 59, 174, 730, 386, + 143, 730, 9770, 5370, + 71, 386, 5370, 2954 }; + + final float[] m2xm1_RM = // m1xm2_CM + new float[]{12557, 893, 748, 1182, + 893, 116, 116, 113, + 748, 116, 120, 104, + 1182, 113, 104, 131 }; + + public static final void multMatrixf_RM(final float[] a, int a_off, final float[] b, int b_off, float[] d, int d_off) { + for (int i = 0; i < 4; i++) { + final float ai0=a[a_off+i*4+0], ai1=a[a_off+i*4+1], ai2=a[a_off+i*4+2], ai3=a[a_off+i*4+3]; + d[d_off+i*4+0] = ai0 * b[b_off+0*4+0] + ai1 * b[b_off+1*4+0] + ai2 * b[b_off+2*4+0] + ai3 * b[b_off+3*4+0] ; + d[d_off+i*4+1] = ai0 * b[b_off+0*4+1] + ai1 * b[b_off+1*4+1] + ai2 * b[b_off+2*4+1] + ai3 * b[b_off+3*4+1] ; + d[d_off+i*4+2] = ai0 * b[b_off+0*4+2] + ai1 * b[b_off+1*4+2] + ai2 * b[b_off+2*4+2] + ai3 * b[b_off+3*4+2] ; + d[d_off+i*4+3] = ai0 * b[b_off+0*4+3] + ai1 * b[b_off+1*4+3] + ai2 * b[b_off+2*4+3] + ai3 * b[b_off+3*4+3] ; + } + } + + @Test + public void testCM_m1xm2(){ + + float[] r = new float[16]; + + FloatUtil.multMatrixf(m1, 0, m2, 0, r, 0); + + Assert.assertArrayEquals(m2xm1_RM, r, 0f); + } + + @Test + public void testCM_m2xm1(){ + + float[] r = new float[16]; + + FloatUtil.multMatrixf(m2, 0, m1, 0, r, 0); + + Assert.assertArrayEquals(m1xm2_RM, r, 0f); + } + + @Test + public void testRM_m1xm2(){ + + float[] r = new float[16]; + + multMatrixf_RM(m1, 0, m2, 0, r, 0); + + Assert.assertArrayEquals(m1xm2_RM, r, 0f); + } + + @Test + public void testRM_m2xm1(){ + + float[] r = new float[16]; + + multMatrixf_RM(m2, 0, m1, 0, r, 0); + + Assert.assertArrayEquals(m2xm1_RM, r, 0f); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestFloatUtil01MatrixMatrixMultNOUI.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestGluUnprojectDoubleNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestGluUnprojectDoubleNOUI.java new file mode 100644 index 000000000..32861f764 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestGluUnprojectDoubleNOUI.java @@ -0,0 +1,57 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.math; + +import javax.media.opengl.glu.GLU; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Julien Gouesse + */ +public class TestGluUnprojectDoubleNOUI { + + @Test + public void test(){ + final GLU glu = new GLU(); + final int[] pickedPoint = new int[]{400,300}; + final double pickedPointDepth = 0; + final double[] sceneModelViewValues = new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + final double[] projectionValues = new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + final int[] viewport = new int[]{0,0,800,600}; + final double[] objCoords = new double[]{Double.NaN,Double.NaN,Double.NaN}; + glu.gluUnProject(pickedPoint[0], pickedPoint[1], pickedPointDepth, sceneModelViewValues, 0, projectionValues, 0, viewport, 0, objCoords, 0); + Assert.assertTrue(!Double.isNaN(objCoords[0])&&!Double.isNaN(objCoords[1])&&!Double.isNaN(objCoords[2])); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestGluUnprojectDoubleNOUI.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestGluUnprojectFloatNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestGluUnprojectFloatNOUI.java new file mode 100644 index 000000000..9951500fc --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestGluUnprojectFloatNOUI.java @@ -0,0 +1,103 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.math; + +import javax.media.opengl.glu.GLU; + +import org.junit.Assert; +import org.junit.Test; + +public class TestGluUnprojectFloatNOUI { + + @Test + public void testNaN(){ + final GLU glu = new GLU(); + final int[] pickedPoint = new int[]{400,300}; + final float pickedPointDepth = 0; + final float[] sceneModelViewValues = new float[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + final float[] projectionValues = new float[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + final int[] viewport = new int[]{0,0,800,600}; + final float[] objCoords = new float[]{Float.NaN,Float.NaN,Float.NaN}; + glu.gluUnProject(pickedPoint[0], pickedPoint[1], pickedPointDepth, sceneModelViewValues, 0, projectionValues, 0, viewport, 0, objCoords, 0); + Assert.assertTrue(!Double.isNaN(objCoords[0])&&!Double.isNaN(objCoords[1])&&!Double.isNaN(objCoords[2])); + } + + @Test + public void test01(){ + float[] mv = new float[] { 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 }; + + float[] p = new float[] { 2.3464675f, 0, 0, 0, + 0, 2.4142134f, 0, 0, + 0, 0, -1.0002f, -1, + 0, 0, -20.002f, 0 }; + + int[] v = new int[] { 0, 0, 1000, 1000 }; + + float[] s = new float[] { 250, 250, 0.5f }; + + float[] expected = new float[] { -4.2612f, -4.1417f, -19.9980f }; + float[] result = new float[] { 0, 0, 0 }; + + final GLU glu = new GLU(); + glu.gluUnProject(s[0], s[1], s[2], mv, 0, p, 0, v, 0, result, 0); + + Assert.assertArrayEquals(expected, result, 0.0001f); + } + + @Test + public void test02(){ + float[] mv = new float[] { 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, -200, 1 } ; + + float[] p = new float[] { 2.3464675f, 0, 0, 0, + 0, 2.4142134f, 0, 0, + 0, 0, -1.0002f, -1, + 0, 0, -20.002f, 0 }; + + int[] v = new int[] { 0, 0, 1000, 1000 }; + + float[] s = new float[] { 250, 250, 0.5f }; + float[] expected = new float[] { -4.2612f, -4.1417f, 180.002f }; + float[] result = new float[] { 0, 0, 0 }; + + final GLU glu = new GLU(); + glu.gluUnProject(s[0], s[1], s[2], mv, 0, p, 0, v, 0, result, 0); + + Assert.assertArrayEquals(expected, result, 0.0001f); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestGluUnprojectFloatNOUI.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestPMVMatrix01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestPMVMatrix01NEWT.java new file mode 100644 index 000000000..3d9bfed7e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestPMVMatrix01NEWT.java @@ -0,0 +1,466 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.math; + +import java.nio.FloatBuffer; + +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLProfile; +import javax.media.opengl.fixedfunc.GLMatrixFunc; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.common.os.Platform; +import com.jogamp.opengl.math.FloatUtil; +import com.jogamp.opengl.math.geom.Frustum; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.PMVMatrix; + +public class TestPMVMatrix01NEWT extends UITestCase { + + static final float epsilon = 0.00001f; + + // matrix 2 rows x 3 columns - In row major order + static FloatBuffer matrix2x3R = FloatBuffer.wrap( new float[] { 1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f } ); + + // matrix 2 rows x 3 columns - In column major order + static FloatBuffer matrix2x3C = FloatBuffer.wrap( new float[] { 1.0f, 4.0f, + 2.0f, 5.0f, + 3.0f, 6.0f } ); + + // matrix 3 rows x 2 columns - In row major order + static FloatBuffer matrix3x2R = FloatBuffer.wrap( new float[] { 1.0f, 2.0f, + 3.0f, 4.0f, + 5.0f, 6.0f } ); + + // matrix 3 rows x 2 columns - In column major order + static FloatBuffer matrix3x2C = FloatBuffer.wrap( new float[] { 1.0f, 3.0f, 5.0f, + 2.0f, 4.0f, 6.0f } ); + + // Translated xyz 123 - Row - In row major order ! + static FloatBuffer translated123R = FloatBuffer.wrap( new float[] { 1.0f, 0.0f, 0.0f, 1.0f, + 0.0f, 1.0f, 0.0f, 2.0f, + 0.0f, 0.0f, 1.0f, 3.0f, + 0.0f, 0.0f, 0.0f, 1.0f } ); + + // Translated xyz 123 - Column - In column major order ! + static FloatBuffer translated123C = FloatBuffer.wrap( new float[] { 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 1.0f, 2.0f, 3.0f, 1.0f } ); + + // Translated xyz 123 - Inverse - In column major order ! + static FloatBuffer translated123I = FloatBuffer.wrap( new float[] { 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + -1.0f, -2.0f, -3.0f, 1.0f } ); + + // Translated xyz 123 - Inverse and Transposed - In column major order ! + static FloatBuffer translated123IT = FloatBuffer.wrap( new float[] { 1.0f, 0.0f, 0.0f, -1.0f, + 0.0f, 1.0f, 0.0f, -2.0f, + 0.0f, 0.0f, 1.0f, -3.0f, + 0.0f, 0.0f, 0.0f, 1.0f } ); + + @Test + public void test00MatrixToString() { + final String s4x4Cpmv = PMVMatrix.matrixToString(null, "%10.5f", translated123C).toString(); + final String s4x4Cflu = FloatUtil.matrixToString(null, null, "%10.5f", translated123C, 0, 4, 4, false).toString(); + final String s4x4Rflu = FloatUtil.matrixToString(null, null, "%10.5f", translated123R, 0, 4, 4, true).toString(); + System.err.println("PMV-C-O 4x4: "); + System.err.println(s4x4Cpmv); + System.err.println(); + System.err.println("FLU-C-O 4x4: "); + System.err.println(s4x4Cflu); + System.err.println(); + System.err.println("FLU-R-O 4x4: "); + System.err.println(s4x4Rflu); + System.err.println(); + Assert.assertEquals(s4x4Cpmv, s4x4Cflu); + Assert.assertEquals(s4x4Cflu, s4x4Rflu); + + final String s2x3Rflu = FloatUtil.matrixToString(null, null, "%10.5f", matrix2x3R, 0, 2, 3, true).toString(); + final String s2x3Cflu = FloatUtil.matrixToString(null, null, "%10.5f", matrix2x3C, 0, 2, 3, false).toString(); + System.err.println("FLU-R-O 2x3: "); + System.err.println(s2x3Rflu); + System.err.println(); + System.err.println("FLU-C-O 2x3: "); + System.err.println(s2x3Cflu); + System.err.println(); + Assert.assertEquals(s2x3Cflu, s2x3Rflu); + + final String s3x2Rflu = FloatUtil.matrixToString(null, null, "%10.5f", matrix3x2R, 0, 3, 2, true).toString(); + final String s3x2Cflu = FloatUtil.matrixToString(null, null, "%10.5f", matrix3x2C, 0, 3, 2, false).toString(); + System.err.println("FLU-R-O 3x2: "); + System.err.println(s3x2Rflu); + System.err.println(); + System.err.println("FLU-C-O 3x2: "); + System.err.println(s3x2Cflu); + System.err.println(); + Assert.assertEquals(s3x2Cflu, s3x2Rflu); + } + + /** + * Test using traditional access workflow, i.e. 1) operation 2) get-matrix references + *

+ * The Mvi, Mvit and Frustum dirty-bits and request-mask will be validated. + *

+ */ + @SuppressWarnings("deprecation") + @Test + public void test01MviUpdateTraditionalAccess() { + FloatBuffer p, mv, mvi, mvit; + Frustum frustum; + boolean b; + final PMVMatrix pmv = new PMVMatrix(true); + // System.err.println("P0: "+pmv.toString()); + + Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); + Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); + Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); + + // + // Action #0 + // + final FloatBuffer ident; + { + pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + pmv.glLoadIdentity(); + ident = pmv.glGetPMatrixf(); + + pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + pmv.glLoadIdentity(); + } + Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test + Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); + Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); + Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); + + // + // Action #1 + // + pmv.glTranslatef(1f, 2f, 3f); // all dirty ! + Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test + Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); + Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); + Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); + // System.err.println("P1: "+pmv.toString()); + + b = pmv.update(); // will not clean dirty bits, since no request has been made -> false + Assert.assertEquals("Update has been perfomed, but non requested", false, b); + Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); + Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); + Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); + // System.err.println("P2: "+pmv.toString()); + + // + // Get + // + p = pmv.glGetPMatrixf(); + MiscUtils.assertFloatBufferEquals("P not identity, "+pmv.toString(), ident, p, epsilon); + mv = pmv.glGetMvMatrixf(); + MiscUtils.assertFloatBufferEquals("Mv not translated123, "+pmv.toString(), translated123C, mv, epsilon); + mvi = pmv.glGetMviMatrixf(); + MiscUtils.assertFloatBufferEquals("Mvi not translated123, "+pmv.toString(), translated123I, mvi, epsilon); + Assert.assertEquals("Request bit Mvi not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW, pmv.getRequestMask()); + Assert.assertEquals("Remaining dirty bits not Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); + + frustum = pmv.glGetFrustum(); + Assert.assertNotNull("Frustum is null"+pmv.toString(), frustum); // FIXME: Test Frustum value! + Assert.assertEquals("Remaining dirty bits not Mvit, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW, pmv.getDirtyBits()); + Assert.assertEquals("Request bits Mvi|Frustum not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getRequestMask()); + // System.err.println("P3: "+pmv.toString()); + + mvit = pmv.glGetMvitMatrixf(); + MiscUtils.assertFloatBufferEquals("Mvit not translated123, "+pmv.toString()+pmv.toString(), translated123IT, mvit, epsilon); + Assert.assertTrue("Dirty bits not clean, "+pmv.toString(), 0 == pmv.getDirtyBits()); + Assert.assertEquals("Request bits Mvi|Mvit|Frustum not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getRequestMask()); + // System.err.println("P4: "+pmv.toString()); + + // + // Action #2 + // + pmv.glLoadIdentity(); // all dirty + Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test + Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); + Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); + Assert.assertEquals("Request bits Mvi|Mvit|Frustum not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getRequestMask()); + MiscUtils.assertFloatBufferEquals("P not identity, "+pmv.toString(), ident, p, epsilon); + MiscUtils.assertFloatBufferEquals("Mv not identity, "+pmv.toString(), ident, mv, epsilon); + MiscUtils.assertFloatBufferNotEqual("Mvi already identity w/o update, "+pmv.toString(), ident, mvi, epsilon); + MiscUtils.assertFloatBufferNotEqual("Mvit already identity w/o update, "+pmv.toString(), ident, mvit, epsilon); + MiscUtils.assertFloatBufferEquals("Mvi not translated123, "+pmv.toString()+pmv.toString(), translated123I, mvi, epsilon); + MiscUtils.assertFloatBufferEquals("Mvit not translated123, "+pmv.toString()+pmv.toString(), translated123IT, mvit, epsilon); + Assert.assertNotNull("Frustum is null"+pmv.toString(), frustum); // FIXME: Test Frustum value! + + b = pmv.update(); // will clean dirty bits, since request has been made -> true + Assert.assertEquals("Update has not been perfomed, but requested", true, b); + Assert.assertTrue("Dirty bits not clean, "+pmv.toString(), 0 == pmv.getDirtyBits()); + Assert.assertEquals("Request bits Mvi|Mvit|Frustum not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getRequestMask()); + MiscUtils.assertFloatBufferEquals("Mvi not identity after update, "+pmv.toString(), ident, mvi, epsilon); + MiscUtils.assertFloatBufferEquals("Mvit not identity after update, "+pmv.toString(), ident, mvit, epsilon); + Assert.assertNotNull("Frustum is null"+pmv.toString(), frustum); // FIXME: Test Frustum value! + } + + /** + * Test using shader access workflow, i.e. 1) get-matrix references 2) operations + *

+ * The Mvi, Mvit and Frustum dirty-bits and request-mask will be validated. + *

+ */ + @SuppressWarnings("deprecation") + @Test + public void test02MviUpdateShaderAccess() { + final FloatBuffer p, mv, mvi, mvit; + Frustum frustum; + boolean b; + final PMVMatrix pmv = new PMVMatrix(true); + // System.err.println("P0: "+pmv.toString()); + + Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); + Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); + Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); + + // + // Action #0 + // + final FloatBuffer ident; + { + pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + pmv.glLoadIdentity(); + ident = pmv.glGetPMatrixf(); + + pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + pmv.glLoadIdentity(); + } + // System.err.println("P0: "+pmv.toString()); + Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test + Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); + Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); + Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); + // System.err.println("P1: "+pmv.toString()); + + // + // Get + // + p = pmv.glGetPMatrixf(); + MiscUtils.assertFloatBufferEquals("P not identity, "+pmv.toString(), ident, p, epsilon); + mv = pmv.glGetMvMatrixf(); + MiscUtils.assertFloatBufferEquals("Mv not identity, "+pmv.toString(), ident, mv, epsilon); + Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); + Assert.assertEquals("Request bits not zero, "+pmv.toString(), 0, pmv.getRequestMask()); + + mvi = pmv.glGetMviMatrixf(); + MiscUtils.assertFloatBufferEquals("Mvi not identity, "+pmv.toString(), ident, mvi, epsilon); + Assert.assertEquals("Remaining dirty bits not Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); + Assert.assertEquals("Request bit Mvi not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW, pmv.getRequestMask()); + + mvit = pmv.glGetMvitMatrixf(); + MiscUtils.assertFloatBufferEquals("Mvi not identity, "+pmv.toString(), ident, mvit, epsilon); + Assert.assertEquals("Remaining dirty bits not Frustum, "+pmv.toString(), PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); + Assert.assertEquals("Request bits Mvi and Mvit not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW, pmv.getRequestMask()); + + frustum = pmv.glGetFrustum(); + Assert.assertNotNull("Frustum is null"+pmv.toString(), frustum); // FIXME: Test Frustum value! + Assert.assertTrue("Dirty bits not clean, "+pmv.toString(), 0 == pmv.getDirtyBits()); + Assert.assertEquals("Request bits Mvi|Mvit|Frustum not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getRequestMask()); + + // + // Action #1 + // + pmv.glTranslatef(1f, 2f, 3f); // all dirty ! + Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test + Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits()); + Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW|PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getDirtyBits()); + MiscUtils.assertFloatBufferEquals("P not identity, "+pmv.toString()+pmv.toString(), ident, p, epsilon); + MiscUtils.assertFloatBufferEquals("Mv not translated123, "+pmv.toString()+pmv.toString(), translated123C, mv, epsilon); + MiscUtils.assertFloatBufferNotEqual("Mvi already translated123 w/o update, "+pmv.toString()+pmv.toString(), translated123I, mvi, epsilon); + MiscUtils.assertFloatBufferNotEqual("Mvit already translated123 w/o update, "+pmv.toString()+pmv.toString(), translated123IT, mvit, epsilon); + MiscUtils.assertFloatBufferEquals("Mvi not identity, "+pmv.toString()+pmv.toString(), ident, mvi, epsilon); + MiscUtils.assertFloatBufferEquals("Mvit not identity, "+pmv.toString()+pmv.toString(), ident, mvit, epsilon); + Assert.assertNotNull("Frustum is null"+pmv.toString(), frustum); // FIXME: Test Frustum value! + + b = pmv.update(); // will clean dirty bits, since all requests has been made -> true + Assert.assertEquals("Update has not been perfomed, but requested", true, b); + Assert.assertTrue("Dirty bits not clean, "+pmv.toString(), 0 == pmv.getDirtyBits()); + Assert.assertEquals("Request bits Mvi|Mvit|Frustum not set, "+pmv.toString(), PMVMatrix.DIRTY_INVERSE_MODELVIEW | PMVMatrix.DIRTY_INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix.DIRTY_FRUSTUM, pmv.getRequestMask()); + MiscUtils.assertFloatBufferEquals("Mvi not translated123, "+pmv.toString()+pmv.toString(), translated123I, mvi, epsilon); + MiscUtils.assertFloatBufferEquals("Mvit not translated123, "+pmv.toString()+pmv.toString(), translated123IT, mvit, epsilon); + // System.err.println("P2: "+pmv.toString()); + } + + @SuppressWarnings("unused") + @Test + public void test03MvTranslate() { + final FloatBuffer pmvMv, pmvMvi, pmvMvit; + { + final PMVMatrix pmv = new PMVMatrix(true); + pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + pmv.glLoadIdentity(); + pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + pmv.glLoadIdentity(); + pmv.glTranslatef(5f, 6f, 7f); + + pmvMv = pmv.glGetMvMatrixf(); + pmvMvi = pmv.glGetMviMatrixf(); + pmvMvit = pmv.glGetMvitMatrixf(); + } + + final FloatBuffer glMv = FloatBuffer.allocate(16); + { + GL2ES1 gl = dc.glc.getGL().getGL2ES1(); + gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + gl.glLoadIdentity(); + gl.glTranslatef(5f, 6f, 7f); + + gl.glGetFloatv(GLMatrixFunc.GL_MODELVIEW_MATRIX, glMv); + } + // System.err.println(PMVMatrix.matrixToString(null, "%10.5f", glMv, pmvMv).toString()); + + MiscUtils.assertFloatBufferEquals("Arrays not equal, expected"+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", glMv).toString()+ + ", actual"+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMv).toString(), + glMv, pmvMv, epsilon); + + // System.err.println("pmvMvi: "+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMvi)); + // System.err.println("pmvMvit: "+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMvit)); + } + + @SuppressWarnings("unused") + @Test + public void test04MvTranslateRotate() { + final FloatBuffer pmvMv, pmvMvi, pmvMvit; + { + final PMVMatrix pmv = new PMVMatrix(true); + pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + pmv.glLoadIdentity(); + pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + pmv.glLoadIdentity(); + pmv.glTranslatef(5f, 6f, 7f); + pmv.glRotatef(90f, 1f, 0f, 0f); + + pmvMv = pmv.glGetMvMatrixf(); + pmvMvi = pmv.glGetMviMatrixf(); + pmvMvit = pmv.glGetMvitMatrixf(); + } + + final FloatBuffer glMv = FloatBuffer.allocate(16); + { + GL2ES1 gl = dc.glc.getGL().getGL2ES1(); + gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + gl.glLoadIdentity(); + gl.glTranslatef(5f, 6f, 7f); + gl.glRotatef(90f, 1f, 0f, 0f); + + gl.glGetFloatv(GLMatrixFunc.GL_MODELVIEW_MATRIX, glMv); + } + // System.err.println(PMVMatrix.matrixToString(null, "%10.5f", glMv, pmvMv).toString()); + + MiscUtils.assertFloatBufferEquals("Arrays not equal, expected"+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", glMv).toString()+ + ", actual"+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMv).toString(), + glMv, pmvMv, epsilon); + + // System.err.println("pmvMvi: "+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMvi)); + // System.err.println("pmvMvit: "+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMvit)); + } + + static DrawableContext dc; + + @BeforeClass + public static void setup() throws Throwable { + try { + dc = createOffscreenDrawableAndCurrentFFPContext(); + } catch (Throwable t) { + setTestSupported(false); + throw t; + } + } + + @AfterClass + public static void cleanup() { + destroyDrawableContext(dc); + } + + static class DrawableContext { + DrawableContext(GLDrawable d, GLContext glc) { + this.d = d; + this.glc = glc; + } + GLDrawable d; + GLContext glc; + } + + private static DrawableContext createOffscreenDrawableAndCurrentFFPContext() throws Throwable { + GLProfile glp = GLProfile.getMaxFixedFunc(true); + GLCapabilities glCaps = new GLCapabilities(glp); + glCaps.setOnscreen(false); + glCaps.setPBuffer(true); + GLDrawableFactory factory = GLDrawableFactory.getFactory(glp); + GLDrawable d = factory.createOffscreenDrawable(null, glCaps, null, 64, 64); + d.setRealized(true); + GLContext glc = null; + try { + glc = d.createContext(null); + Assert.assertTrue("Context could not be made current", GLContext.CONTEXT_NOT_CURRENT < glc.makeCurrent()); + return new DrawableContext(d, glc); + } catch (Throwable t) { + if(null != glc) { + glc.destroy(); + } + d.setRealized(false); + throw t; + } + } + + private static void destroyDrawableContext(DrawableContext dc) { + if(null != dc.glc) { + dc.glc.destroy(); + dc.glc = null; + } + if(null != dc.d) { + dc.d.setRealized(false); + dc.d = null; + } + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestPMVMatrix01NEWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestPMVMatrix02NOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestPMVMatrix02NOUI.java new file mode 100644 index 000000000..0c66ad237 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestPMVMatrix02NOUI.java @@ -0,0 +1,109 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.math; + +import org.junit.Before; +import org.junit.Test; + +import com.jogamp.opengl.util.PMVMatrix; + +import javax.media.opengl.fixedfunc.GLMatrixFunc; +import java.nio.FloatBuffer; + +import static org.junit.Assert.assertArrayEquals; + +/** + * @author Thomas De Bodt + */ +public class TestPMVMatrix02NOUI { + + private PMVMatrix fMat; + + @Before + public void setUp() throws Exception { + fMat = new PMVMatrix(); + } + + @Test + public void testLookAtNegZIsNoOp() throws Exception { + fMat.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + // Look towards -z + fMat.gluLookAt( + 0, 0, 0, + 0, 0, -1, + 0, 1, 0 + ); + FloatBuffer mvMatrix = fMat.glGetMvMatrixf(); + float[] mvMatrixArr = new float[16]; + mvMatrix.asReadOnlyBuffer().get(mvMatrixArr); + assertArrayEquals( + /** + * The 3 rows of the matrix (= the 3 columns of the array/buffer) should be: side, up, -forward. + */ + new float[] { + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + }, + mvMatrixArr, + 1e-6f + ); + } + @Test + public void testLookAtPosY() throws Exception { + fMat.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + // Look towards +y + fMat.gluLookAt( + 0, 0, 0, + 0, 1, 0, + 0, 0, 1 + ); + FloatBuffer mvMatrix = fMat.glGetMvMatrixf(); + float[] mvMatrixArr = new float[16]; + mvMatrix.asReadOnlyBuffer().get(mvMatrixArr); + assertArrayEquals( + /** + * The 3 rows of the matrix (= the 3 columns of the array/buffer) should be: side, up, -forward. + */ + new float[] { + 1, 0, 0, 0, + 0, 0, -1, 0, + 0, 1, 0, 0, + 0, 0, 0, 1 + }, + mvMatrixArr, + 1e-6f + ); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestPMVMatrix02NOUI.class.getName()); + } +} -- cgit v1.2.3