I would like to do precise picking on a sphere surface, converting mouse X,Y to world space XYZ point so that I can draw object at that coord. Sounds simple enough and it should be, but I need some help ;)
I have built this simple test snippet that would simply create a some geo at the point on a globe where the mouse click ray intersection occurs and its nearly working! Its taking my xy casting that along the projection angle, taking into account the modelView inv (camera pos) etc. The only thing that I have an issue is that intersection with the Y coordinate is upside-down, also strangely I have to swap the Z coord of the mouse ( so ray_start = [x,y,1] and ray_dest = [x,y,0] otherwise its rejected as pointing backwards .
So, that done, clicking around the equator of the sphere it plots the geo's nicely at the x and y moving orbit the camera left/right it works fine, but plotting above of the center screen creates geo points south or downward and clicking below center screen viceversa plots mirrored north . Simply swapping the final vector does not work as its the intersection thats matters. I know I am so close.. I looking at the computeWindow Matrix calculation as a potential culprit. I Just need a little more light I really appreciate some help if possible.
Many thanks for any help!
// window matrix function (where I think the problem could be)