A copy and paste of the source code is better.
You would need to add the viewports view location onto the mouse position.
So if the viewport was viewing +50 from your world origin, mousex+50.
You might be able use the camera's location for this, unless your moving the world around and camera remains stationary. in that event you would need to use the offset of the world.