matrix_to_facedir.lua 724 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. -- Code by Pedro Gimeno, donated to the public domain.
  2. -- Big thanks to entuland for making it much easier to create the table.
  3. local facedirs = {
  4. [-246] = 19;
  5. [-244] = 10;
  6. [-242] = 4;
  7. [-240] = 13;
  8. [ -90] = 21;
  9. [ -82] = 20;
  10. [ -80] = 22;
  11. [ -72] = 23;
  12. [ -36] = 7;
  13. [ -30] = 18;
  14. [ -24] = 12;
  15. [ -18] = 9;
  16. [ 18] = 11;
  17. [ 24] = 16;
  18. [ 30] = 14;
  19. [ 36] = 5;
  20. [ 72] = 3;
  21. [ 80] = 2;
  22. [ 82] = 0;
  23. [ 90] = 1;
  24. [ 240] = 17;
  25. [ 242] = 6;
  26. [ 244] = 8;
  27. [ 246] = 15;
  28. }
  29. local function matrix_to_facedir(matrix)
  30. local index = matrix[1] + 3 * matrix[2] + 9 * matrix[3]
  31. + 27 * matrix[5] + 81 * matrix[6] + 243 * matrix[7]
  32. return facedirs[index] or 0
  33. end
  34. return matrix_to_facedir