/** * Texture-column helpers for Wolfenstein-style wall strips. * Each screen column samples exactly one source pixel column. */ function textureColumnIndex (tileX, texWidth) { if (!(texWidth > 0)) { return 0; } var sx = Math.floor(Number(tileX) * texWidth); if (sx < 0) { sx = 0; } if (sx > texWidth - 1) { sx = texWidth - 1; } return sx; } function textureColumnUv (tileX, texWidth) { var sx = textureColumnIndex(tileX, texWidth); var w = texWidth > 0 ? texWidth : 1; return { sx: sx, sw: 1, u0: sx / w, u1: (sx + 1) / w, v0: 0, v1: 1 }; } /** Face U from hit position within a cell (no +1 bias). */ function faceTileX (hitCoord, cellSize, face) { var local = hitCoord % cellSize; if (local < 0) { local += cellSize; } var t = local / cellSize; switch (face) { case "north": return t; case "south": return 1 - t; case "east": return 1 - t; case "west": return t; default: return t; } } if (typeof module !== "undefined" && module.exports) { module.exports = { textureColumnIndex: textureColumnIndex, textureColumnUv: textureColumnUv, faceTileX: faceTileX }; }