PICK OBJECT This command will return the Object Number of the closest object at the specified screen coordinates.
Syntax
    Return Integer=PICK OBJECT(Screen X, Screen Y, Object Start, Object End)
    Return Integer=PICK OBJECT(Screen X, Screen Y, Object Start, Object End, Ignore Camera Flag)
Parameters
    Screen X
Integer This value is an integer number such as 1.
    Screen Y
Integer This value is an integer number such as 1.
    Object Start
Integer This value is an integer number such as 1.
    Object End
Integer This value is an integer number such as 1.
    Ignore Camera Flag
Integer Specify a value of zero to disable, and a value of one to enable.
Returns
This command will return the Object Number of the closest object at the specified screen coordinates
Description
The objects that are tested against the 2D coordinate are only those within the Object Start and Object End range in order to speed up specific tests. If no object exists at the coordinate, a value of zero is returned. If an object number is returned, additional data will be generated and stored internally. This extra data can be retrieved using the GET PICK VECTOR and GET PICK DISTANCE commands. Be aware that there may be multiple cameras when picking objects. To make sure you are selecting the correct screen object, use the SET CURRENT CAMERA command for the screen being rendered by that camera view. Do not use extreme camera range or object distances with this command, as this increases the inaccuracy of the raycast line being used internally. You can specify an optional parameter to ignore the camera orientation, which is usefulfor selecting objects that also ignore the influences of the camera.
Example Code
    sync on : sync rate 60

    make object plain 1,300,300

    position object 1,0,-50,0

    xrotate object 1,270

    make object cube 2,100

    set shadow shading on 2

    set point light 0,-100,500,-100

    position camera -200,0,-200

    point camera 0,0,0

    x#=0:y#=0:z#=0

    do

    set cursor 0,0

    if mouseclick()=0 then pickmode=0

    if mouseclick()>0

    if pick object(mousex(),mousey(),2,2)>0

    if pickmode=0

    d#=get pick distance()

    x#=get pick vector x():y#=get pick vector y():z#=get pick vector z()

    print "object x ",x#," object y ",y#," object z ",z#," distance ",d#

    inc pickmode

    endif

    endif

    if pickmode=1

    pick screen mousex(),mousey(),d#

    dx#=x#-get pick vector x():dy#=y#-get pick vector y():dz#=z#-get pick vector z()

    print dx#," ",dy#," ",dz#

    endif

    position object 2,dx#,dy#,dz#

    endif

    print x#," ",y#," ",z#

    print "CLICK AND HOLD OBJECT TO DRAG"

    sync

    loop

    end
See also
BASIC3D Commands Menu Index