Advertisement
DEKTEN

FOR_SKETCHPUNKLABS_002

Nov 26th, 2020
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** ************************************************ ***
  2.  
  3. Hello SketchpunkLabs guy.
  4.  
  5. Forgive me if I am mentioning stuff you already know,
  6. but I am excited to see someone else is working on
  7. the same kind of stuff I am working on, so I thought
  8. I would share some of my notes.
  9.  
  10. You can check out my working demo by taking code from
  11. pastebin and cutting and pasting it into shadertoy.
  12.  
  13.     www.tinyurl.com/SDF-009
  14.     OR
  15.     https://pastebin.com/yYSKzCHx
  16.        
  17.     ShaderToy: www.shadertoy.com
  18.  
  19. *** ************************************************ **/
  20.  
  21. const WID = 8; //:width  of tilemap in tiles.
  22. const HIG = 4; //:height of tilemap in tiles.
  23.  
  24. //: To access the data in this, we need to be
  25. //: able to convert an XY coordinate int a
  26. //: 1-dimensional index.
  27. //: Lets say we want to get tile [ 2,3 ]
  28. //:
  29. //:     var tcX = 2;
  30. //:     var tcY = 3;
  31. //:     var tcI = TileCoordXY_To_TileCoordIndex(
  32. //:                                     tcX,tcY );;
  33. //:     var tile_value = my_2d_tilemap[ tcI ];
  34.  
  35. const X = 1;
  36. const _ = 0;
  37. var my_2d_tilemap=[
  38.     _,_,_,_,X,_,_,_
  39. ,   _,X,_,_,_,_,_,_
  40. ,   _,_,X,_,_,_,X,_
  41. ,   _,_,_,_,_,_,_,X
  42. ];;
  43.  
  44. function TileCoordIndex_To_TileCoordXY( tcI ){
  45.  
  46.     var tcX =  tcI % WID        ;
  47.     var tcY = (tcI - tcX ) / WID;
  48.  
  49.     return([ tcX , tcY ]);
  50.  
  51. };;
  52.  
  53. function TileCoordXY_To_TileCoordIndex( tcX , tcY ){
  54.  
  55.     var tcI = tcX + ( WID * tcY);
  56.     return( tcI );
  57.  
  58. };;
  59.  
  60.  
  61. //:For A 3-Dimensional array of tiles, we can think
  62. //:of it as a whole bunch of 2D tilemaps layered
  63. //:on top of each other:
  64. /** ************************************************ ***
  65.  
  66.     I haven't done the math for  1D index to
  67.     voxel X,Y,Z coordinate yet. But here is my
  68.     math for voxel X,Y,Z coord to index.
  69.  
  70.     D2D is the index math for a 2D tilemap.
  71.     D3D is the final index for a 3D tilemap.
  72.  
  73.     T_X == tile coordinate X
  74.     T_Y == tile coordinate Y
  75.     NTX == number of tiles X ( tile map size x axis )
  76.     NTY == number of tiles Y ( tile map size y axis )
  77.     NTZ == number of tiles Z ( tile map size z axis )
  78.  
  79.         //: Index2D -and- Index3D
  80.         int D2D = T_X + ( NTX    *    T_Y );
  81.         int D3D = D2D + ( NTX * NTY * T_Z );
  82.  
  83. *** ************************************************ **/
  84.  
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement