Quote:
Originally Posted by genesis
i dont think it should matter (mathematically) whether x1 >= x2 because lets say it isn't
Assume x1 = -5 and x2 = 2, adding them together will give -3, well distances can't be negative right, but then you square that, and anything squared is positive so it shouldn't matter, however, somewhere in the programming it may get messed up, I ended up ripping out a function out of a plugin on the forums the one that lets you voice chat to only nearby players... this method DOES work and works well...
Code:
stock Float:vecdist(Float:vec1[3], Float:vec2[3])
{
new Float:x = vec1[0] - vec2[0]
new Float:y = vec1[1] - vec2[1]
new Float:z = vec1[2] - vec2[2]
x*=x;
y*=y;
z*=z;
return floatsqroot(x+y+z);
}
|
-5 - 3 = -7, subtraction not addition.
No it doesn't
Code:
stock Float:vecdist(Float:vec1[3], Float:vec2[3])
{
new Float:x = vec1[0] - vec2[0]
new Float:y = vec1[1] - vec2[1]
new Float:z = vec1[2] - vec2[2]
x*=x;
y*=y;
z*=z;
return floatsqroot( x + floatsqroot(y+z) * floatsqroot(y+z) );
}
Code:
stock _get_distance(const Origin1[3], const Origin2[3]) {
new Diff[3]
Diff[0] = Origin1[0] - Origin2[0]
Diff[1] = Origin1[1] - Origin2[1]
Diff[2] = Origin1[2] - Origin2[2]
Diff[0] *= Diff[0]
Diff[1] *= Diff[1]
Diff[2] *= Diff[2]
new Temp = sqroot(Diff[0] + Diff[1])
return sqroot(Diff[2] + Temp * Temp)
}
stock Float:_get_distance_f(const Float:Origin1[3], const Float:Origin2[3]) {
new Float:Diff[3]
Diff[0] = Origin1[0] - Origin2[0]
Diff[1] = Origin1[1] - Origin2[1]
Diff[2] = Origin1[2] - Origin2[2]
Diff[0] *= Diff[0]
Diff[1] *= Diff[1]
Diff[2] *= Diff[2]
new Float:Temp = floatsqroot(Diff[0] + Diff[1])
return floatsqroot(Diff[2] + Temp * Temp)
}
Seems to work.