SHARE
TWEET

ROBO24 - index conversion

lignite0 Oct 23rd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const chunkSize = 32;
  2. const chunkSizeSquare = chunkSize ** 2;
  3.  
  4. const toIndex = function (x, y, z) {
  5.     return (y * chunkSizeSquare) + (z * chunkSize) + x;
  6. };
  7.  
  8. const fromIndex2 = function (index) {
  9.     let y = index >> 6;
  10.     let z = (index - (y << 6)) >> 3;
  11.     let x = (index - (y << 6) - (z << 3));
  12.     return {x, y, z};
  13. };
  14.  
  15. const fromIndex = function (index) {
  16.     let y = index >> 10;
  17.     let z = index % 1024 >> 5;
  18.     let x = index % 32;
  19.     return {x, y, z};
  20. };
  21.  
  22.  
  23. const index = toIndex(5, 6, 7);
  24. console.log(index);
  25. console.log(fromIndex(index));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top