BGE/ImpostorFit

Alias: BGE.ImpostorFit


Static Methods

fitScaleTranslate( fromX: Array.<float>, fromY: Array.<float>, toX: Array.<float>, toY: Array.<float>, ): FitResult

static

Fits x' = sx * x + tx and y' = sy * y + ty by least squares - what a single DrawScaledObject can draw. A mirrored or collapsed axis isn't usable.

Parameters

  • fromX (Array.<float>) — captured x of each point
  • fromY (Array.<float>) — captured y of each point
  • toX (Array.<float>) — current x of each point
  • toY (Array.<float>) — current y of each point

Returns

fitRotateScale( fromX: Array.<float>, fromY: Array.<float>, toX: Array.<float>, toY: Array.<float>, ): FitResult

static

Fits a rotation about the points' centre, then a scale along each rotated axis - what a single DrawTransformedObject can draw. The rotation comes from the best similarity fit, then each axis's scale by least squares, so it isn't the joint optimum but is close for the small rotations an impostor sees.

Parameters

  • fromX (Array.<float>)
  • fromY (Array.<float>)
  • toX (Array.<float>)
  • toY (Array.<float>)

Returns

fitAffine( fromX: Array.<float>, fromY: Array.<float>, toX: Array.<float>, toY: Array.<float>, ): FitResult

static

Fits a general affine map by least squares - what a corner pin of the captured bitmap would draw, since a pin warps a parallelogram exactly.

Parameters

  • fromX (Array.<float>)
  • fromY (Array.<float>)
  • toX (Array.<float>)
  • toY (Array.<float>)

Returns

scaleTranslateAsRotateScale( params: roAssociativeArray, ): roAssociativeArray

static

fitScaleTranslate()'s params as fitRotateScale() would give them, with no rotation, so mapRotateScale() and the same blit can use either.

Parameters

  • params (roAssociativeArray) — a fitScaleTranslate() result's params

Returns

  • roAssociativeArray

mapRotateScale( params: roAssociativeArray, x: float, y: float, ): BGE.Math.Vector

static

Where fitRotateScale()'s params take the point (x, y).

Parameters

  • params (roAssociativeArray) — a fitRotateScale() result's params
  • x (float)
  • y (float)

Returns

  • BGE.Math.Vector

fitColumnsToEdges( fromX: Array.<float>, fromY: Array.<float>, toX: Array.<float>, toY: Array.<float>, projective?: boolean, ): FitResult

static

Builds a column warp - the captured bitmap redrawn as vertical strips (#556) - from vertical edges of the model: capture x maps to current x, and each column is scaled and shifted vertically, all linear in capture x between the edges. Exact for vertical walls when the camera only turns and moves. Params: knotX (capture x, increasing), x (current x), offset and scale (current y = offset + scale * capture y) at each knot. The residual is 0; measure one with columnsResidual(). A projective warp interpolates between knots with perspective (see makeColumnsProjective()), exact for flat walls between edges.

Parameters

  • fromX (Array.<float>) — each edge's top then bottom captured x, edge after edge
  • fromY (Array.<float>)
  • toX (Array.<float>) — the same points' current x
  • toY (Array.<float>)
  • projective (boolean, optional, default: false)

Returns

makeColumnsProjective(params: roAssociativeArray): void

static

Makes a column warp interpolate with perspective between knots. With the camera only turning and moving, a column's vertical scale is its depth then over its depth now, so along a flat wall 1 / scale and offset / scale are linear in capture x, and current x moves by weights of 1 / scale - no depths needed. Adds q (1 / scale) and g (offset / scale).

Parameters

  • params (roAssociativeArray) — a column warp's params, every scale above 0

Returns

  • void

placeKnots(xs: Array.<float>, count: integer): Array.<float>

static

Knots for fitColumns() at quantiles of the points' distinct x (to the half pixel), so each segment has points to fit, and no more than the points support: two per knot.

Parameters

  • xs (Array.<float>) — the points' x
  • count (integer) — knots wanted

Returns

  • Array.<float> — increasing; fewer than 2 if the points can't support a warp

fitColumns( knotX: Array.<float>, fromX: Array.<float>, fromY: Array.<float>, toX: Array.<float>, toY: Array.<float>, projective?: boolean, ): FitResult

static

Fits a column warp (see fitColumnsToEdges()) with the given knots by least squares. A projective warp fits the vertical map backwards (capture y from current y is linear in its unknowns), then x with perspective weights.

Parameters

  • knotX (Array.<float>) — capture x of each knot, increasing
  • fromX (Array.<float>)
  • fromY (Array.<float>)
  • toX (Array.<float>)
  • toY (Array.<float>)
  • projective (boolean, optional, default: false)

Returns

mapColumns( params: roAssociativeArray, x: float, y: float, ): BGE.Math.Vector

static

Where a column warp's params take the point (x, y). Past the first or last knot, the nearest segment carries on.

Parameters

  • params (roAssociativeArray) — a column warp's params
  • x (float)
  • y (float)

Returns

  • BGE.Math.Vector

columnsResidual( params: roAssociativeArray, fromX: Array.<float>, fromY: Array.<float>, toX: Array.<float>, toY: Array.<float>, ): float

static

The farthest a column warp puts any point from where it is now, in pixels.

Parameters

  • params (roAssociativeArray)
  • fromX (Array.<float>)
  • fromY (Array.<float>)
  • toX (Array.<float>)
  • toY (Array.<float>)

Returns

  • float

cameraBasis( rightAxis: BGE.Math.Vector, upAxis: BGE.Math.Vector, backAxis: BGE.Math.Vector, eye: BGE.Math.Vector, focal: float, centreX: float, centreY: float, ): Array.<float>

static

A camera's view as a flat array, for projectToBasis() and mapBetweenBases(): its right, up and back axes, the eye, the focal length in pixels and the canvas centre. Projects as Camera3d does, without the rounding to whole pixels.

Parameters

  • rightAxis (BGE.Math.Vector)
  • upAxis (BGE.Math.Vector)
  • backAxis (BGE.Math.Vector) — the camera looks down -backAxis
  • eye (BGE.Math.Vector)
  • focal (float)
  • centreX (float)
  • centreY (float)

Returns

  • Array.<float>

basisFromView( worldToCamera: Array.<Array.<float>>, eye: BGE.Math.Vector, focal: float, frameWidth: float, frameHeight: float, shiftY?: float, ): Array.<float>

static

cameraBasis() for a camera's world-to-camera matrix (a rigid transform, as Camera3d's).

Parameters

  • worldToCamera (Array.<Array.<float>>)
  • eye (BGE.Math.Vector)
  • focal (float)
  • frameWidth (float)
  • frameHeight (float)
  • shiftY (float, optional, default: "0.0") — how far down the image is moved (Camera3d.getPitchShiftY())

Returns

  • Array.<float>

levelBasis(basis: Array.<float>): Array.<float>

static

The same camera turned level: the same eye and heading, with no pitch or roll (world up is +y). World verticals project as vertical lines in it, which the column warp needs.

Parameters

  • basis (Array.<float>) — from cameraBasis()

Returns

  • Array.<float> — empty when the camera looks almost straight up or down

projectToBasis( basis: Array.<float>, points: Array.<BGE.Math.Vector>, outX: Array.<float>, outY: Array.<float>, ): boolean

static

Projects world points through a cameraBasis().

Parameters

  • basis (Array.<float>)
  • points (Array.<BGE.Math.Vector>)
  • outX (Array.<float>) — cleared, then each point's canvas x
  • outY (Array.<float>)

Returns

  • boolean — false as soon as a point isn't in front of the camera

mapBetweenBases( fromBasis: Array.<float>, toBasis: Array.<float>, x: float, y: float, out: Array.<float>, ): boolean

static

Where the canvas point (x, y) of one camera lands in another at the same eye (the view turned): its ray, projected again. Writes x, y to out[0], out[1].

Parameters

  • fromBasis (Array.<float>)
  • toBasis (Array.<float>)
  • x (float)
  • y (float)
  • out (Array.<float>)

Returns

  • boolean — false if the ray isn't in front of the other camera

homographyBetween( fromBasis: Array.<float>, toBasis: Array.<float>, ): Array.<float>

static

