Jump to content
  • Advertisement
Sign in to follow this  
gorgorath

OpenGL gluUnproject errors (JOGL)

This topic is 4789 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to get the world position from a given position on the openGL canvas, accesible by a mouse click. this is then transformed in to a 3d Position. ////////////////////////////// //GLEVENTLISTENER implementation ////////////////////////////// public void display(GLDrawable drawable) { if( mouseClicked){ render.get3DPoint(oglMouseX, oglMouseY, drawable); mouseClicked = false; } } now the the gluUnproject code: gl = d.getGL(); glu = d.getGLU(); double[] mvmatrix = new double[16]; double[] projmatrix = new double[16]; int[] viewport = new int[4]; double[] objPos = new double[3]; double dClickY; gl.glGetIntegerv(GL.GL_VIEWPORT, viewport); gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix); gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix); dClickY = (double) (viewportHeight - y); glu.gluUnProject( (double)x, dClickY, 0.0, mvmatrix, projmatrix, viewport, objPos); but the objPos always seems to be (0,0,0); which seems coz this are the values of the matrices: PROJECTION MATRIX -1.7018005847930908 -0.12783338129520416 0.6429447531700134 0.6429447531700134 -1.436849594116211 0.1514054834842682 -0.7615019679069519 -0.7615019679069519 0.0 2.4060678482055664 0.08207805454730988 0.08207805454730988 0.0 0.0 0.0 0.0 MODELVIEW MATRIX 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 VIEWPORT 0 0 594 548 thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
If you want to use gluUnproject, you must make sure you use the proper modelview, projection and viewport information. You want to transform the mouse cursor to world space. Look at the typical matrix concatenation:
<window space> viewport_transform <screen space> projection_matrix <camera space> view_matrix <world space> model_matrix <model space>

You have a point in <window space> and wish to transform it to <world space>. Looking at the required matrices in between you'll need: viewport_transform (if the render part of your window is 594x548 it's ok), projection_matrix (hard to tell from the numbers, but the matrix you print is definitely not made with a glFrustum/gluPerspective/glOrtho call: the end of this Red Book appendix shows what the shape of the projection matrix should be), view_matrix (you need the view part of the matrix, for example made with gluLookAt, but it's identity, so that's definately wrong). You should make sure your projection matrix stack contains the same projection matrix as used when rendering the scene and the modelview matrix should contain the view matrix that was used to render your scene (and no model matrix). If the projection matrix you print is the one you use when rendering, you may want to make sure that it is constructed using a single call to one of these functions: glFrustum, gluPerspective or glOrtho.

Tom

[Edited by - dimebolt on November 3, 2005 7:49:39 AM]

Share this post


Link to post
Share on other sites
Did you check for errors? Logically to unproject it needs the inverse of the projection matrix, but that particular one doesn't have an inverse. You can tell that easily by the row/column of zeroes at the end.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!