I suddenly got the urge to summarize it all up for a bit, so here I go:
Finding 3D point from screen coordinates at a certain distance
To find a 3D point under a screen coordinate at a certain distance
Distance# you can use the command
pick screen X, Y, Distance#
The calculated vector is relative to the camera's position, and can be retrieved using
get pick vector x/y/z()
So to get the world coordinates (not relative to the camera) you just add the position of the camera:
`Find 3D position at screen coordinates (X, Y)
pick screen X, Y, Distance#
WorldX# = camera position x() + get pick vector x()
WorldY# = camera position y() + get pick vector y()
WorldZ# = camera position z() + get pick vector z()
Finding 3D point from screen coordinates at a certain height
Basically, the method is the same as the previous, but you rescale the vector so that the y-component of the pick vector is fixed. Let's say that we want to find the point at height
h#.
`First find 3D point at distance 1.0 (so the vector is actually normalized)
pick screen X, Y, 1
`Rescale the vector so that the y-component has the right size and add it to the camera position to find the world coordinates
Scale# = (h# - camera position y()) / get pick vector y()
WorldX# = camera position x() + (get pick vector x() * Scale#)
`WorldY# = camera position y() + (get pick vector y() * Scale#) but this will just give:
WorldY# = h#
WorldZ# = camera position z() + (get pick vector z() * Scale#)
Finding 3D point from screen coordinates on an object
Instead of using pick screen, you just use
pick object(
X, Y, StartObj, EndObj)
This command will check whether or not (X, Y) is over an object starting from
StartObj and ending with
EndObj. If an object is found, the command will return that object number, and will store the 3D intersection data in the pick vector commands.
Example:
`Check whether or not the mouse hovers any object between 1 and 15, and if it does, find the 3D point where the mouse points to on that object
if pick object(mousex(), mousey(), 1, 15) > 0
`Store coordinates of intersection point with mouse cursor
WorldX# = camera position x() + get pick vector x()
WorldY# = camera position y() + get pick vector y()
WorldZ# = camera position z() + get pick vector z()
end
There are unlimited possibilities...
Sven B