Raised This Month: $ Target: $400
 0% 

wierd results from get_distance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 02-21-2007 , 00:56   Re: wierd results from get_distance
Reply With Quote #1

Quote:
Originally Posted by genesis View Post
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.

Last edited by [ --<-@ ] Black Rose; 02-21-2007 at 01:36.
[ --<-@ ] Black Rose is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:35.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode