Pseudo-3D Without a 3D Engine: Pinhole Projection, First-Order Control, and Swept Collision in a One Button MATLAB Game

An engineering analysis of Santa's Christmas Flight: inverse perspective mapping, a lane filter with a measurable time constant, and a collision test that cannot tunnel
Introduction
SANTA'S CHRISTMAS FLIGHT draws its scene as pixels in a single image that is updated every frame, with no 3D engine involved. Underneath the snow and presents are three engineering ideas, and this post derives each one and measures it against the game's own code. First, the pinhole camera model: one similar triangles ratio projects every tree, present, and ground row. Second, a first order lag, which makes lane changes smooth and has a time constant you can read straight from the code. Third, a swept collision test, which catches fast presents that a naive test can miss.
Demo
Santa Christmas Flight
One button switches lanes in a bouncing pattern: right,middle,left, middle, and so on. Catch presents and orbs, avoid the ice, and fly 40 seconds to the North Pole, where Santa brakes to a stop.
Tips & Tricks
Trick 1: One ratio draws a 3D world
By similar triangles, a point at (X,Y,Z) lands on the image plane at f.X/Z and f.Y/Z. The game uses a focal length of 60 pixels and a camera height of 2.2 units, so a point at lateral x, height y, and depth z appears at column W/2 + f(x-xc)/z and row h0+f(ch-y)/z. Here xc is the camera's sideways offset, and h0=52 is the horizon row. The same focal length sets the field of view: FOV=2.arctan(sensor/2f), which gives 126.9 degrees horizontally and 40.9 degrees above and 54.1 degrees below the horizon for this 240 x 135 image. At Santa's depth of 2, one world unit is 30 pixels, and at depth 18 it is only 3.3.
Trick 2: Run the camera backward to draw the ground
To shade each ground row, set the height to zero and solve for depth: z= ch.f/(row-h0). The game computes this for every row at once with zr=ch*f./((1:H-h0)'). This is the same idea as unprojection, where a pixel is mapped back to 3D by scaling with a known depth. I projected 1,000 random ground points forward and mapped them back, and they returned to within 2.5x10^-14 in depth and 5x10^-15 in lateral position. Resolution is not uniform: each pixel row spans z^2/(ch*f) units of depth, which is 0.03 at depth 2 and 3.0 at depth 20. That is why distant stripes bunch together and why the game fades the far ground into fog.
Trick 3: Size and fog come from the same ratio
A sprite's width and height both scale by f/z, so its pixel area falls as 1/z^2. I tested this with the game's own drawing function and got a log log slop of -2.02 (1,369 pixels at depth 2 against 1,385 predicted, and 16 at depth 18 against 17). Fog is a linear blend between a sprite's color and the sky color, with weight g=min(1,z/18).
Trick 4: One button, three lanes, one low pass filter
The lane rule is ln=ln+dr; if ln~=2,dr=-dr; end, which produces the sequence 3,2,1,2,3,2,1,2 with a single button. Santa's sideways motion follows px=px+(target-px)*min(1,dt*7). That is a first order lag with time constant = 1/7 ~ 0.143 seconds, so a lane change reaches 63% in 0.14 seconds and 95% in 0.43 seconds. The update is an Euler step, so its real time constant depends on the frame rate: 0.134 seconds at 60 fps and 0.116 seconds at 20 fps, which is slightly faster when the game runs slowly. An exact version would use 1-exp(-7*dt). Because the hit radius (1.1) is larger than half the lane spacing (1.8), both neighboring lanes are catchable for about 0.065 seconds while Santa crosses between them.
Trick 5: A swept collision test cannot tunnel
A discrete collision test can miss fast objects, and the inability to detect collisions between fast moving objects passing through each other is called tunneling. The game avoids it with q>2 & s.cz<=2, which asks whether an item crossed the catch plane during the frame. This is a one dimensional version of what sweep based collision detection does, computing impacts along an object's path. I compared it with a naive test that checks whether an item is inside a slab 0.3 units thick, with items moving at 10 units per second. The naive test found 100% of crossings at 60 fps, 90% at 30 fps, and only 60% at 20 fps, where items move 0.5 units per frame. The swept test found 100% at every frame rate.
Trick 6: Brake with a proportional controller
After 40 seconds, the speed command is min(speed,1.5*(zT-3.6)), which means the distance to the stopping point decays exponentially with the time constant 1/1.5=0.667 seconds. My simulation lands in 3.65 seconds, and the closed form prediction is 3.67 seconds: a constant speed phase until the exponential takes over, then the decay.
Live script: the derivations, the code, and the plots
This script covers the notation, the pin hole equations, the inverse ground mapping, a 3D figure of rays meeting the image plane, the depth resolution plot, the sprite area test, fog composting, the lane filter, the lane rule, the double catch window, the swept collision test, the landing controller, and a summary table.
run('SantaFlight_PinholeEngineering.mlx');
Table 1 - dictionary from math symbols to game variables.
Table 2 - where ground points straight ahead land on screen. The column stays at W/2; the row climbs toward the horizon (row 52) as depth grows; the scale u = f/z shrinks.
Table 3 - the field of view that the focal length f = 60 px gives for a 240 x 135 image.
Table 4 - round trip: 1000 random ground points are projected to pixels and mapped back. Errors near 1e-14 mean the two maps are exact inverses.
Table 5 - how much depth one pixel row spans. It grows as z^2, so far rows are coarse and near rows are fine.
Figure 1 - 3-D pinhole camera: rays from the camera to each object cross the image plane at x f/z and (ch - y) f/z.
Figure 2 - left: depth versus ground row; right: depth per pixel row versus depth (solid = measured, dashed = z^2/(ch f)).
Table 6 - pixels painted by the game's own drawing routine for an orb at each depth, next to the formula pi (0.7u)^2. Then the log-log slope: -2 means area falls as 1/z^2.
Table 7 - an orb's color blended toward the sky color: g grows with depth, so far orbs fade (g = 1 means fully fog).
Figure 3 - lane-change step response: exact curve (black) versus the game's Euler update at three frame rates.
Table 8 - effective time constant and rise times of the game's update at each frame rate (ideal tau = 0.143 s).
Table 9 - lane after each tap (1 = left, 2 = middle, 3 = right): the one-button rule bounces 3, 2, 1, 2, 3, 2, 1, 2.
Figure 4 - the yellow band is the short window in which Santa can catch items in both lanes at once.
Table 10 - when Santa enters the new lane's zone, leaves the old one, and the length of the overlap.
Table 11 - fraction of items detected by a naive slab test versus the swept test, for four frame rates (20000 random items each).
Figure 5 - left: an item hopping past a thin slab at 20 fps; right: detection probability of the naive test falls as the step grows, the swept test stays at 1.
Figure 6 - the landing: depth to the North Pole (left) and speed (right) while the proportional controller brakes Santa.
Table 12 - simulated landing time versus the closed-form prediction, and the controller time constant 1/k.
Table 13 - the functions the game relies on. Click a name to open its page. meshgrid mod sort painter's algorithm find min max sin exp sub2ind image CData property sprintf Figure 7 - the functions table: plain-text math next to the same math typeset as LaTeX (yellow column).
Table 14 - one line per engineering idea: the check, the equation, and the measured result. Figure 8 - the summary table: yellow column = equation typeset as LaTeX, green column = what this script measured.
Concluding thoughts
Santa's Christmas Flight shows that a convincing 3D scene can come from a few lines of engineering mathematics. A single ratio, f/z, projects the world and sets the size of every sprite. Its inverse recovers depth for each ground row, and a proportional rule brakes the sleigh. A first order lag gives the lane change its feel, with a time constant you can measure. A swept collision test guarantees thst no present is skipped, however fast the game runs.
Each model has limits. The pinhole model is only a first order approximation of a real 3D to 2D mapping, and this game has no lens distortion at all. The Euler lane update makes the response slightly faster at low frame rates, and the exact update 1-exp(-7*dt) would fix that. The swept test checks only the depth plane and a lateral radius, so it is a one dimensional special case of full continous collision detection. These are the next experiments I would suggest: an exact discretization, a time of impact step, and perspective correct shadows.
References
  1. Foundations of Computer Vision (MIT), "Pinhole image formation and linear perspective"
  2. "Neural Camera Models" (arXiv:2208.12903),pinhole projection and un-projection
  3. B.Wang et Al.,"A large Scale Benchmark and an Inclusion Based Algorithm for Continuous Collision Detection" (ACM TOG, 2021)
Vasilis Bellos
Vasilis Bellos on 28 Nov 2026 at 13:28
Nice article, Umar! Great to see you experimenting with pseudo-3D and improving your skills throughout the contest!
Umar
Umar on 29 Nov 2026 at 13:37
Thankyou 🙏 @Vasilis Bellos! Hope you enjoyed reading it. I've really enjoyed experimenting with pseudo-3D and exploring the engineering behind it. Always something new to learn!