Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: problem with gluUnProject

  1. #1
    Member Contributor
    Join Date
    Apr 2002
    Posts
    52

    problem with gluUnProject

    Hi,

    I tried to convert coordinates from a GLAnimCanvas to the object coordinates when the user clicks with the mouse using gluUnProject. Unfortunately, it seems that the operation failed because it returns GL_FALSE...

    Do you have an idea of what could make failed the operation...

    Thanks a lot

    Mat

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    442

    Re: problem with gluUnProject

    More information required, including the values of your unproject point etc. and the code that is causing the trouble....

  3. #3
    Member Contributor
    Join Date
    Apr 2002
    Posts
    52

    Re: problem with gluUnProject

    Originally posted by Robbo:

    More information required, including the values of your unproject point etc. and the code that is causing the trouble....
    I give you the more information I can:

    My GLAnimCanvas (Java) has a size of 900*600 and he is incerted in a JPanel of the same size. The user will click everywhere on this GLAnimCanvas that will generate an event. I pick up from this event the position where the user clicked for example 400-300. Then the Zone method is called it will make the convertion:

    /***************************************/
    public void mousePressed(MouseEvent e) {

    Pos_X_Dep = e.getX();
    Pos_Y_Dep = e.getY();
    Canvas.Zone(Pos_X_Dep, Pos_Y_Dep);
    }
    }
    /***************************************/
    public void Zone(int X, int Y){

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

    glu.gluUnProject((double)X,(double)Y,0.0,mvmatrix, projmatrix,viewport,x,y,z));

    }
    /**************************************/

    The method Zone below should make the conversion but it failed.
    I initialised the GLAnimCanvas like this:

    /**************************************/
    gl.glViewport(0,0,width,height); //width et height size of the GLAnimCanvas which is size of the JPanel
    gl.glMatrixMode(GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluPerspective(Angle_View_Degree, width/height, 0.0f, 10.0f);
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    gl.glLoadIdentity();
    /**************************************/

    I draw many rectangles in my GLAnimcanvas they represent a pipeline. For seeing all the pipeline, I calculate an ideal Z position and I use glTranslated for setting the new position. The user can also drag with the mouse to move the scene. I also use glTanslated:
    /**************************************/

    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    gl.glTranslated(X_Value,Y_Value,Z_Value);
    // I change the value of the variables X Y and Z to see the new view of the scene

    for (int i=0 ; i < Pipe_Values.size();i++){// For each part of the pipe

    pipe = (Pipe)Pipe_Values.get(i);
    // Take the pipe
    Lenght = (float)pipe.getLenght();
    // Take his lenght
    Angle = (float)(pipe.getAngle());//*180/Math.PI);
    // Take his angle

    gl.glRotatef (Angle, 0.0f,0.0f,1.0f); // Rotate the direction of the pipe depending the angle value
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glBegin(GL_QUADS); // Draw a quad
    gl.glColor4f(0.75f,0.0f,0.0f,0.9f); gl.glVertex3f(0.0f,(float)(-Diameter/2*1.2),0.0f); gl.glVertex3f(Lenght,(float)(-Diameter/2*1.2),0.0f); gl.glVertex3f(Lenght,(float)(Diameter/2*1.2),0.0f); gl.glVertex3f(0.0f,(float)(Diameter/2*1.2),0.0f); gl.glEnd(); // End of the quad

    gl.glTranslated Lenght+3*Diameter/2,0.0f,0.0f); // Move the cursor to the next pipe to draw
    gl.glRotatef (-Angle,0.0f,0.0f,1.0f); // Reinitialise the angle to 0
    gl.glFlush();
    }

    gl.glLoadIdentity();

    /**************************************/

    I hope i have the most complete I could and wish you can help me Robbo..

    Thanks in advance
    Mat

  4. #4
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    442

    Re: problem with gluUnProject

    Hmmm. I'm not 100% sure (never used Java before), but I have a sneaking suspicion your modelview matrix might not be setup correctly when you execute your `zone' method.

    You are being neat and tidy and resetting the matrix to identity after use. I suspect the matrix is identity when you unproject. Print out the values in the modelview matrix, if they are something like

    1, 0, 0, 0,
    0, 1, 0, 0,
    0, 0, 1, 0,
    0, 0, 0, 1

    Then you have an identiy matrix and thus your inverse transform won't be correct to the view you are rendering into.

  5. #5
    Member Contributor
    Join Date
    Apr 2002
    Posts
    52

    Re: problem with gluUnProject

    Originally posted by Robbo:

    Hmmm. I'm not 100% sure (never used Java before), but I have a sneaking suspicion your modelview matrix might not be setup correctly when you execute your `zone' method.

    You are being neat and tidy and resetting the matrix to identity after use. I suspect the matrix is identity when you unproject. Print out the values in the modelview matrix, if they are something like

    1, 0, 0, 0,
    0, 1, 0, 0,
    0, 0, 1, 0,
    0, 0, 0, 1

    Then you have an identiy matrix and thus your inverse transform won't be correct to the view you are rendering into.

    Hi Robbo and thanks for your reply

    I tried what you told me and exactly the matrix was the original and it was not the good. Nevertheless it still don't work.. I tried with the ortho mode and then it works more or less correctly but it still failed in gluPerspective mode !!

    Mathieu

  6. #6
    Member Contributor
    Join Date
    Jan 2001
    Location
    Portland, ME., USA
    Posts
    86

    Re: problem with gluUnProject

    Hi,
    What's z? In order to use gluUnProject, you need the correct z value. Check out glreadpixels to obtain the correct z value, then call gluUnProject. That should help.

    lobstah...
    lobstah

  7. #7
    Member Contributor
    Join Date
    Apr 2002
    Posts
    52

    Re: problem with gluUnProject

    Originally posted by lobstah:
    Hi,
    What's z? In order to use gluUnProject, you need the correct z value. Check out glreadpixels to obtain the correct z value, then call gluUnProject. That should help.

    lobstah...
    Hi lobstah thanks for your help..

    I don't know if I use the method glReadPixel correctly because it alway's return the 0 value
    Can you tell me more about how using this funtion

    Thanks a lot
    MAt

  8. #8
    Member Contributor
    Join Date
    Apr 2002
    Posts
    52

    Re: problem with gluUnProject

    I used the glReadPixel like that

    gl.glReadPixels(X,Y,0,0,GL_DEPTH_COMPONENT,GL_FLOA T,depthbuffer);

    with X Y the coordinates where the user clicked..

    Mat

  9. #9
    Member Contributor
    Join Date
    Jan 2001
    Location
    Portland, ME., USA
    Posts
    86

    Re: problem with gluUnProject

    glReadPixels (x, real_y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);

    Make sure the y component (real_y here) is oriented correctly (Windows and OGL treat the orientation of the y component of the window differently (opposite)) and pass z by reference. Also, the dimensions of the pixel should be set to 1; in your call they're set to 0.

    I think that should do it.


    lobstah...
    lobstah

  10. #10
    Member Contributor
    Join Date
    Apr 2002
    Posts
    52

    Re: problem with gluUnProject

    I still have the same result with a value equal to 0...

    and with this value my glUnProject still failed..

    I don't know what it could be...and why it works with a ortho projection... If I know how to do a zoom effect in orto mode I could continue with ortho mode...

    Mat

Page 1 of 2 12 LastLast

Similar Threads

  1. problem using gluUnproject
    By abhijit in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 05-06-2005, 11:04 AM
  2. Problem with gluUnProject
    By Aquileo in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-11-2004, 10:06 AM
  3. Little problem with gluUnProject
    By jirkamelich in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 12-28-2002, 12:25 PM
  4. problem with gluUnProject
    By jirkamelich in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 12-16-2002, 06:15 AM
  5. gluUnProject problem
    By nstod in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-26-2002, 12:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean