Archived

This topic is now archived and is closed to further replies.

SpiralGuru3d

Picking

Recommended Posts

SpiralGuru3d    122
Hey everybody, I''m having some trouble with my picking routine. I use the same camera setup when picking as I do when setting up the projection matrix for rendering (I am using D3D, though this is not API dependent). I pass the FOV and near z value as variables, and calculate the view plane width and height from these values. I specify the horizontal FOV, and it forces a 4:3 aspect ratio from that. With FOV 90 and a near-z of 5, the view plane width is 10, and 7.5 high. When picking, I take the screen coords clicked, map them to view plane coords (-5 to 5 and 3.75 to -3.75 since y is up in my world), and deproject a vector from the camera position, through this point in the view plane and out into the world. I intersect that line with the ground plane (y=0). I''ve done that math for THAT 3 different ways, and I know it''s not wrong. To generate the vector I take: vDir = fViewX * cam.xAxis + fViewY * cam.yAxis + fNearZ * cam.zAxis; When I click in the dead centre of the screen, it deprojects into the world at the exact point I require (am clicking on). The further I click from the screen''s centre, the worse the error gets. Can anybody offer any ideas for how I might debug this? Verifying the camera view plane does indeed rest how I explained it would also be good, though I''m sure I''ve got that part right. Many thanks, sorry for the long post! =) -Spiral P.S If you are just stopping by, wish me luck! =p -- Give me a hard copy right there ---

Share this post


Link to post
Share on other sites
EgonOlsen    145
Looks reasonable and i think i''m doing it almost the same way (except that it works in my case ). Are you sure that your view plane dimensions are correct?

Share this post


Link to post
Share on other sites
SpiralGuru3d    122
Thanks

Well, I pass the FOV and the near z, and get half the view plane width with TAN(FOV) * fNearZ.

The width is thus twice that, and the height, 0.75 of that...since our resolution is n 4:3 aspect ratio.

Do you have any small code snippets?

-Spiral


-- Give me a hard copy right there ---

Share this post


Link to post
Share on other sites
EgonOlsen    145
Sorry, no code...the code is at home and i''m not. What kind of error do you get exactly? If you try to pick the polygon on the leftmost border for example...where does your picking actually end up?

Share this post


Link to post
Share on other sites
SpiralGuru3d    122
Picking in the centre of the screen works fine.

Working outward from this point, in any direction, the actual point that is picked lags behind where I''m clicking.

The further from the screen centre I go (i.e. the more the pick ray and camera z-axis diverge), the greater the error..


I can''t even think how to debug it! =)

-Spiral


-- Give me a hard copy right there ---

Share this post


Link to post
Share on other sites
EgonOlsen    145
Well, i would try to find out if the error is linear, i.e. multiply fViewX and -Y with a scalar and try to find a value that fixes the problem. Whether this works or not may be used as an indicator that either something very simple is wrong (like the dimension/FOV-stuff...albeit it looks ok to me at first glance) or that the problem is located elsewhere (maybe in the logic, maybe in the raycasting code itself).
Anyway, i wish you luck...i have to go to bed now

[edited by - EgonOlsen on September 30, 2002 7:22:32 PM]

Share this post


Link to post
Share on other sites
SpiralGuru3d    122
Yes, I was doing FOV / 2 as required.

Hey, I forgot about that example! Sorry!

After working through my code alongside the sample, I eventually identified my view and projection matrices as being slightly out. I was putting the right data in the right places, but my axes were not quite orthogonal (error elsewhere).

I''ve fixed that up, and it''s picking perfectly!


Thanks for the help, it''s good to have folks to bounce off when you''ve got something that *seems* very odd going on! =)

-Spiral


-- Give me a hard copy right there ---

Share this post


Link to post
Share on other sites