miaoda-game-mode7-core
v0.3.1
Published
Engine-agnostic Mode 7 math with SNES-style affine screen-to-map transforms and perspective ground scanlines for retro racing, flight and world maps. No rendering dependency.
Maintainers
Readme
miaoda-game-mode7-core
Engine-independent Mode 7 coordinate math for retro racers, low-altitude flight, rotating maps, water/ground planes, and arena views. It returns map sampling coordinates; image data, shaders, filtering, and sprites remain renderer-owned.
pnpm add miaoda-game-mode7-coreconst camera = {position: {x: 100, y: 200}, heading: Math.PI / 4, height: 1, fieldOfView: Math.PI / 2, horizonY: 180};
const viewport = {width: 640, height: 360};
for (let y = 181; y < viewport.height; y += 1) {
const row = buildMode7PerspectiveScanline(camera, viewport, y);
if (row) sampleRow(row.start, row.step);
}
const carAnchor = projectMode7GroundPoint(camera, viewport, car.position);Angles are radians and positions are continuous map units. Each perspective scanline supplies one start coordinate and one constant per-pixel world step. buildMode7PerspectiveScanlines can skip rows for a low-resolution effect.
For raw rotation/scale/shear, use mapMode7Texel or buildMode7AffineScanline with an explicit 2x2 transform, pivot, and scroll. The package models one flat plane; use segmented roads for hills or a terrain package for height fields.
