Results 1 to 10 of 10

Thread: Get the Polygon Mouse Position

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    13

    Get the Polygon Mouse Position

    Hi Friends,

    Using the gluUnProject, i'm get the object(Ex:A Simple Polygon) position while mouse click. Its perfect

    My Problem is if any other object like sphere or cyliner or even a line is infront of the Polygon object means it returns the position of object which is infront of the quad object. But I need whatever object infront of the Polygon, it should return the position of the Polygon.....Is it Possible....?

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Get the Polygon Mouse Position

    Actually gluUnproject just performs the matrix operation described here. It does not have any knowledge of what is currently drawn and just perform a matrix operation using the window coordinates (winX, winY, winZ) that you compute and specify yourself.

    Now, I don't know how you compute the window coordinates. I assume that WinX and WinY are computed from the mouse position and WinZ, reading depth value from the depth buffer.

    In this case, if you want to ignore an object in the object picking code you may perform an additional depth pass removing this object from the rendering batch.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    13

    Re: Get the Polygon Mouse Position

    can u please explain me how to perform additional depth pass to removing a object from the rendering batch?

    Thnxs.

  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Get the Polygon Mouse Position

    You do the same thing as the first pass but disable color writing (glColorMask) as it is not needed because you just want to sample the depth buffer then. Clear depth buffer, enable depth writing and don't draw the objects you don't want to pick.


  5. #5
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    13

    Re: Get the Polygon Mouse Position

    Thnxs for ur reply.....

    I used the glColorMask before the glReadPixels and set false all the RGBA , but the result is same it detect sphere which is infront of the polygon...can u please the explain the step sequence...


    Thnxs

  6. #6
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Get the Polygon Mouse Position

    When you disable color writing while you draw this sphere, you can't prevent depth writing for this particular sphere. So either you know which objects don't have to be detected and simply don't write them in the depth pass. Or you have to select a particular depth layer (the question I can't answer is which one?). Can you explain exactly what you are intending to do, for what purpose?

    There is something that might interest you that is called depth peeling. Google it and read about it. This algorithm allows you to draw a particular depth layer but is not performance-wise.

  7. #7
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    13

    Re: Get the Polygon Mouse Position

    i am trying to develop drawing software based on the plane. For example, if i draw a circle on the xy plane means, i create a dummy polygon on xy plane(to get the exact position of the mouse, otherwise it return the near/far value of the frustum. i dont know its correct way for get mouse position of exact xy plane...but i tried this way) and draw the circle..its work.

    But the problem is ..i drawn one sphere on xy plane and try to draw a line on xy from sphere center position to some point(Again i create the dummy polygon on xy plane to get the xy mouse poistion). I cant draw line from the sphere center postion, instead sphere center position it return the surface the spere which is not the exact xy plane.....

  8. #8
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Get the Polygon Mouse Position

    I am sorry but I am still not sure to understand exactly your problem. Perhaps some screenshots would help.

    If you are trying to find the position of a point below the mouse on one of (xy, xz, yz) 3d planes, why don't you simply draw first your dummy polygon only then compute the 3d point position and finally draw the entire scene. I still don't understand why you have to draw this sphere above the plane.

  9. #9
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    13

    Re: Get the Polygon Mouse Position

    Hi,

    These are the screen shots.

    I already draw a Cylinder on the center (0, 0, 0).Now i trying to draw a line on the selected plane(yellow is the selected plane, i draw a dummy plane on the selected plane to get the mouse position). X1 is the some point on the selected plane and x1 is the center (0, 0, 0) which also the cylinder center.




    Now the line is drawn. X1 is on the selected plane.. but the X2 is not on the selected plane....it's on the surface of the Cylinder






    Thanks.

  10. #10
    Junior Member Newbie Dave Driesen's Avatar
    Join Date
    Apr 2009
    Location
    Belgium
    Posts
    7

    Re: Get the Polygon Mouse Position

    What Dletozeun means is that you don't need to draw anything other than your selection plane(s) in your selection pass. Then you can't have the problem that some other object's name is being returned because it ended up being closer to the camera than the selection plane itself (which seems to be the case judging by the screenshots you posted).

    If you're using a GL_SELECT-based picking method then it's somewhat traditional to make a render function with 2 modes (one being render and one being select) which you can then call in select-mode when your app receives a mouseclick event. Nehe has a tutorial (I think) which demonstrates this technique.

    You could look into the maths involved in unprojection of your mouse coordinates and then doing a ray/plane intersect or something; GL_SELECT can be a bit slow at times but for a drawing application it could do just fine.

Similar Threads

  1. Window coordinates and polygon position
    By EnriqueP in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-18-2011, 04:08 AM
  2. Render polygon at mouse position
    By LukeSmith in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-02-2010, 03:58 PM
  3. how to change mouse position ,please help
    By haitian in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 11-28-2005, 10:42 PM
  4. How to get the mouse position ?
    By in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-01-2003, 08:05 PM
  5. Mouse Position
    By SeeDAreW in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-05-2002, 11:11 AM

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