/// <summary> /// Creates the UV mapping of a block. /// </summary> /// <param name="b">The block to get the mapping of.</param> /// <param name="d">The direction of the block to render.</param> /// <returns>UVMap representing the UV mapping of the current block.</returns> internal static UVMap?CreateUVMapping(this BlockID b, Direction d) { /* * Cheat Sheet * x * 2^y = x << y * x / 2^y = x >> y - Except that / rounds up for negatives, and >> always rounds down * x % 2^y = x & (2^y - 1) */ // Same as X % 256 // 256 = (2^16) = 1 << 16 // x % 256 = x & (256 - 1) // x % 256 = x & ((1 << 16) - 1) Vector2?posOrNull = b.TileVector(d); if (posOrNull == null) { return(null); } Vector2 tile = posOrNull.GetValueOrDefault(); float x = ((int)tile.Y & ((1 << 16) - 1)) * Settings.Offset; // U float y = ((int)tile.X & ((1 << 16) - 1)) * Settings.Offset; return(new UVMap( new Vector2(x + Settings.Offset, y), new Vector2(x, y), new Vector2(x + Settings.Offset, y + Settings.Offset), new Vector2(x, y + Settings.Offset) )); }