Jump to content


Photo

Angle Difference Script


  • Please log in to reply
11 replies to this topic

#1 ninja_x

ninja_x

    GMC Member

  • GMC Member
  • 276 posts

Posted 15 July 2008 - 05:27 PM

Edit: Removed the script. I tried using it today and didn't work properly, which is pretty bad considering how long it's been up here. I didn't feel like debugging my approach since the post below has a completely good solution, which I'd recommend using instead.

Edited by ninja_x, 23 May 2012 - 04:49 PM.

  • 0

#2 Mnementh

Mnementh

    15151

  • GMC Member
  • 6328 posts
  • Version:GM:Studio

Posted 15 July 2008 - 05:43 PM

*cough*

/*
**  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.
  • 0

#3 ninja_x

ninja_x

    GMC Member

  • GMC Member
  • 276 posts

Posted 15 July 2008 - 06:12 PM

...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...
  • 0

#4 Mnementh

Mnementh

    15151

  • GMC Member
  • 6328 posts
  • Version:GM:Studio

Posted 15 July 2008 - 06:47 PM

Yea... If it's any consolation, I still have no idea how their script works, while yours is easy to understand.

Edited by Mnementh, 15 July 2008 - 06:47 PM.

  • 0

#5 BK-TN

BK-TN

    GMC Member

  • New Member
  • 5 posts

Posted 03 June 2010 - 02:23 PM

This works, thanks alot!
  • 0

#6 yanai21

yanai21

    GMC Member

  • New Member
  • 44 posts

Posted 06 June 2010 - 04:37 PM

all angle diffrent is not relly fast =\ i make one :

return (argument0-argument1)-round((argument0-argument1)/360)*360;

its only 5 operators\functions :P i 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 fps :( its what you should..
  • 0

#7 LSnK

LSnK

    NaN

  • GMC Member
  • 1188 posts

Posted 08 June 2010 - 01:29 AM

all angle diffrent is not relly fast =\ i make one :


return (argument0-argument1)-round((argument0-argument1)/360)*360;

its only 5 operators\functions :P i 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 fps :) its what you should..

Your code is 1.45 times slower than the GMLscripts version.
  • 0

#8 DanRedux

DanRedux

    GMC Member

  • GMC Member
  • 1403 posts
  • Version:GM:Studio

Posted 08 June 2010 - 02:40 AM

Does his script work correctly?

This would be more efficient..

return ( argument0 - argument1 ) - ( argument0 - argument1 ) div 360
  • 0

#9 slayer 64

slayer 64

    GMC Member

  • GMC Member
  • 3833 posts
  • Version:GM8.1

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.
  • 0

#10 DanRedux

DanRedux

    GMC Member

  • GMC Member
  • 1403 posts
  • Version:GM:Studio

Posted 10 June 2010 - 04:16 AM

Haha! Oh, slayer. <3
  • 0

#11 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Member
  • 15785 posts
  • Version:GM:Studio

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 :)
  • 0

#12 sneaky666

sneaky666

    536e65616b79

  • GMC Member
  • 1045 posts
  • Version:GM:Studio

Posted 30 December 2011 - 07:06 PM

If you want the difference to be between 0 and 180, then see this:

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users