Okay, here is some example code for you. This creates 59 'trees' (boxes) and places them randomly. Use the arrow keys to move around. The tree closest to the camera will turn red. The one farthest away will turn green.
Rem Project: Dark Basic Pro Project
Rem Created: Saturday, January 29, 2011
Rem ***** Main Source File *****
sync on : sync rate 60
randomize timer()
global NearObj, FarObj
#constant myvect 1
null = make vector3(myvect)
type TreePostions
treeX# as float
treeZ# as float
treeObj as integer
endtype
rem make array stor x and z positions and set it to 58 as a total number of objects
dim TreeArray(58) as TreePostions
for i = 0 to 58
TreeArray(i).TreeObj = 1000 + i
make object box TreeArray(i).TreeObj,5,15,5
color object TreeArray(i).TreeObj,rgb(128,128,128) : set object ambience TreeArray(i).TreeObj,rgb(128,128,128)
position object TreeArray(i).TreeObj,rnd(500),0,rnd(500)
NEXT i
OldNearObj = TreeArray(0).TreeObj
OldFarObj = TreeArray(1).TreeObj
repeat
control camera using arrowkeys 0,2,1
Nearest# = 1000.0 : NearObj = -1 : Farthest# = 0.0 : FarObj = -1
for tree = 0 to 58
dist# = CheckDistance(tree)
if dist# < Nearest# then Nearest# = dist# : NearObj = TreeArray(tree).TreeObj
if dist# > Farthest# then Farthest# = dist# : FarObj = TreeArray(tree).TreeObj
NEXT tree
color object OldNearObj,rgb(128,128,128) : set object ambience OldNearObj,rgb(128,128,128)
color object OldFarObj,rgb(128,128,128) : set object ambience OldFarObj,rgb(128,128,128)
oldNearObj = NearObj : OldFarObj = FarObj
color object NearObj,rgb(255,0,0) : set object ambience NearObj,rgb(255,0,0)
color object FarObj,rgb(0,255,0) : set object ambience OldFarObj,rgb(0,255,0)
text 10,50,"Nearest# = " + str$(Nearest#,1)
text 10,70,"NearObj = " + str$(NearObj)
text 10,90,"Farthest# = " + str$(Farthest#,1)
text 10,110,"FarObj = " + str$(FarObj)
sync
UNTIL mouseclick() > 0
end
function CheckDistance(Tree)
set vector3 1,(object position x(TreeArray(tree).treeObj) - camera position x()),(object position y(TreeArray(tree).treeObj) - camera position y()),(object position z(TreeArray(tree).treeObj) - camera position z())
dist# = length vector3(1)
endfunction dist#
Hope this helps,
LB