~GaLs~
† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
- Reaction score
- 180
This is just a small snippet made by me from converting the original natives.
Ofcourse, it is in Jass.
I just found it generally useful because it is quite frustating for every time search for the native and use the formula inside the native, so I made this snippet to make it easy for me, and now for everyone.
Enough of the stupid intro, lets take a look in the code!
*Below is the implementation instruction, it is not the real code!
*This is the real code!
Demo Map:
View attachment RealXY Demo Map.w3x
Feel free to criticize me, I know I am not the perfect one.
Ofcourse, it is in Jass.
I just found it generally useful because it is quite frustating for every time search for the native and use the formula inside the native, so I made this snippet to make it easy for me, and now for everyone.
Enough of the stupid intro, lets take a look in the code!
*Below is the implementation instruction, it is not the real code!
JASS:
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
//Implement
//Create a trigger name anything, delete everything inside it and copy this code inside.
//Usage
//It is the same as normal function calling, below is every detail of each function.
//Functions (This snippet contains of 4 functions)
//
//-------------------------------------------------------------------------------------------------------
//================================================================================
//== function DistanceBetweenXYl takes real x1, real y1, real x2, real y2 returns real ==
//================================================================================
//
//This function work the same way as the function "DistanceBetweenPoints".
//(function DistanceBetweenPoints takes location locA, location locB returns real)
//
//You can use it by just as same as calling DistanceBetweenPoints but replace the locations to real.
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
//========================================================================
//== function OffsetX takes real x1, real dist, real angle returns real ==
//========================================================================
//========================================================================
//== function OffsetY takes real y1, real dist, real angle returns real ==
//========================================================================
//
//These 2 functions works the same way as the function "PolarProjectionBJ".
//(function PolarProjectionBJ takes location source, real dist, real angle returns location)
//
//Since a function can't return 2 different value, I'll seperate to different functions.
//Unlike PolarProjectionBJ, you don't give the location as paremeter but each real to each function.
//
//Call "OffsetX" to find the polar offset of the location's X.
//Call "OffsetY" for the polar offset of the location's Y.
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
//===============================================================================
//== function AngleBetweenXY takes real x1, real y1, real x2, real y2 returns real ==
//===============================================================================
//
//This function works the same way as the function "AngleBetweenPoints".
//(function AngleBetweenPoints takes location locA, location locB returns real)
//
//Since that function takes 2 location as paremeter, this function takes 4 reals as paremeter. (X and Y axis per location)
//
//It is so easy to use it by just call it and replace the paremeter to the location's x-axis and y-axis.
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
*This is the real code!
JASS:
library RealXY
function DistanceBetweenXY takes real x1, real y1, real x2, real y2 returns real
return SquareRoot((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
endfunction
function OffsetX takes real x1, real dist, real angle returns real
return x1 + dist * Cos(angle * bj_DEGTORAD)
endfunction
function OffsetY takes real y1, real dist, real angle returns real
return y1 + dist * Sin(angle * bj_DEGTORAD)
endfunction
function AngleBetweenXY takes real x1, real y1, real x2, real y2 returns real
return bj_RADTODEG * (Atan2(y2 - y1, x2 - x1))
endfunction
endlibrary
Demo Map:
View attachment RealXY Demo Map.w3x
Feel free to criticize me, I know I am not the perfect one.