The canvas-to-canvas map between two views from the same eye (a turn), as a homography: [a, b, c, d, e, f, g, h, i], where (x, y) goes to ((ax + by + c) / w, (dx + ey + f) / w) with w = gx + hy + i, in front of the second view while w > 0. Lets the hot loops map points without calls (see mapPointsByHomography()).

Parameters

  • fromBasis (Array.<float>)
  • toBasis (Array.<float>)

Returns

  • Array.<float>

warpHomographies( bases: Array.<Array.<float>>, ): Array.<Array.<float>>

static

homographyBetween() for a capture's camera to its level view, and for the current level view to the current camera: what the strip maps below take.

Parameters

  • bases (Array.<Array.<float>>) — capture camera, capture level, current level, current camera

Returns

  • Array.<Array.<float>>

mapPointsByHomography( h: Array.<float>, xs: Array.<float>, ys: Array.<float>, outX: Array.<float>, outY: Array.<float>, ): boolean

static

Maps points through a homographyBetween().

Parameters

  • h (Array.<float>)
  • xs (Array.<float>)
  • ys (Array.<float>)
  • outX (Array.<float>) — cleared, then filled
  • outY (Array.<float>)

Returns

  • boolean — false as soon as a point isn't in front of the second view

mapPointsCaptureToNow( params: roAssociativeArray, homographies: Array.<Array.<float>>, xs: Array.<float>, ys: Array.<float>, outX: Array.<float>, outY: Array.<float>, ): boolean

static

Where a capture's canvas points are drawn now: into the level view at capture, through the column warp, then out of the level view now into the camera now. Inlined: it runs for every cut, bound and sample point of every strip frame.

Parameters

  • params (roAssociativeArray) — a column warp fitted between the two level views
  • homographies (Array.<Array.<float>>) — from warpHomographies()
  • xs (Array.<float>) — capture canvas x
  • ys (Array.<float>)
  • outX (Array.<float>) — cleared, then filled
  • outY (Array.<float>)

Returns

  • boolean — false as soon as a point won't map

mapCaptureToNow( params: roAssociativeArray, homographies: Array.<Array.<float>>, x: float, y: float, out: Array.<float>, ): boolean

static

mapPointsCaptureToNow() for one point, writing x, y to out[0], out[1].

Parameters

  • params (roAssociativeArray)
  • homographies (Array.<Array.<float>>)
  • x (float)
  • y (float)
  • out (Array.<float>)

Returns

  • boolean

stripTransforms( params: roAssociativeArray, homographies: Array.<Array.<float>>, originX: float, cuts: Array.<integer>, top: float, height: float, ): Array.<float>

static

How to draw each strip between cuts (capture bitmap columns) now: [x, y, x scale, y scale, rotation] per strip, flat, for DrawTransformedObject about the strip's top left (rotation in radians, counterclockwise on screen). Each cut's top and bottom are mapped (mapPointsCaptureToNow()); a strip turns to follow the line through its middle, so verticals keep converging as they should under a pitched camera, and its top edge's middle lands where it maps. A strip that would flip or collapse gets 0 scales.

Parameters

  • params (roAssociativeArray)
  • homographies (Array.<Array.<float>>) — from warpHomographies()
  • originX (float) — the bitmap's left edge, in capture canvas x
  • cuts (Array.<integer>)
  • top (float) — the bitmap's top, in capture canvas y
  • height (float)

Returns

  • Array.<float> — empty if a corner won't map

stripsCoverFrame( params: roAssociativeArray, homographies: Array.<Array.<float>>, x0: float, y0: float, x1: float, y1: float, cutXs: Array.<float>, frameWidth: float, frameHeight: float, ): boolean

static

Whether the strips keep a capture's clip rect over the whole frame, so the parts the capture left out stay off it: the rect's top and bottom at its sides and every cut, and its sides at the top, middle and bottom, mapped (mapPointsCaptureToNow()).

Parameters

  • params (roAssociativeArray)
  • homographies (Array.<Array.<float>>)
  • x0 (float) — the clip rect, in capture canvas coordinates
  • y0 (float)
  • x1 (float)
  • y1 (float)
  • cutXs (Array.<float>) — the cuts, in capture canvas x
  • frameWidth (float)
  • frameHeight (float)

Returns

  • boolean

