So basically doing it accurately requires matrix math and stuff
Here is Port's implementation of the matrix functions required to do this
https://github.com/portify/projectionThen here's a function I made to get the location that you clicked at
function RRscreenToWorld(%x, %y)
{
%xFac = getWord(getRes(), 0)/2;
%yFac = getWord(getRes(), 1)/2;
%newX = (%x - %xFac) / %xFac;
%newY = -(%y - %yFac) / %yFac;
%start = projectScreenToWorld(%newX SPC %newY SPC "-1 1");
%end = projectScreenToWorld(%newX SPC %newY SPC "0.999999 1");
%mask = $TypeMasks::All;
%player = serverConnection.getControlObject();
%scanTarg = containerRaycast(%start, %end, %mask, %player);
if(!%scanTarg)
{
echo("No intersection!");
return;
}
%pos = posFromRaycast(%scanTarg);
return %pos;
}
Where %x and %y are the cursor's (x,y)
Also for background on how it actually works, look up the pipeline for how OpenGL renders. It basically reverses this process.
