Below is a comparing program. Admiral - you're a genius. The new method is definitely faster. However, I'm starting to wonder how much it matters - but, if you know a faster way, why not use it?
REM nothing new here, I just combined the two to add in Admiral's code
SystemGetDistance3DSetup()
rem Create objects
make object cube 1, 10 : position object 1, rnd(1000), rnd(1000), rnd(1000)
make object cube 2, 10 : position object 2, rnd(1000), rnd(1000), rnd(1000)
backdrop off
Restart:
cls
rem Calculate Vector-Time
t = timer()
for x = 1 to 99999
REM i and j are the dbpro object numbers
dist# = systemGetDistance3D(1,2)
next x
t1 = timer()-t
rem Show info
print "Time needed for Vector-Calculations: ", t1, " ms"
print "Dist# = ", dist#
sync
rem Calculate SQRT-Time
t = timer()
for x = 1 to 99999
dist# = GetSQRTObjectDistance(1,2)
next x
t2 = timer()-t
print "Time needed for SQRT-Calculation: ", t2, " ms"
print "Dist# = ", dist#
rem Calculate Admiral's Vectors
t = timer()
for x = 1 to 99999
dist# = vecdistance(1,2)
next x
t3 = timer()-t
print "Time needed for Admiral's Vector-Calculation: ", t3, " ms"
print "Dist# = ", dist#
print
print "Press space to run it again, any other key to exit."
sync
rem Get key
repeat : until scancode()=0
repeat
s = scancode()
until s <> 0
if s=57 then goto Restart
end
`uses vectors to find the distance between two objects
function vecdistance(obja,objb)
`object data
x1#=object position x(obja)
y1#=object position y(obja)
z1#=object position z(obja)
x2#=object position x(objb)
y2#=object position y(objb)
z2#=object position z(objb)
`calculations
xdist# = x1#-x2#
ydist# = y1#-y2#
zdist# = z1#-z2#
set vector3 1,xdist#,ydist#,zdist#
distance# = length vector3(1)
endfunction distance#
function GetSQRTObjectDistance(i,j)
xd# = object position x(j)-object position x(i)
yd# = object position y(j)-object position y(i)
zd# = object position z(j)-object position z(i)
dis# = sqrt(xd#^2+yd#^2+zd#^2)
endfunction dis#
function systemGetDistance3D(i,j)
local dist# as float
set vector3 systemVector3A, object position x(i), object position y(i), object position z(i)
set vector3 systemVector3B, object position x(j), object position y(j), object position z(j)
subtract vector3 systemVector3C, systemVector3A, systemVector3B
dist# = length vector3(systemVector3C)
endfunction dist#
function systemGetDistance3DSetup()
#constant systemVector3A 1
retval = make vector3(systemVector3A)
#constant systemVector3B 2
retval = make vector3(systemVector3B)
#constant systemVector3C 3
retval = make vector3(systemVector3C)
endfunction
http://forum.thegamecreators.com/xt/xt_apollo_pic.php?i=1234759