TheCyborg:
Yep It's correct, I typed "3D math" into google (in quotes) and I found several examples there.
As for placing your calculations on one line, your way is slightly slower because your function would be calculating things like x1-x2 twice, which, if you need this for gaming where speed is paramount, is small waste of clock cycles.
Consider this test:
+ Code Snippetsync on
sync rate 0
set text opaque
text 0,0,"Easily Confused's function:"
text 0,48,"TheCyborg's function:"
sync
repeat
rem --- Easily Confused's Test
count = 0 : ti = timer()
repeat
d#=Dist3DTest1(100,100,100,500,500,500)
inc count,1
until (timer() - ti) >= 1000
text 16,16,str$(count)+" calls per sec. "
sync
rem --- TheCyborg's Test
count = 0 : ti = timer()
repeat
d#=Dist3DTest2(100,100,100,500,500,500)
inc count,1
until (timer() - ti) >= 1000
text 16,64,str$(count)+" calls per sec. "
sync
until spacekey()
end
function Dist3DTest1(x1#,y1#,z1#,x2#,y2#,z2#)
xd# = x1# - x2#
yd# = y1# - y2#
zd# = z1# - z2#
Distance# = sqrt((xd#*xd#) + (yd#*yd#) + (zd#*zd#))
endfunction Distance#
function Dist3DTest2(x1#,y1#,z1#,x2#,y2#,z2#)
Distance#=SQRT(((x1#-x2#)*(x1#-x2#))+((y1#-y2#)*(y1#-y2#))+((z1#-z2#)*(z1#-z2#)))
endfunction Distance#
On my somewhat pathetic AMD 650, My function gets about 123000 calls per second, and yours about 121000. A small difference I know, but noticable.
I win, where's my prize!