Edited by ninja_x, 23 May 2012 - 04:49 PM.
Angle Difference Script
#1
Posted 15 July 2008 - 05:27 PM
#2
Posted 15 July 2008 - 05:43 PM
/*
** usage:
** diff = angle_difference(angle1,angle2);
**
** given:
** angle1 first direction in degrees, real
** angle2 second direction in degrees, real
**
** returns:
** difference of the given angles in degrees, -180 to 180
**
** GMLscripts.com
*/
{
return ((((argument0 - argument1) mod 360) + 540) mod 360) - 180;
}I applaud you for the effort, however.
#3
Posted 15 July 2008 - 06:12 PM
They even had the same name for the function.
But they did it in 1 line.
Well, I suppose there's some moral to this story, to always look for general scripts on GMLscripts.com before making them myself. So thanks for pointing that out.
I wonder if this makes my homing scripts obsolete as well...
#4
Posted 15 July 2008 - 06:47 PM
Edited by Mnementh, 15 July 2008 - 06:47 PM.
#5
Posted 03 June 2010 - 02:23 PM
#6
Posted 06 June 2010 - 04:37 PM
return (argument0-argument1)-round((argument0-argument1)/360)*360;
its only 5 operators\functions
Ray without DLL you can make RAY in slower computer 60\60 fps
#7
Posted 08 June 2010 - 01:29 AM
Your code is 1.45 times slower than the GMLscripts version.all angle diffrent is not relly fast =\ i make one :
return (argument0-argument1)-round((argument0-argument1)/360)*360;
its only 5 operators\functionsi make and i was see it in different engine and like that 0.0 i only publish is in my engine
Ray without DLL you can make RAY in slower computer 60\60 fpsits what you should..
#8
Posted 08 June 2010 - 02:40 AM
This would be more efficient..
return ( argument0 - argument1 ) - ( argument0 - argument1 ) div 360
#9
Posted 10 June 2010 - 02:09 AM
Does his script work correctly?
This would be more efficient..
return ( argument0 - argument1 ) - ( argument0 - argument1 ) div 360
you could not use any code at all, that would be super efficient and it would do the same thing, not work.
#10
Posted 10 June 2010 - 04:16 AM
#11
Posted 10 June 2010 - 04:33 AM
...oh.
They even had the same name for the function.
But they did it in 1 line.
Well, I suppose there's some moral to this story, to always look for general scripts on GMLscripts.com before making them myself. So thanks for pointing that out.
I wonder if this makes my homing scripts obsolete as well...
Yeah, I duped the one they call lerp... In my defence, I had no idea the method I was implementing was called lerp
Oh and I added a post in you turn script
#12
Posted 30 December 2011 - 07:06 PM
c_time = current_time;
for(i=-1000;i<=1000;i+=1) {
for(j=-1000;j<=1000;j+=1) {
val = abs(((((i - j) mod 360) + 540) mod 360) - 180);
}
}
show_message((current_time-c_time)/1000); // time was 7.29 seconds
c_time = current_time;
for(i=-1000;i<=1000;i+=1) {
for(j=-1000;j<=1000;j+=1) {
val = abs((i + 180 - j) mod 360 - 180);
}
}
show_message((current_time-c_time)/1000); // time was 6.49 seconds
So the bottom one was faster. If you want it to be from -180 to 180, then I think you can just remove the abs() from either.
Edited by sneaky666, 30 December 2011 - 08:44 PM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











