How does GetCursorPos() really work?

Hi All!
I am new here on the Rhino forum, however I am not new Rhino user.
Recently I started to play with Python scripting and now I wonder how does the GetCursorPos() function work, more precisely: in what way are 2D screen coordinates translated to world/3D coordinates?

I’ve created a script that puts a line between camera position and cursor position:

import rhinoscriptsyntax as rs
def main():
    something=rs.GetPoint("indicate point")
    cursordata=rs.GetCursorPos()
    if not cursordata: return
    rs.AddLine(rs.ViewCamera(),cursordata[0])
if __name__ =="__main__":
    main()

The effect is visible below:


Here I “shooted” lines towards the same object (camera target was set at it), with the same zoom, but at different angles. And lengths of the lines are completely different!
Can anybody answer how is depth of the cursor position calculated in the GetCursorPos() function?

Regards,
Andrzej

Hey Andrzej,

So I was doing some testing and it looks like GetCursorPos returns the position in the world at the nearest clipping plane.

Before running your script:

After:

You can see the line stops where the near clipping plane used to be, and zooming in to the camera location, the near clipping plane has moved:
image

And re-running your script validates this:
image

So when you were rotating around the object, the camera’s clipping planes were changing and thus the seemingly random lines.

This is definitely odd behaviour because I was also wondering what world coordinates the GetCursorPos returns, since it definitely wasn’t the coordinates in the bottom left (on the status bar when set to world).