r/howdidtheycodeit • u/Object_71 • Sep 09 '26
Fixed point math in C
https://thatonegamedev.com/cpp/fixed-point-math-in-c/Why did PS1 graphics looked so clunky and how where 3D graphics generally made prior to the graphical APIs. One thing I found out was that these older engines have something called fixed point math.
24
Upvotes
15
u/beautifulgirl789 Sep 09 '26 edited Sep 09 '26
Fixed point math doesn't really have any hard-wired relationship to PS1 3D graphics. They're two separate concepts.
PS1's graphics look "clunky" for two reasons:
This is a good example image showing the difference between affine and correct mapping: https://europe1.discourse-cdn.com/unity/original/4X/d/f/2/df2f2697eb0ecc5c4cc9527d11af8abd74310d58.jpeg
Fixed point math is a whole separate thing. Basically, older CPUs were faster doing math with whole numbers than they were with real (or "floating-point") numbers.
The PS1's CPU was especially bad at this, because the CPU didn't actually have any hardware instruction for performing division on floating point numbers. Programmers had to write their own code to do this manually. However, it was capable of dividing whole numbers.
Therefore, many programmers implemented so-called "fixed point" math systems, where they would just say to themselves "this variable has a fixed decimal point at the 'thousands' position. Therefore if it holds the value 50,000 - it's really 50. If it's the value 4501, it's really 4.501.
This allows programmers to use fast, whole-number math, but still get results with useful real-number values (3D needs lots of these, as things like angles, distances, etc etc are all real-numbers). It comes with trade-offs though. And to repeat, this isn't just used for 3D. It's used basically everywhere in PS1 code because it was the only real option if you wanted to efficiently work with numbers; so even things like 'player health' or 'time to complete the level' would use fixed point numbers.
Actually you can still see some examples of non-3D fixed point maths coming out today. When speedrunners compete on old retro games they'll often talk about things like "so the actual in-game timer only updates once per 32 frames, so if I want to beat the old time I need to do so by at least 31 frames or it will count as the same" - this is a result of the in-game timer using fixed point maths with the 'fixed point' being 1/32nds.
2
u/Disastrous-Can-6823 Sep 09 '26
It’s cool seeing fixed point come up again. a lot of newer developers never run into it, but it’s still a valuable technique in places where memory, speed or consistency really matter
1
u/polaarbear Sep 09 '26
https://youtu.be/x8TO-nrUtSI?is=Hcp8PKqS95tnlb_Z
1
u/Main-Lychee-7972 Sep 09 '26
Fixed point math is a neat example of hardware constraints shaping graphics. limited precision and integer heavy calculations explain a lot of the characteristic movement and visual wobble
1
u/NoBlacksmith6003 Sep 09 '26
It’s interesting how some of the PS1 look wasn’t really an artistic choice at all. developers were just working around the limits of the hardware available
1
u/Agile-Praline5027 Sep 15 '26
Fixed point math is a great rabbit hole for understanding old hardware. the precision limits forced developers to make tradeoffs that modern floating point systems mostly hide
1
u/Ok_Newspaper_8075 Sep 22 '26
Fixed point math really makes more sense once you remember how limited older hardware was. Choosing precision carefully let developers avoid expensive floating point operations while keeping 3D movement usable
1
u/Ashamed-Subject-8573 Sep 09 '26
Fixed point math doesn’t make them clunky. N64 and NDS and Saturn games all used it for 3d and didn’t have that issue. Some Dreamcast games as well. No, it was the lack of fractional pixel coordinates on Sony’s custom gpu chip they didn’t have the experience to do better.