miaoda-game-perspective-core
v0.2.0
Published
Engine-independent pinhole projection primitives for fixed-axis and freely oriented pseudo-3D cameras.
Maintainers
Readme
miaoda-game-perspective-core
Small, engine-independent pinhole projection primitives. Choose this package when the game owns its geometry and only needs world-to-screen math, rather than a road, tube, terrain, or raycast world model.
pnpm add miaoda-game-perspective-coreimport {cameraDepthForFov, project} from 'miaoda-game-perspective-core';
const camera = {x: 0, height: 1000, z: 0, depth: cameraDepthForFov(100)};
const point = project({x: 500, y: 0, z: 4000}, camera, 640, 360);The final arguments are viewport half-width and half-height. The fixed convention is world +z forward, +x right, and +y up; returned screen coordinates are centered with y up. cameraDepthForFov accepts a full FOV in degrees strictly between 0 and 180.
Use projectWithBasis for a freely oriented camera. The caller owns clipping and should project only points with positive forward camera depth. horizonDepth(camera, halfWidth) returns a forward camera-space distance, not absolute world z.
