yet another stupid post on RAY PICKING

Started by
1 comment, last by nkint 13 years, 4 months ago
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]
Advertisement
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?
ok i got it it was stupid : )
picking ray needs to be horizzontal to clipping cube

This topic is closed to new replies.

Advertisement