Here's the whole function/thingy
int getHex(_xcoord, _ycoord)
float _xcoord, _ycoord;
{
int t,n,ox,oy,h,e,x;
h = get_H(_xcoord, _ycoord);
e = get_E(_xcoord, _ycoord);
x = get_X(_xcoord, _ycoord);
/* t will be the E value of the <base> triangle */
t := e + h - x + ((((x-2*h) mod 3)+3) mod 3);
/* <hex> = <base> + n*<0,3,3> + get_H()*<1,1,2> */
n := floor( (x - 2*h - ((((x-2*h) mod 3)+3) mod 3))/3.0 );
if (t > 0) then
ox = 2 + 2 * n + h;
oy = 1 + floor( ((float)(h-1))/2.0);
else
ox = 1 + 2 * n + h;
oy = 1 + floor( ((float)(h))/2.0 );
endif;
^( 100 * ox + oy);
}I don't know C so I wasn't 100% sure what it is... After reading a bit more it seems to be Actor, never heard of it LOL...
Actually, while I'm posting... This is what I'm working on...
Function HexToX# (H#)
Local TX#
TX = H/100
Return 1/(2*Sqr(3)) + (TX-1)*(Sqr(3)/2)
End Function
Function HexToY# (H#)
Local TY#,TX#
TX = (H/100)
TY = H Mod 100
Return TY-0.5*(TX Mod 2)
End Function
Function GetAngle (ThisHex,TargetHex)
Local T#,DX#,DY#
DX = HexToX (TargetHex) - HexToX (ThisHex)
DY = HexToY (ThisHex) - HexToY (TargetHex)
If DX = 0
If DY >= 0
Return 90
Else
Return 270
EndIf
EndIf
T = RadToDeg (Tan(DY/DX))
If T >= 0
If DX > 0
Return (T+0.5)
Else
Return (T+0.5+180)
EndIf
Else
If DX > 0
Return (T+360+0.5)
Else
Return (180+T+0.5)
EndIf
EndIf
End Function
Function RadToDeg# (X#)
Return (X*57.29578)
End Function
Function DegToRad# (X#)
Return (X/57.29578)
End Function
Print GetAngle (0102,0201);30
Print GetAngle (0102,0101);90
Print GetAngle (0102,0202);330
WaitKey()
The ;30 90 and 330 are the values I'm expecting but it doesn't work. My maths isn't too sharp so I can't tell if I'm doing it right, just my best guess.
Here's the bit I'm trying to convert...
http://www-cs-students.stanford.edu/~amitp/Articles/Hexagon1.html