@ paul5147
That is very inefficient code. You don't need the square root, you can use the "fast" pythagoras method. x^2 is slower than x*x. And you don't need the abs() function, because something ^2 is always positive.
@ Mathew_wi
Untested, but this should find the closest object:
function GetClosestObject(objects)
rem get camera positions
cx#=camera position x()
cy#=camera position y()
cz#=camera position z()
rem set this as high as possible
closest_dist#=99999999
rem find closest object
closest=0
for t=1 to objects
rem get positions of current object
x#=object position x(t)
y#=object position y(t)
z#=object position z(t)
rem subtract object positions from camera positions
dec x#,cx#
dec y#,cy#
dec z#,cz#
rem calculate distance, and compare with closest distance
dist#=x#*x#+y#*y#+z#*z#
if closest_dist#>dist#
closest_dist#=dist#
closest=t
endif
next t
endfunction closest
It should return the closest object to the camera. You must specify how many objects there are with
objects. Higher objects aren't checked. So if you have an object 5000, and you set
objects to 4000, any objects above 4000 won't be checked, so object 5000 won't be checked.
TheComet