# yet another stupid post on RAY PICKING

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

## Recommended Posts

hi guys
i have to ray pick some points on the screen with JOGL.
i want to use gluUnproject cause i think it is better way instead of selection buffer.

i have 3 points in world (3d) space:
x1: eye's coordinate
x2: mouse coordinate on near plane
x0: point to test

i have to get the distance between between line x1-x2 and see the difference between x0, with this formula:
http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html

now..

firstofall:
glu.gluPerspective(45.0f, h, 1.0, 20.0); //near plane is at: 1.0Vector3D x0 = new Vector3D(0.6, 1, 2); // my target point

x1:
glu.gluUnProject(width/2, height/2, 0, mvmatrix, 0,projmatrix, 0, viewport, 0, wcoord, 0);

because my eye's coordinate is at the center of the screen at z = 0, right?
x2:
glu.gluUnProject( mouseX,  height-mouseY, 1, blabla);

because my mouse is on my near plane at z = 1.0

and then math for distance between point and line

..
where am i wrong??
the result is not good.. i thought it should be perfectly calculated but i have to add some offset to get distance <0.2 exactly where is the point..
hope some of you can help me despite my bad english

[Edited by - nkint on December 22, 2010 2:07:17 PM]

##### Share on other sites
ok if i put mouse coordinate z (3° input in gluUnproject) as 0.8 instead of 1
everything is ok.

why? ho can i calculate the exactly z value with other canvas dimension or different projections matrix?

##### Share on other sites
ok i got it it was stupid : )
picking ray needs to be horizzontal to clipping cube

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632936
• Total Posts
3009312
• ### Who's Online (See full list)

There are no registered users currently online

×