Confusion with PMVMatrix

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Confusion with PMVMatrix

john bauer
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.
Reply | Threaded
Open this post in threaded view
|

Re: Confusion with PMVMatrix

Sven Gothel
Administrator
On 06/05/2013 07:28 PM, john bauer [via jogamp] wrote:
> I am trying to use the PMVMatrix project and unproject functions and I think
> that I am using them wrong.

.. before digging into details,
which JOGL version do you use ?
Pls test w/ latest aggregated build -> wiki.

This reminds me of an old bug, which we have fixed a while ago.

~Sven

>
> 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.
>
> ------------------------------------------------------------------------------
> If you reply to this email, your message will be added to the discussion below:
> http://forum.jogamp.org/Confusion-with-PMVMatrix-tp4029336.html
> To start a new topic under jogl, email [hidden email]
> To unsubscribe from jogl, click here
> <
> NAML
> <
http://forum.jogamp.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>

--
health & wealth
mailto:[hidden email] ; http://jausoft.com
land : +49 (471) 4707742 ; fax : +49 (471) 4707741
Timezone CET: PST+9, EST+6, UTC+1


signature.asc (911 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Confusion with PMVMatrix

john bauer
Ok, we are just using the latest release. I can try it against the nightly builds.
Reply | Threaded
Open this post in threaded view
|

Re: Confusion with PMVMatrix

Sven Gothel
Administrator
In reply to this post by john bauer
On 06/05/2013 07:28 PM, john bauer [via jogamp] wrote:
> I am trying to use the PMVMatrix project and unproject functions and I think
> that I am using them wrong.
>
> I have
>

Fixed - thx.
<https://jogamp.org/bugzilla/show_bug.cgi?id=748>

Note: Your array print method is wrong.

~Sven


signature.asc (911 bytes) Download Attachment
HRJ
Reply | Threaded
Open this post in threaded view
|

Re: Confusion with PMVMatrix

HRJ
Does this affect JOGL version 2.1.3? I am seeing some strange results with PMVMatrix.glProject()

Thanks,
HRJ
Reply | Threaded
Open this post in threaded view
|

Re: Confusion with PMVMatrix

gouessej
Administrator
Hi

Your comment is so vague. Please tell us what you do, what the expected result is and what you get. Moreover, use the very latest version (which is currently JOGL 2.1.4).
Julien Gouesse | Personal blog | Website
HRJ
Reply | Threaded
Open this post in threaded view
|

Re: Confusion with PMVMatrix

HRJ
Before posting my whole test case, I just want to know if the reported bug is known to be present in 2.1.3.

I did try to get 2.1.4 but the jar files are apparently corrupted. For example, this file:
http://jogamp.org/deployment/v2.1.4/jar/jogl-all.jar

.. gives this error:
jar tf jogamp_2.1.4/jogl-all.jar
java.util.zip.ZipException: error in opening zip file
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:215)
        at java.util.zip.ZipFile.<init>(ZipFile.java:145)
        at java.util.zip.ZipFile.<init>(ZipFile.java:116)
        at sun.tools.jar.Main.list(Main.java:1004)
        at sun.tools.jar.Main.run(Main.java:245)
        at sun.tools.jar.Main.main(Main.java:1177)
Reply | Threaded
Open this post in threaded view
|

Re: Confusion with PMVMatrix

gouessej
Administrator
This JAR is not corrupted but Mozilla Firefox included a "security" feature affecting JARs several years ago, the content of the JAR is more or less wrapped into a ZIP... which leads to a JAR unusable as is. Rather download the whole archive and extract the JARs from it:
http://jogamp.org/deployment/v2.1.4/archive/jogamp-all-platforms.7z

If you still have the same error, then the JAR is really corrupted. The reported bug was already fixed a long time before JOGL 2.1.3 was released, it should work but maybe you have found another bug.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Confusion with PMVMatrix

Irene Tang
In reply to this post by Sven Gothel
Why is the projection matrix  after m.glMatrixMode(GL_PROJECTION);
m.glOrthof(0, 10, 0, 10, 1, -1); Why the value in the blue circle isn't -1?
Reply | Threaded
Open this post in threaded view
|

Re: Confusion with PMVMatrix

elect
Irene Tang wrote
Why is the projection matrix  after m.glMatrixMode(GL_PROJECTION);
m.glOrthof(0, 10, 0, 10, 1, -1); Why the value in the blue circle isn't -1?
public static Mat4 ortho(Mat4 res, float left, float right, float bottom, float top, float zNear, float zFar) {
        res.m00 = 2.0f / (right - left);
        res.m01 = 0.0f;
        res.m02 = 0.0f;
        res.m03 = 0.0f;
        res.m10 = 0.0f;
        res.m11 = 2.0f / (top - bottom);
        res.m12 = 0.0f;
        res.m13 = 0.0f;
        res.m20 = 0.0f;
        res.m21 = 0.0f;
        res.m22 = -2.0f / (zFar - zNear);
        res.m23 = 0.0f;
        res.m30 = -(right + left) / (right - left);
        res.m31 = -(top + bottom) / (top - bottom);
        res.m32 = -(zFar + zNear) / (zFar - zNear);
        res.m33 = 1.0f;
        return res;
    }

that value is m22

m22 = -2.0f / (-1 - 1) = -2.0f / -2 = 1

I strongly suggest you to move away from using deprecated opengl and starting working with the matrices directly by yourself ;)