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

Play it: SANTA'S 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');
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
2 Comments
Time DescendingNice article, Umar! Great to see you experimenting with pseudo-3D and improving your skills throughout the contest!
Sign in to participate





