levelStripCuts( params: roAssociativeArray, leftX: float, rightX: float, top: float, bottom: float, maxStep: float, ): Array.<float>

static

Where to cut a column warp's capture x (in its level view) into strips, from leftX to rightX: each knot segment split as columnSegmentStrips() says, and the parts past the outer knots a strip each. A projective warp's cuts are spaced evenly in current x, where a flat wall's top and bottom are straight lines, so every strip changes about as much.

Parameters

  • params (roAssociativeArray)
  • leftX (float)
  • rightX (float)
  • top (float) — the bitmap's top, in level capture y
  • bottom (float)
  • maxStep (float)

Returns

  • Array.<float> — increasing, leftX first and rightX last

snapKnotTo(knotX: Array.<float>, x: float): void

static

Moves the inner knot nearest x onto it - the crease between two walls, where the warp changes from one wall to the next - if the knots stay in order more than a pixel apart.

Parameters

  • knotX (Array.<float>) — increasing, changed in place
  • x (float)

Returns

  • void

subsetWithExtremes( xs: Array.<float>, ys: Array.<float>, maxPoints: integer, ): Array.<integer>

static

Which of the points to keep, at most maxPoints of them: the leftmost, rightmost, top and bottom ones, so knots and errors still reach the model's outline, then an even spread.

Parameters

  • xs (Array.<float>)
  • ys (Array.<float>)
  • maxPoints (integer) — below 4 keeps every point

Returns

  • Array.<integer> — indices

projectiveDenominator(d: float, q0: float, q1: float): float

static

A projective warp's denominator, kept positive past the outer knots, where it can reach 0 before the bitmap's edge.

Parameters

  • d (float)
  • q0 (float)
  • q1 (float)

Returns

  • float

columnSegmentStrips( params: roAssociativeArray, j: integer, top: float, bottom: float, maxStep: float, ): integer

static

How many vertical strips knot segment j needs so that no column lands more than maxStep pixels from the warp, given the captured bitmap's top and bottom y. Each strip is one scaled blit with a single vertical scale and offset, taken at its middle.

Parameters

  • params (roAssociativeArray)
  • j (integer)
  • top (float)
  • bottom (float)
  • maxStep (float)

Returns

  • integer

fixedStripCuts( width: integer, stripWidth: integer, ): Array.<integer>

static

Strips every stripWidth pixels across a bitmap width wide: the cuts from 0 to width.

Parameters

  • width (integer)
  • stripWidth (integer) — above 0

Returns

  • Array.<integer>

columnsUsable(params: roAssociativeArray): boolean

static

A warp with knots out of order (an edge has passed another - a face has turned edge-on) or a flipped or collapsed column can't be drawn as strips.

Parameters

  • params (roAssociativeArray)

Returns

  • boolean

columnSegment(knotX: Array.<float>, x: float): integer

static

The knot segment whose line x lies on: the first or last past either end.

Parameters

  • knotX (Array.<float>)
  • x (float)

Returns

  • integer

solveLinear( matrix: Array.<float>, rhs: Array.<float>, n: integer, ): Array.<float>

static

Solves an n x n system (row-major matrix) by Gaussian elimination with partial pivoting, or returns [] if it's singular. Overwrites matrix and rhs.

Parameters

  • matrix (Array.<float>)
  • rhs (Array.<float>)
  • n (integer)

Returns

  • Array.<float>

zeros(n: integer): Array.<float>

static

Parameters

  • n (integer)

Returns

  • Array.<float>

fitAxis( fromValues: Array.<float>, toValues: Array.<float>, ): roAssociativeArray

static

Parameters

  • fromValues (Array.<float>)
  • toValues (Array.<float>)

Returns

  • roAssociativeArray

mean(values: Array.<float>): float

static

Parameters

  • values (Array.<float>)

Returns

  • float

unusable(): FitResult

static

Returns

Other

FitResult

static

How well one 2D mapping takes a set of captured canvas points to where they are now - see specs/2026-10-22-model-impostors-design.md. residual is the farthest any point lands from where it really is, in pixels; invalid params mean the fit isn't usable.

Properties

  • residual (float)
  • params (roAssociativeArray) — scale + translate: x' = scaleX * x + offsetX, y' = scaleY * y + offsetY