Login  Register

Confusion with PMVMatrix

Posted by john bauer on Jun 05, 2013; 5:28pm
URL: https://forum.jogamp.org/Confusion-with-PMVMatrix-tp4029336.html

I am trying to use the PMVMatrix project and unproject functions and I think that I am using them wrong.

I have

PMVMatrix m = new PMVMatrix();
System.out.println("MATRIX - Identity");
System.out.println(m);

// Simple 10 x 10 view port
int[] viewport = new int[] { 0,0,10,10};

float[] win = new float[4];

m.gluProject(1f, 0f, 0f, viewport, 0, win, 0);
System.out.println("Project 1,0 -->" + Arrays.toString(win));

m.gluProject(0f, 0f, 0f, viewport, 0, win, 0);
System.out.println("Project 0,0 -->" + Arrays.toString(win));

m.glMatrixMode(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);

m.gluProject(1f, 0f, 0f, viewport, 0, win, 0);
System.out.println("Project 1,0 -->" +Arrays.toString(win));

m.gluProject(0f, 0f, 0f, viewport, 0, win, 0);
System.out.println("Project 0,0 -->" +Arrays.toString(win));

System.out.println();
System.out.println("Don't trust the implementation");
		
float[] projMatrix = new float[16];
m.glGetFloatv(GL_PROJECTION, projMatrix, 0);
System.out.println("Projection");
for (int i=0; i<4;i++) System.out.println(projMatrix[i] + "\t" +projMatrix[i+1] + "\t" +projMatrix[i+2] + "\t" +projMatrix[i+3] );


float[] modelMatrix = new float[16];
m.glGetFloatv(GL_MODELVIEW, modelMatrix, 0);
System.out.println("Modelview");
for (int i=0; i<4;i++) System.out.println(modelMatrix[i] + "\t" +modelMatrix[i+1] + "\t" +modelMatrix[i+2] + "\t" +modelMatrix[i+3] );


new ProjectFloat(true).gluProject(1f, 0f, 0f,modelMatrix, 0, 
		projMatrix, 0, viewport, 0, win, 0);
System.out.println("Project 1,0 -->" +Arrays.toString(win));

new ProjectFloat(true).gluProject(0f, 0f, 0f,modelMatrix, 0, 
		projMatrix, 0, viewport, 0, win, 0);
System.out.println("Project 0,0 -->" +Arrays.toString(win));

And when I run it I get

PMVMatrix[backingArray true, modified[P true, Mv true, T true], dirty/req[Mvi true/false, Mvit true/false], Projection
[    1.00000    0.00000    0.00000    0.00000 ]
[    0.00000    1.00000    0.00000    0.00000 ]
[    0.00000    0.00000    1.00000    0.00000 ]
[    0.00000    0.00000    0.00000    1.00000 ]
, Modelview
[    1.00000    0.00000    0.00000    0.00000 ]
[    0.00000    1.00000    0.00000    0.00000 ]
[    0.00000    0.00000    1.00000    0.00000 ]
[    0.00000    0.00000    0.00000    1.00000 ]
, Texture
[    1.00000    0.00000    0.00000    0.00000 ]
[    0.00000    1.00000    0.00000    0.00000 ]
[    0.00000    0.00000    1.00000    0.00000 ]
[    0.00000    0.00000    0.00000    1.00000 ]
]
Project 1,0 -->[10.0, 5.0, 0.5, 0.0]
Project 0,0 -->[5.0, 5.0, 0.5, 0.0]
MATRIX - Ortho 0,0,10,10 - Locate the origin in the bottom left and scale
PMVMatrix[backingArray true, modified[P true, Mv true, T true], dirty/req[Mvi true/false, Mvit true/false], Projection
[    0.20000    0.00000    0.00000   -1.00000 ]
[    0.00000    0.20000    0.00000   -1.00000 ]
[    0.00000    0.00000    1.00000    0.00000 ]
[    0.00000    0.00000    0.00000    1.00000 ]
, Modelview
[    1.00000    0.00000    0.00000    0.00000 ]
[    0.00000    1.00000    0.00000    0.00000 ]
[    0.00000    0.00000    1.00000    0.00000 ]
[    0.00000    0.00000    0.00000    1.00000 ]
, Texture
[    1.00000    0.00000    0.00000    0.00000 ]
[    0.00000    1.00000    0.00000    0.00000 ]
[    0.00000    0.00000    1.00000    0.00000 ]
[    0.00000    0.00000    0.00000    1.00000 ]
]
Project 1,0 -->[10.0, 5.0, 0.5, 0.0]
Project 0,0 -->[5.0, 5.0, 0.5, 0.0]

Don't trust the implementation
Projection
0.2	0.0	0.0	0.0
0.0	0.0	0.0	0.0
0.0	0.0	0.0	0.2
0.0	0.0	0.2	0.0
Modelview
1.0	0.0	0.0	0.0
0.0	0.0	0.0	0.0
0.0	0.0	0.0	1.0
0.0	0.0	1.0	0.0
Project 1,0 -->[0.99999994, 0.0, 0.5, 0.0]
Project 0,0 -->[0.0, 0.0, 0.5, 0.0]

I am not getting what I expect after I apply the glOrtho in the PMVMatrix (the anwser is not changing) and when I compare it to the result of FloatProject I get different anwsers. The FloatProject Anwser looks correct. I think that I have tracked this down to the PMVMatrix gluProject function on the lines that have  matrixMv.array(), and
 matrixP.array(). They seem to be getting the wrong data from the array

Can you tell me if I am using these functions incorrectly and if so how they are expected to be used. For now I am using the FloatProject work around.