Re: pack/unpack pos to binary
function packpos(x, y, z)
x = 819200+math.floor(x*100) -- -8192 - 8192 3 byte
y = 819200+math.floor(y*100)
z = math.floor(1300*65535/(z+100)) -- -100 - 1200 2 byte
return string.byte(
x, BitExtract(x, 8, 8), BitExtract(x, 16, 8)
8),
y, BitExtract(y, 8, 8), BitExtract(x, 16, 8),
z, BitExtract(z, 8, 8))
end
function unpackpos(string, startindex)
local x1, x2, x3, y1, y2, y3, z1, z2 = string:byte(startindex, startindex + 7)
return ((x1 + x2*256 + x3*65536) - 819200)/100,
((y1 + y2*256 + y3*65536) - 819200)/100,
(z1 + z2*256)/65535*1300 - 100
end
Replies to Re: pack/unpack pos to binary
{"text":"text","html5":"html","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"lua","bash":"sh","erlang":"erlang","go":"golang","c":"c_cpp","cpp":"c_cpp","diff":"diff","latex":"latex","sql":"sql","xml":"xml","0":"text","abap":"abap","actionscript":"actionscript","actionscript3":"actionscript","ada":"ada","apache":"apache_conf","applescript":"applescript","asm":"assembly_x86","autohotkey":"autohotkey","closure":"closure","cobol":"cobol","coffeescript":"coffee","cpp-winapi":"c_cpp","c_loadrunner":"c_cpp","c_mac":"c_cpp","c_winapi":"c_cpp","csharp":"csharp","d":"d","dart":"dart","dot":"dot","eiffel":"eiffel","fortran":"fortran","groovy":"groovy","haskell":"haskell","haxe":"haxe","ini":"ini","io":"io","java":"java","java5":"java","make":"makefile","matlab":"matlab","mysql":"mysql","objc":"objectivec","ocaml":"ocaml","pascal":"pascal","perl":"perl","perl6":"perl","postgresql":"pgsql","powershell":"powershell","prolog":"prolog","properties":"properties","rails":"ruby","rust":"rust","scala":"scala","scheme":"scheme","smarty":"smarty","tcl":"tcl","vala":"vala","vb":"vbscript","verilog":"verilog","vhdl":"vhdl","yaml":"yaml"}