Raised This Month: $ Target: $400
 0% 

wierd results from get_distance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
stupok
Veteran Member
Join Date: Feb 2006
Old 02-20-2007 , 17:33   Re: wierd results from get_distance
Reply With Quote #1

Why would you do that, Black Rose? btw, abs is absolute value, for example abs(-1) = 1

Code:
#include <amxmodx> public plugin_init() {     new integer_value = 1 - 2     new Float:float_value = 1.0 - 2.0     server_print("POWER: %i, %f", (integer_value * integer_value), (float_value * float_value))     server_print("DISTANCE: %i, %f", sqroot(integer_value * integer_value), floatsqroot(float_value * float_value)) }

Code:
POWER: 1, 1.000000
DISTANCE: 1, 1.000000
I'd wager that genesis is putting a %s where a %f should be or something along those lines. I doubt there is anything wrong with the distance functions.
stupok is offline
genesis
Senior Member
Join Date: Oct 2004
Location: CALIFORNIA, USA
Old 02-20-2007 , 23:28   Re: wierd results from get_distance
Reply With Quote #2

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); }
__________________
CS 1.6 cali.radclan.net:27015
I have a feeling we're not in cs anymore.
I take pride that all my AMXX plugins were writen in notepad.
genesis is offline
[ --<-@ ] 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 #3

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
mysticssjgoku4
Veteran Member
Join Date: Jan 2005
Location: Chicago Heights, IL
Old 02-26-2007 , 15:37   Re: wierd results from get_distance
Reply With Quote #4

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...
Negative square roots are imaginary numbers, therefore they don't exist.
The only way you get a -squareroot is by having a negative number.....and a negative number times itself is positive....so its not possible.

That may be why you are getting messed up results.
__________________


Last edited by mysticssjgoku4; 02-26-2007 at 15:39.
mysticssjgoku4 is offline
Send a message via AIM to mysticssjgoku4 Send a message via MSN to mysticssjgoku4
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