EntityDistance speed...
Blitz3D Forums/Blitz3D Programming/EntityDistance speed...
| ||
Graphics3D 800,600,32,0 Global mesh1=CreateCube() Global mesh2=CreateSphere() Function EntityDistanceWorld#(mesh1, mesh2, xzOnly=False) x#=EntityX(mesh1,True) y#=EntityY(mesh1,True) z#=EntityZ(mesh1,True) x2#=EntityX(mesh2,True) y2#=EntityY(mesh2,True) z2#=EntityZ(mesh2,True) Return Sqr#((x2-x)*(x2-x)+(y2-y)*(y2-y)+(z2-z)*(z2-z)) End Function Function EntityDistanceWorldPLUS#(mesh1, mesh2, xzOnly=False) Return BP_Distance3d(EntityX(mesh1,True),EntityY(mesh1,True),EntityZ(mesh1,True),EntityX(mesh2,True),EntityY(mesh2,True),EntityZ(mesh2,True)) End Function sm=MilliSecs() For i=1 To 1000000 EntityDistance(mesh1,mesh2) Next Print "Blitz3d(Local): "+(MilliSecs()-sm) sm=MilliSecs() For i=1 To 1000000 EntityDistanceWorldPLUS(mesh1,mesh2) Next Print "Blitz3d+: "+ (MilliSecs()-sm) sm=MilliSecs() For i=1 To 1000000 EntityDistanceWorld(mesh1,mesh2) Next Print "World function: "+ (MilliSecs()-sm) WaitKey End What's the fastest way to get entitydistance in world space?and why blitz3d standard function doesn't have a world flag? At the moment I'm using Blitz3d+.dll for a better performance, btw standar B3d Entitydistance would be the best option if it just had world space calculations... |
| ||
Erm, i thought entity distance told you the distance between two entities. That doesn't matter if it's global or local, as the distance is the same. |
| ||
Edit: Ops.. you are right :) nevermind.. btw blitz3d+ function is faster when not using entitydistance. |
| ||
Ah nice to know, thanks! |
| ||
If all you want to know is which entity is closest (regardless of distance), then you can drop the Sqr() to speed it up further. |
| ||
btw blitz3d+ function is faster when not using entitydistance. What do you mean by that? and I haven't tested it, but I think it's rather strange that a DLL function is faster than an internal one... are you sure about the results? |
| ||
I mean...when you you have two test the distance between two points, it is faster to use b3d+ than a custom blitz coded function. |
| ||
GfK if you drop the Sqr, then you may also drop the ^2 Multiplication, no? |
| ||
GfK if you drop the Sqr, then you may also drop the ^2 Multiplication, no? No. Unless you only want to know the distance on one plane.(although x*x is faster than x^2). |
| ||
Just in case anyone is confused by the reference to 'Blitz3D+', it relates to this: http://www.blitzbasic.com/Community/posts.php?topic=75711 "Billp" never reappeared after that thread, almost like it was a parting gift. |