hm, the line

f = -mouse_pos3d.z/dir.z;

seems to be giving me an error, it says "System Crash" whenever I run the program.
The fact that I'm dividing there seems to be the cause but I'm not sure why.