C to Blitz help...

Miscellaneous Forums/General Discussion/C to Blitz help...

I'm converting a small program from C to Blitz3D. I don't actually know C so I'm just guessing most of it ;)

What would be the Blitz equivalent to this? Particuarly the last line...

  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);


That's not C, for starters, and that last line makes no sense in C or Blitz, AFAIK.

The last line makes no sense.. to get the rest of it working remove the semi colons.

The last line ^ is to the power of... but you've not got any value that you're applying to the power of to.

ie 2^7 makes sense ^7 makes no sense

I think maybe there's code missing from above it.

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

^ is the exclusive OR (XOR) operator, in C.

At a guess...
Function getHex(xcoord#, ycoord#)
	Local 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((h - 1) / 2.0)
	Else
	  ox = 1 + 2 * n + h
	  oy = 1 + Floor(h / 2.0)
	EndIf
	
	Return  (100 * ox + oy)
End Function
??