Fix half-tile offset in corridor canvas drawing
Shader maps world coords to UV via: gUv = rotated / uGroundSize + 0.5 rotated = 0 -> canvas centre But drawTileAt placed tiles at: canvasX = (lng + halfLong) * TILE_SIZE canvasY = (perp + halfPerp) * TILE_SIZE With halfLong = 12 and lng iterating [-12..12], tile lng=0 lands at canvas X = 3072 - but the shader wants gUv.x=0.5 (rotated=0) at canvas centre X = 3200. Half a tile off. Fix: shift drawing by +0.5 tiles so each tile CENTRE is at (lng, perp), matching the shader's rotated-frame interpretation. Tile centres now align with shader expectation; previous half-tile diagonal wobble gone (which is what they meant by 'x und y vertauscht' - the perpendicular axis was indeed offset).
This commit is contained in:
1 parent
a3f5bf6084
commit
14fda4c7d6
1 file changed
+9
-6
Vendored
+9
-6
@@ -314,12 +314,15 @@ function drawTileAt(lng, perp, dx, dz, centerTileX, centerTileY) {
|
|||||||
var tileY = centerTileY + dz;
|
var tileY = centerTileY + dz;
|
||||||
var halfLong = Math.floor(GROUND_CORRIDOR_LONG / 2);
|
var halfLong = Math.floor(GROUND_CORRIDOR_LONG / 2);
|
||||||
var halfPerp = Math.floor(GROUND_CORRIDOR_PERP / 2);
|
var halfPerp = Math.floor(GROUND_CORRIDOR_PERP / 2);
|
||||||
// Canvas position is the rotated-frame coordinate (lng, perp),
|
// Canvas position: place each tile so its CENTRE sits at the
|
||||||
// NOT the rotated tile offset (dx, dz). This way the texture
|
// rotated-frame coordinate (lng, perp). The shader maps
|
||||||
// is rectangular in canvas space and the shader maps world
|
// gUv = rotated / uGroundSize + 0.5, so rotated = 0 is at the
|
||||||
// (hitPoint - centre) -> rotated axes -> canvas UV.
|
// canvas centre (canvas_width/2, canvas_height/2). Iterating
|
||||||
var canvasX = (lng + halfLong) * GROUND_TILE_SIZE;
|
// (lng, perp) over [-halfLong..halfLong] means tile centres at
|
||||||
var canvasY = (perp + halfPerp) * GROUND_TILE_SIZE;
|
// halfLong + 0.5 etc. Without the +0.5 the canvas would be
|
||||||
|
// half a tile off from the shader's expectation.
|
||||||
|
var canvasX = (lng + halfLong + 0.5) * GROUND_TILE_SIZE;
|
||||||
|
var canvasY = (perp + halfPerp + 0.5) * GROUND_TILE_SIZE;
|
||||||
if (canvasX < 0 || canvasX >= groundCanvas.width || canvasY < 0 || canvasY >= groundCanvas.height) {
|
if (canvasX < 0 || canvasX >= groundCanvas.width || canvasY < 0 || canvasY >= groundCanvas.height) {
|
||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user