summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--[-rwxr-xr-x]make/scripts/tests.sh3
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java24
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/math/TestPMVMatrix03NOUI.java125
3 files changed, 139 insertions, 13 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index d49a0fc33..693683827 100755..100644
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -281,7 +281,7 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestOlympicES1NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestRedSquareES1NEWT $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $*
-testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT $*
+#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelsAWT $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasAWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
@@ -312,6 +312,7 @@ testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT
#testnoawt com.jogamp.opengl.test.junit.jogl.math.TestPMVMatrix01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.math.TestPMVMatrix02NOUI $*
+testnoawt com.jogamp.opengl.test.junit.jogl.math.TestPMVMatrix03NOUI $*
#testnoawt com.jogamp.opengl.test.junit.jogl.math.TestGluUnprojectFloatNOUI $*
#testnoawt com.jogamp.opengl.test.junit.jogl.math.TestGluUnprojectDoubleNOUI $*
#testnoawt com.jogamp.opengl.test.junit.jogl.math.TestFloatUtil01MatrixMatrixMultNOUI $*
diff --git a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
index bfc03d019..58151856f 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/PMVMatrix.java
@@ -488,7 +488,7 @@ public class PMVMatrix implements GLMatrixFunc {
if(matrixGetName==GL_MATRIX_MODE) {
params.put((float)matrixMode);
} else {
- FloatBuffer matrix = glGetMatrixf(matrixGetName);
+ final FloatBuffer matrix = glGetMatrixf(matrixGetName);
params.put(matrix); // matrix -> params
matrix.reset();
}
@@ -500,7 +500,7 @@ public class PMVMatrix implements GLMatrixFunc {
if(matrixGetName==GL_MATRIX_MODE) {
params[params_offset]=(float)matrixMode;
} else {
- FloatBuffer matrix = glGetMatrixf(matrixGetName);
+ final FloatBuffer matrix = glGetMatrixf(matrixGetName);
matrix.get(params, params_offset, 16); // matrix -> params
matrix.reset();
}
@@ -619,15 +619,15 @@ public class PMVMatrix implements GLMatrixFunc {
@Override
public final void glMultMatrixf(final FloatBuffer m) {
if(matrixMode==GL_MODELVIEW) {
- FloatUtil.multMatrixf(matrixMv, m, matrixMv);
+ FloatUtil.multMatrixf(matrixMv, m);
dirtyBits |= DIRTY_INVERSE_MODELVIEW | DIRTY_INVERSE_TRANSPOSED_MODELVIEW | DIRTY_FRUSTUM ;
modifiedBits |= MODIFIED_MODELVIEW;
} else if(matrixMode==GL_PROJECTION) {
- FloatUtil.multMatrixf(matrixP, m, matrixP);
+ FloatUtil.multMatrixf(matrixP, m);
dirtyBits |= DIRTY_FRUSTUM ;
modifiedBits |= MODIFIED_PROJECTION;
} else if(matrixMode==GL.GL_TEXTURE) {
- FloatUtil.multMatrixf(matrixTex, m, matrixTex);
+ FloatUtil.multMatrixf(matrixTex, m);
modifiedBits |= MODIFIED_TEXTURE;
}
}
@@ -635,15 +635,15 @@ public class PMVMatrix implements GLMatrixFunc {
@Override
public final void glMultMatrixf(float[] m, int m_offset) {
if(matrixMode==GL_MODELVIEW) {
- FloatUtil.multMatrixf(matrixMv, m, m_offset, matrixMv);
+ FloatUtil.multMatrixf(matrixMv, m, m_offset);
dirtyBits |= DIRTY_INVERSE_MODELVIEW | DIRTY_INVERSE_TRANSPOSED_MODELVIEW | DIRTY_FRUSTUM ;
modifiedBits |= MODIFIED_MODELVIEW;
} else if(matrixMode==GL_PROJECTION) {
- FloatUtil.multMatrixf(matrixP, m, m_offset, matrixP);
+ FloatUtil.multMatrixf(matrixP, m, m_offset);
dirtyBits |= DIRTY_FRUSTUM ;
modifiedBits |= MODIFIED_PROJECTION;
} else if(matrixMode==GL.GL_TEXTURE) {
- FloatUtil.multMatrixf(matrixTex, m, m_offset, matrixTex);
+ FloatUtil.multMatrixf(matrixTex, m, m_offset);
modifiedBits |= MODIFIED_TEXTURE;
}
}
@@ -813,8 +813,8 @@ public class PMVMatrix implements GLMatrixFunc {
float[] win_pos, int win_pos_offset ) {
if(usesBackingArray) {
return projectFloat.gluProject(objx, objy, objz,
- matrixMv.array(), 0,
- matrixP.array(), 0,
+ matrixMv.array(), matrixMv.position(),
+ matrixP.array(), matrixP.position(),
viewport, viewport_offset,
win_pos, win_pos_offset);
} else {
@@ -843,8 +843,8 @@ public class PMVMatrix implements GLMatrixFunc {
float[] obj_pos, int obj_pos_offset) {
if(usesBackingArray) {
return projectFloat.gluUnProject(winx, winy, winz,
- matrixMv.array(), 0,
- matrixP.array(), 0,
+ matrixMv.array(), matrixMv.position(),
+ matrixP.array(), matrixP.position(),
viewport, viewport_offset,
obj_pos, obj_pos_offset);
} else {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestPMVMatrix03NOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestPMVMatrix03NOUI.java
new file mode 100644
index 000000000..81242ce6e
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestPMVMatrix03NOUI.java
@@ -0,0 +1,125 @@
+package com.jogamp.opengl.test.junit.jogl.math;
+
+import java.util.Arrays;
+
+import jogamp.opengl.ProjectFloat;
+
+import com.jogamp.opengl.math.FloatUtil;
+import com.jogamp.opengl.util.PMVMatrix;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestPMVMatrix03NOUI {
+
+ static final float epsilon = 0.00001f;
+
+ // Simple 10 x 10 view port
+ static final int[] viewport = new int[] { 0,0,10,10};
+
+ @Test
+ public void test01() {
+ float[] winA00 = new float[4];
+ float[] winA01 = new float[4];
+ float[] winA10 = new float[4];
+ float[] winA11 = new float[4];
+ PMVMatrix m = new PMVMatrix();
+
+ m.gluProject(1f, 0f, 0f, viewport, 0, winA00, 0);
+ System.out.println("A.0.0 - Project 1,0 -->" + Arrays.toString(winA00));
+
+ m.gluProject(0f, 0f, 0f, viewport, 0, winA01, 0);
+ System.out.println("A.0.1 - Project 0,0 -->" + Arrays.toString(winA01));
+
+ m.glMatrixMode(PMVMatrix.GL_PROJECTION);
+ m.glOrthof(0, 10, 0, 10, 1, -1);
+ System.out.println("MATRIX - Ortho 0,0,10,10 - Locate the origin in the bottom left and scale");
+ System.out.println(m);
+ float[] projMatrixA = new float[16];
+ float[] modelMatrixA = new float[16];
+ m.glGetFloatv(PMVMatrix.GL_PROJECTION, projMatrixA, 0);
+ m.glGetFloatv(PMVMatrix.GL_MODELVIEW, modelMatrixA, 0);
+
+ m.gluProject(1f, 0f, 0f, viewport, 0, winA10, 0);
+ System.out.println("A.1.0 - Project 1,0 -->" +Arrays.toString(winA10));
+
+ m.gluProject(0f, 0f, 0f, viewport, 0, winA11, 0);
+ System.out.println("A.1.1 - Project 0,0 -->" +Arrays.toString(winA11));
+
+
+ ////////////////////
+ /////////////////////
+
+ float[] winB00 = new float[4];
+ float[] winB01 = new float[4];
+ float[] winB10 = new float[4];
+ float[] winB11 = new float[4];
+ float[] projMatrixB = new float[16];
+ float[] modelMatrixB = new float[16];
+ FloatUtil.makeIdentityf(projMatrixB, 0);
+ FloatUtil.makeIdentityf(modelMatrixB, 0);
+ final ProjectFloat projectFloat = new ProjectFloat(true);
+
+ projectFloat.gluProject(1f, 0f, 0f, modelMatrixB, 0, projMatrixB, 0, viewport, 0, winB00, 0);
+ System.out.println("B.0.0 - Project 1,0 -->" +Arrays.toString(winB00));
+
+ projectFloat.gluProject(0f, 0f, 0f, modelMatrixB, 0, projMatrixB, 0, viewport, 0, winB01, 0);
+ System.out.println("B.0.1 - Project 0,0 -->" +Arrays.toString(winB01));
+
+ glOrthof(projMatrixB, 0, 10, 0, 10, 1, -1);
+ System.out.println("FloatUtil - Ortho 0,0,10,10 - Locate the origin in the bottom left and scale");
+ System.out.println("Projection");
+ System.err.println(FloatUtil.matrixToString(null, null, "%10.5f", projMatrixB, 0, 4, 4, false /* rowMajorOrder */));
+ System.out.println("Modelview");
+ System.err.println(FloatUtil.matrixToString(null, null, "%10.5f", modelMatrixB, 0, 4, 4, false /* rowMajorOrder */));
+
+ projectFloat.gluProject(1f, 0f, 0f, modelMatrixB, 0, projMatrixB, 0, viewport, 0, winB10, 0);
+ System.out.println("B.1.0 - Project 1,0 -->" +Arrays.toString(winB10));
+
+ projectFloat.gluProject(0f, 0f, 0f, modelMatrixB, 0, projMatrixB, 0, viewport, 0, winB11, 0);
+ System.out.println("B.1.1 - Project 0,0 -->" +Arrays.toString(winB11));
+
+ Assert.assertArrayEquals("A/B 0.0 Project 1,0 failure", winB00, winA00, epsilon);
+ Assert.assertArrayEquals("A/B 0.1 Project 0,0 failure", winB01, winA01, epsilon);
+ Assert.assertArrayEquals("A/B 1.0 Project 1,0 failure", winB10, winA10, epsilon);
+ Assert.assertArrayEquals("A/B 1.1 Project 0,0 failure", winB11, winA11, epsilon);
+
+ Assert.assertEquals("A 0.0 Project 1,0 failure X", 10.0, winA00[0], epsilon);
+ Assert.assertEquals("A 0.0 Project 1,0 failure Y", 5.0, winA00[1], epsilon);
+ Assert.assertEquals("A.0.1 Project 0,0 failure X", 5.0, winA01[0], epsilon);
+ Assert.assertEquals("A.0.1 Project 0,0 failure Y", 5.0, winA01[1], epsilon);
+ Assert.assertEquals("A 1.0 Project 1,0 failure X", 1.0, winA10[0], epsilon);
+ Assert.assertEquals("A 1.0 Project 1,0 failure Y", 0.0, winA10[1], epsilon);
+ Assert.assertEquals("A.1.1 Project 0,0 failure X", 0.0, winA11[0], epsilon);
+ Assert.assertEquals("A.1.1 Project 0,0 failure Y", 0.0, winA11[1], epsilon);
+ }
+
+ public final void glOrthof(final float[] m, final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) {
+ // Ortho matrix:
+ // 2/dx 0 0 tx
+ // 0 2/dy 0 ty
+ // 0 0 2/dz tz
+ // 0 0 0 1
+ final float dx=right-left;
+ final float dy=top-bottom;
+ final float dz=zFar-zNear;
+ final float tx=-1.0f*(right+left)/dx;
+ final float ty=-1.0f*(top+bottom)/dy;
+ final float tz=-1.0f*(zFar+zNear)/dz;
+
+ float[] matrixOrtho = new float[16];
+ FloatUtil.makeIdentityf(matrixOrtho, 0);
+ matrixOrtho[0+4*0] = 2.0f/dx;
+ matrixOrtho[1+4*1] = 2.0f/dy;
+ matrixOrtho[2+4*2] = -2.0f/dz;
+ matrixOrtho[0+4*3] = tx;
+ matrixOrtho[1+4*3] = ty;
+ matrixOrtho[2+4*3] = tz;
+
+ FloatUtil.multMatrixf(m, 0, matrixOrtho, 0);
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main(TestPMVMatrix03NOUI.class.getName());
+ }
+}