Sign in to follow this  

JOGL gluUnproject Problem

This topic is 2394 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

Hey everybody,

I did a search in the forum looking for other people having the same problem as me, but i found nothing... So i created a new thread here to see if someone could find what I'm missing.
The problem is that I'm trying to implement a picking function using gluUnproject to convert my window coords to my world cords under JOGL and the results doesn't seem to be fine.
I capture the mouse event using a mouse listener on my GLJPanel and use it on my display function. After having the window coords, I use gluUnproject to know where the click is on my world, but actually, these coords doesn't seem to be correct, my scene just isn't in the place the unprojected coords says.

I feel that I'm messing something up while setting the perspective projection, setting the gluLookAt position. I think the problem is on my stack.

This is my code and, by the way, I'm trying to pick a chess board:

[code]public void display(GLAutoDrawable glad)
{
GL gl = glad.getGL();
GLU glu = new GLU();

gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f); //backgroung color
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();

glu.gluLookAt(camX, camY, camZ,
camPointX, camPointY, camPointZ,
0.0, 1.0, 0.0);

gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(60.0, 1.0, 1.0, 1000.0);

if (mouse != null)
{
//Picking part
double x = (double)mouse.getX(), y = (double)mouse.getY();
mouse = null;
int viewport[] = new int[4];
double mvmatrix[] = new double[16];
double projmatrix[] = new double[16];
double realy = (double)viewport[3] - y - 1.0;
double wcoord[] = new double[4];

gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);

glu.gluUnProject(x, realy, 0.0, mvmatrix, 0, projmatrix, 0, viewport, 0, wcoord, 0);

System.out.println("X = " + wcoord[0] + " , Y = " + wcoord[1] + " , Z = " + wcoord[2]);
}

gl.glMatrixMode(GL.GL_MODELVIEW);

models.get(6).draw(glad); //draws the board

gl.glCallList(skyBoxDList); //draws my skybox

for (int i=0 ; i<8 ; i++)
{
for (int j=0 ; j<8 ; j++)
{
if (tabuleiro[i][j] != -1) //tabuleiro is the matrix I use to map the board
{
gl.glPushMatrix(); //push the actual matrix
if (pecaSendoMovida == tabuleiro[i][j])
{
gl.glTranslated(j * 0.215 + movX * 0.215, 0.0 + movY * 0.215 , -i * 0.215 + movZ * 0.215);
}
else
{
gl.glTranslated(j * 0.215, 0.0 , -i * 0.215); //translates the pieces to the place it's going to be drawn according to my matrix map
}
models.get(tabuleiro[i][j]).draw(glad); //draws the pieces
gl.glPopMatrix(); //return to the matrix pushed
}
}
}

gl.glFlush(); //execute all commands
}[/code]


If any other code is needed to figure out what I'm trying to do, feel free to ask.

Thanks for the help,
Eduardo.

Share this post


Link to post
Share on other sites

This topic is 2394 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this