ray tracing

I am using gluLookAt to position my camera:
and using gluPerspective(fovy,(GLdouble) window_width/window_height,cnear,cfar); to setup perspective…
I have been working on some 3D geometry and try to do ray tracing (effectively come up with a map from my “PIXEL” coordinate (where I clicked on screen) to the MODEL coordinate)…but my algorithm is off by a little bit…anyone know a good and accurate algorithm that does this?
I want to be able to shoot a ray from my projection point to my clicked point…

thank you!!