Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** ************************************************ ***
- Hello SketchpunkLabs guy.
- Forgive me if I am mentioning stuff you already know,
- but I am excited to see someone else is working on
- the same kind of stuff I am working on, so I thought
- I would share some of my notes.
- You can check out my working demo by taking code from
- pastebin and cutting and pasting it into shadertoy.
- www.tinyurl.com/SDF-009
- OR
- https://pastebin.com/yYSKzCHx
- ShaderToy: www.shadertoy.com
- *** ************************************************ **/
- const WID = 8; //:width of tilemap in tiles.
- const HIG = 4; //:height of tilemap in tiles.
- //: To access the data in this, we need to be
- //: able to convert an XY coordinate int a
- //: 1-dimensional index.
- //: Lets say we want to get tile [ 2,3 ]
- //:
- //: var tcX = 2;
- //: var tcY = 3;
- //: var tcI = TileCoordXY_To_TileCoordIndex(
- //: tcX,tcY );;
- //: var tile_value = my_2d_tilemap[ tcI ];
- const X = 1;
- const _ = 0;
- var my_2d_tilemap=[
- _,_,_,_,X,_,_,_
- , _,X,_,_,_,_,_,_
- , _,_,X,_,_,_,X,_
- , _,_,_,_,_,_,_,X
- ];;
- function TileCoordIndex_To_TileCoordXY( tcI ){
- var tcX = tcI % WID ;
- var tcY = (tcI - tcX ) / WID;
- return([ tcX , tcY ]);
- };;
- function TileCoordXY_To_TileCoordIndex( tcX , tcY ){
- var tcI = tcX + ( WID * tcY);
- return( tcI );
- };;
- //:For A 3-Dimensional array of tiles, we can think
- //:of it as a whole bunch of 2D tilemaps layered
- //:on top of each other:
- /** ************************************************ ***
- I haven't done the math for 1D index to
- voxel X,Y,Z coordinate yet. But here is my
- math for voxel X,Y,Z coord to index.
- D2D is the index math for a 2D tilemap.
- D3D is the final index for a 3D tilemap.
- T_X == tile coordinate X
- T_Y == tile coordinate Y
- NTX == number of tiles X ( tile map size x axis )
- NTY == number of tiles Y ( tile map size y axis )
- NTZ == number of tiles Z ( tile map size z axis )
- //: Index2D -and- Index3D
- int D2D = T_X + ( NTX * T_Y );
- int D3D = D2D + ( NTX * NTY * T_Z );
- *** ************************************************ **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement