View Full Version : Get the Polygon Mouse Position
10-27-2009, 08:33 AM
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....?
10-27-2009, 09:37 AM
Actually gluUnproject just performs the matrix operation described here (http://www.opengl.org/sdk/docs/man/xhtml/gluUnProject.xml). 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.
10-28-2009, 12:26 AM
can u please explain me how to perform additional depth pass to removing a object from the rendering batch?
10-28-2009, 12:44 PM
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.
10-29-2009, 02:36 AM
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...
10-29-2009, 03:50 PM
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.
10-31-2009, 01:19 AM
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.....
10-31-2009, 08:13 AM
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.
11-01-2009, 01:26 AM
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
11-01-2009, 02:04 PM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.