8 ms·
Translating a Fortran F-16 Simulator to Unity3D
- imp0cat 1y agoThe "UNITS" part is wonderful. I had no idea slugs even existed. You want to measure how much air mass is in a given volume? That’s gonna be slugs/ft3.
- kataklasm 1y agoThe whole imperial/British side has tons of ugly and weird units of measure. Reading old engineering documentation will give you headaches and nightmares from all the inconsistent systems of units.
- arnsholt 1y agoMy favourite one was when I learned about the existence of US survey feet.
- HeyLaughingBoy 1y agoMy property is very irregularly shaped with the longest straight dimension being 6" shy of a quarter mile. The really scary thing is that I recognized that immediately the first time I looked at the property survey map.
- hans_castorp 1y agoMy favorite "strange unit" is poronkusema: "A Sami measurement of distance; the distance a reindeer can travel before needing to stop to urinate. Today used to describe something that is at a very obscure distance away" (approximately 7.5 km) https://en.wikipedia.org/wiki/Obsolete_Finnish_units_of_measurement#Miscellaneous https://en.wikipedia.org/wiki/Obsolete_Finnish_units_of_meas...
- sunrunner 1y agoThere's no reason for this to obsolete, I have to factor this into route planning for myself so I vote we bring this one back.
- sunrunner 1y agoThe 'List of non-coherent units of measurement' [1] and 'List of humorous units of measurement' [2] pages are always a fun rabbit hole to go down. [1] https://en.wikipedia.org/wiki/List_of_non-coherent_units_of_measurement https://en.wikipedia.org/wiki/List_of_non-coherent_units_of_... [2] https://en.wikipedia.org/wiki/List_of_humorous_units_of_measurement https://en.wikipedia.org/wiki/List_of_humorous_units_of_meas...
- Tor3 1y agoAh, I now learned that "One moment, please" means that I'll have to expect to wait 90 seconds.
- dghlsakjg 1y agoCompletely NSFW, but I worked at a company where we frequently needed to measure distance in approximate meters. I don't know the full origin, but at some point, after a night of drinking, one of the managers discovered that an elephant penis was approximately one meter. From then on, any estimated distance was done in EDs.
- jan_g 1y agoA nautical mile is ~6,076 feet or exactly 1,852 meters (???). That is actually defined by distances on Earth (which is of course an approximation, but still ...). So, 1 nautical mile equals to one minute in the 90 degrees hemisphere arc. It's approximately 10k km from equator to the pole, so 10,000km/90/60 equals 1.852km.
- alephnil 1y ago> 1 nautical mile equals to one minute in the 90 degrees hemisphere arc The nautical mile is not an SI unit, so it is not defined by a single organization, Your definition used to be the common definition, but it seems like the relevant organizations has updated the definition to be exactly 1852 m. If the original definition of the meter applies, then it would have been 1851.85 or 15 cm shorter, but with newer measurement of the earth, it would have been more like 1855 m.
- throw0101c 1y ago> The nautical mile is not an SI unit, so it is not defined by a single organization "In 1929 the International Hydrographic Bureau obtained an agreement from a large number of countries to adopt a value of 1852 metres for the nautical mile, the unit thus defined to be called the International Nautical Mile." * https://usma.org/laws-and-bills/adoption-of-international-nautical-mile https://usma.org/laws-and-bills/adoption-of-international-na... * https://en.wikipedia.org/wiki/International_Hydrographic_Organization https://en.wikipedia.org/wiki/International_Hydrographic_Org... But there was no treaty or anything with a fancy ceremony, just a 'handshake', and so it was up to each country to adopt it with a domestic law or regulation, which (e.g.) the US did in 1954: * https://usma.org/wp-content/uploads/2015/06/Nautical-Mile.pdf?x40840 https://usma.org/wp-content/uploads/2015/06/Nautical-Mile.pd... Previously in the US it was 1853.25 m (because the US is actually metric "officially": all of its customary units (ft, oz) are defined in terms of metric equivalents): * https://usma.org/laws-and-bills/mendenhall-order https://usma.org/laws-and-bills/mendenhall-order
- JSR_FDED 1y ago> Note that Fortran supports arrays with an arbitrary starting index, in this case -2. So this table supports indices in the range [-2, 9]. That is such a useful feature! Surprised I haven’t seen that more often. So much fiddly code exists that’s just fixing offsets to conform to 0 (or 1 for Lua) -based indexing!
- hans_castorp 1y agoPascal (and Modula if I'm not mistaken) supports this too.
- LiamPowell 1y agoAda too, which is of course Pascal-based. Like many programming language features, it feels like it was lost simply because C didn't have it and everyone wanted to copy C.
- pjmlp 1y agoMany BASIC dialects as well. Hence why the whole base index discussion only became relevant in C based languages.
- ubercore 1y agoReminds me of this fantastic talk: https://www.youtube.com/watch?v=wo84LFzx5nI https://www.youtube.com/watch?v=wo84LFzx5nI
- IsTom 1y agoIn C can't you just offset pointer and then you'll be able to index with arbitrary starting value?
- michaelrpeskin 1y agoYes. I do this a lot when writing linear algebra stuff. All the math texts write things in 1-based notation for matrices. The closer I can make the code match the paper I'm implementing makes life so much easier. Of course there's a big comment at the beginning of the function when I modify the pointer to explain why I'm doing it.
- bob1029 1y agoThis seems like a really reasonable implementation looking at the actual physics loop. From a game design perspective, lookup tables can be a very powerful way for artists to interact with the physics. For example, it makes balancing 2 different vehicles a lot easier in conversation. You could say things like "I think we need to reduce the performance of XYZ between 1000 and 8000 feet to balance with ABC". Inserting a new band into the table is an obvious exercise in Microsoft excel.
- ForHackernews 1y agoI'm somewhat surprised the physical units matter in a computer simulation. As long as the simulation is internally consistent (which I would assume the original code is) it seems odd to me that the nominal units are important at all. Is that video game character walking 100 yards? Or maybe the character is 500 feet tall and he's walking 50 leagues?
- kyykky 1y agoIn mechanics simulations we often change the units to avoid adding small and large floats.
- lloydatkinson 1y agoWould you want to fly in an aircraft that's been modelled with pretend computer units? Or the one that was modelled correctly in a simulator? :)
- ForHackernews 1y agoOk but if you did a global find-replace for "meters" with "smoots" do you think that the simulated plane would crash?
- lloydatkinson 1y agoAh but smoots would still follow the same maths as a meter right?
- ForHackernews 1y agoYes, that's how numbers work. 10 smoots + 1 smoot is 11 smoots. That's the point of my question.
- meheleventyone 1y agoThey don't matter as long as the relative values and the relationships hold. For video games where you're making something arcadey you're often implementing the physical behavior in terms of regular old physics but the values used don't have to be real as long as you get the right results. It's just when you're simulating something real it's useful to have units that make intuitive sense and that's often real world units as we've built up a lot of understanding by using them already. In particular with a flight model based on look up tables from real world data it's already in a set of units.
- UncleSlacky 1y ago"It turns out, Fortran is actually pretty good at translating formulas." I'm hoping they know that the language's name comes from FORmula TRANslator...
- bitwize 1y agoThats_the_joke.jpg
- forgotpwd16 1y agoSeems too good of pun to not be deliberate.
- Reubachi 1y ago.......that's the joke
- ertucetin 1y agoHere is Clojure implementation of Space Simulator: https://wedesoft.github.io/sfsim/ https://wedesoft.github.io/sfsim/
- master_crab 1y agoI saw slugs and I immediately had PTSD from my days in aero engineering. Imagine trying to keep track of pounds in a single set of equations using subscripts m and f to differentiate between the units’ use for both mass and force.
- throw0101c 1y agoWhen I was growing up computers were getting faster by leaps and bounds, and I remember a video game that was so 'sophisticated' that it needed a math (FP) co-processor (80387) to play some parts of it: > The program requires a minimum of a 12MHz 80286, 1MB RAM, DOS 5.0 or DR DOS, one 1.2MB 5 1⁄4" or 1.44MB 3 1⁄2" disk drive, hard drive with 11MB of free disk space, and VGA graphics. In addition, Falcon3.O supports a joystick, a joystick with a throttle, dual joysticks, rudder pedals or the ThrustMaster controls. The game also supports a mouse and various sound cards, including the Ad Lib, Sound Blaster and Roland. The 80x87 math coprocessor is supported for the HighFidelity flight model. > Optimal system requirements are a 20MHz 80386 system or faster, 80x87 math coprocessor, 4MB RAM with EMS (expanded memory), DOS 5.0 or DR DOS, one 1.2MB 51⁄411 or 1.44MB 31⁄2" disk drive, hard drive with 11MB of free space, a 16-bit VGA card, a mouse and a joystick. * https://vtda.org/docs/computing/SpectrumHolobyte/Falcon_3.0_Customer_Support_Question_Answer_Booklet.pdf https://vtda.org/docs/computing/SpectrumHolobyte/Falcon_3.0_... * https://en.wikipedia.org/wiki/Falcon_3.0 https://en.wikipedia.org/wiki/Falcon_3.0 "Wow!" we thought at the time.
- qmr 1y agoFalcon 4.0 source code leak led to Falcon BMS, still actively developed today.
- spankibalt 1y agoFalcon 4.0 was one of the worst bugfests I ever encountered, practically unplayable; the modding community did a tremendous job to fix and improve that mess. At the time of its release it was even worse than Privateer 2: The Darkening, a title whose structural imperfections were only matched by its utterly bizarre Britkraft sci-fi setting.
- psunavy03 1y agoPrivateer 2, as I recall, just had the "Privateer" name slapped on a completely unrelated project due to executive meddling. That aside, I kind of weirdly liked it. The story was hard as hell to follow, but the setting was interesting in a trippy way.
- enopod_ 1y agoI just learned about the slug and I‘m absolutely flabbergasted that this exists.
- colechristensen 1y agoThe confusion between force and mass tends not to get appreciated by many folks outside of engineering. Particularly in aerospace when you slip the surly bonds of earth and your mass stops being so bound to the force your feet impart on the floor.
- arethuza 1y agoOther "interesting" units include: shakes, barns and bans https://en.wikipedia.org/wiki/Shake_(unit) https://en.wikipedia.org/wiki/Shake_(unit) https://en.wikipedia.org/wiki/Barn_(unit) https://en.wikipedia.org/wiki/Barn_(unit) https://en.wikipedia.org/wiki/Hartley_(unit) https://en.wikipedia.org/wiki/Hartley_(unit)
- drewg123 1y agoMy Mom was a FORTRAN programmer for a defense contractor from the late 50s to the mid 90s. She spent her career doing things like that F16 simulator. The last thing I remember her talking about was one of the B1 or B2 bombers. When I was elementary school age in the late 70s, I'd go into her office with her sometimes on school holidays that were not work holidays. She'd let me play Colossal Cave Adventure on a terminal in her office. I remember looking at printouts of code she was working on, and seeing a wireframe diagram of some futuristic plane. I think it must have been one of the first Stealth fighters. I wonder how many security protocols she broke by having me there... :) She passed a way many years ago, but I think she would have been excited to see work like this.
- AndrewKemendo 1y agoFWIW she probably wasn’t breaking any security protocols - basically as long as the kids can’t read well they are fine to be escorted without the red light. I used to take my daughter into the SCIF when she was about 2 when needed, and there was a week where I was took my son into work at the Pentagon. I working for Snake Clark at the time and people kept bringing him candies and treats. I think he was watching cartoons on Nick in the deputy’s office most of the day. He gets a kick out of that story now.
- the__alchemist 1y agoI do a double-take if I see a dog! I've seen babies, but I'm pretty sure anyone that can walk or talk would be a no-go. My assumption is OP wasn't in a facility like that.
- AndrewKemendo 1y agoUltimately it’s up to the SSO/SSM/facility manager to make the risk call, and that’s largely based on commander guidance and DSCID inspections from the HQ SSO. Plenty of shenanigans in JSOC scifs that wouldn’t fly on NSA campus.
- drewg123 1y ago
- reactordev 1y agoAwesome read except I have one nit. Instead of writing translating functions to convert everything from US Customary units to Unity, Metric, and the rest of sanity, you should have converted everything to metric in the formulas. Rewritten the math. It's not that hard, it's not that difficult, saves you all those function calls, improves performance, and simplifies the math a whole bunch. Air density can become pliable, controllable. Thrust velocities match projectile spec velocities (m/s) making calculating intersect a breeze. Trust me, you want to convert the FORTRAN math into standard metric. They didn't believe in Base10 back then so do the math.
- pmarreck 1y agoI was going to say this! Why not just convert all the constants and units once since the mathematical relationships are the same?
- vazgriz 1y agoHi, author here. I wanted to keep the data tables exactly the same in the C# translation. While formulas can be converted to metric easily, the data tables do not actually have units defined for any of them, so translating them to metric is non-trivial. And the way data is mixed from multiple tables is very complex. So verifying that the calculations have equivalent results in metric is well beyond my ability. Or rather, the best way to verify it would be to write a flight model that uses customary units (what I describe in the article), and then use that to verify that the metric flight model is equivalent. At the end of the day, only the inputs and outputs of the flight model need to be converted, which is just handful of multiplication operations. The flight model is very cheap to run, even with conversions at runtime.
- reactordev 1y agoThis is exactly what unit tests are for. You did the first (hard part), dissecting the Fortran ark for goodies. You built a Unity equivalent (slightly less hard than deciphering ancient text but still high on difficulty). Now, write tests that test those inputs and outputs (translation calls included). Great, now that all the tests pass, change to metric until the tests pass again. I know it sounds daunting. Making a painting does too to someone who doesn’t paint. However, there are steps you can follow that make it super easy to create masterpieces and all the greats follow the same process. So where you translate ft to m or slug/ft to slug/m or however - the surrounding math is perfect for a unit test. Keeping you from having to build another flight model and do analog mark-2 eyeball testing. You could just leave it - someone will pick it up and do the work. *EDIT* I ran some of it through my models and converted AirDataComputer to Kelvin, kg/m, m/s: public class AirDataComputer { /// <summary> /// Density at sea level in kg/m³ (standard atmosphere) /// </summary> public const float SeaLevelDensity = 1.225f; /// <summary> /// Max altitude in meters /// </summary> public const float MaxAltitude = 10668.0f; // ~35,000 ft in meters /// <summary> /// Calculates air data based on velocity and altitude using SI units /// </summary> /// <param name="velocity">Velocity in m/s</param> /// <param name="altitude">Altitude in meters</param> /// <returns>Air data</returns> public AirData CalculateAirData(float velocity, float altitude) { const float baseTemperature = 288.15f; // Sea level temp in K (~15°C) const float minTemperature = 216.65f; // Tropopause temp in K (~ -56.5°C) const float temperatureGradient = 0.0065f; // Lapse rate in K/m const float gamma = 1.4f; // Ratio of specific heats const float gasConstant = 287.05f; // J/(kg·K), specific gas constant for air const float densityPower = 4.14f; altitude = Mathf.Clamp(altitude, 0, MaxAltitude); // Calculate temperature in Kelvin using linear lapse rate model float temperatureFactor = 1.0f - (temperatureGradient * altitude / baseTemperature); float T = Mathf.Max(minTemperature, baseTemperature * temperatureFactor); // Speed of sound in m/s float speedOfSound = Mathf.Sqrt(gamma * gasConstant * T); float altitudeMach = velocity / speedOfSound; // Air density using barometric approximation float rho = SeaLevelDensity * Mathf.Pow(temperatureFactor, densityPower); // Dynamic pressure in Pascals (N/m²) float qBar = 0.5f * rho * velocity * velocity; return new AirData() { altitudeMach = altitudeMach, qBar = qBar }; }
- kjellsbells 1y agoAwesome achievement but I have to say the units stressed me out. I hope that in the real world there's some kind of dimensional analysis code linter that verifies no one is comparing slugs to feet or something, and that altitude doesn't go below zero.
- btrettel 1y agoIn practice, unit checking is almost never done on actual code, though it should be done. From what I recall, some Fortran folks have been trying to get unit checking into the Fortran standard itself since the 1970s without success. I was able to coerce Fortran's type system into checking units, but it comes with quite a few downsides: https://fortran-lang.discourse.group/t/compile-time-unit-checking-in-fortran-some-practical-experiences/8488/1 https://fortran-lang.discourse.group/t/compile-time-unit-che... An approach based on static analysis would not have the downsides I listed, but I personally would prefer being unable to compile the code at all if it had an error that could be detected.
- colechristensen 1y agoElaborate typing is what Ada was for.
- justsomehnguy 1y ago> altitude doesn't go below zero Uhm... https://www.c-130.net/forum/viewtopic.php?p=9974&sid=bb425b372e4e862aeb0b35911829d998#p9974 https://www.c-130.net/forum/viewtopic.php?p=9974&sid=bb425b3...
- dghlsakjg 1y agoYou actually need the altimeter to be capable of reading below 0 in the real world. Aircraft altimeters are based on air pressure. The reference pressure is variable based on atmospheric conditions and is decided by controllers, or in the case of uncontrolled airspace, the matching the altimeter of the known altitude that you took off from. All that is to say, on my home (uncontrolled) airport which is ~10 feet above sea level, I occasionally land at a negative altimeter value since the weather conditions have changed while I am in the air. Assuming that an altimeter reading must be positive is a bad assumption.
- noobermin 1y agoIn keeping with the discussion here a few days ago, this article demonstrates exactly my point about developer types not being the target for computational codes. Their interpolation routine looks extremely verbose already, I cannot imagine them attempting to solve or compute any other more complex formula like that beyond a mere 2d interpolator writing so verbosely like that. The result would be unreadable, to my eyes. Modern fortran has a bit more modern flavour to it, but formulae being so verbose would make the "formula" aspect of a code disappear.
- colechristensen 1y agoMath or engineering people do not have problems with short symbol names, that's it. Also our formulas are complex. If you wrote out many of our formulas with long descriptive variable names the structure and relation between the variables would no longer be readable, there would be many more mistakes. We were educated doing these things on paper with pages and pages of math with these symbols. 20 years later I can still read just this fortran code and guess most of what's going on with no context needed. I have problems reading "developer code" that boil down to "where the hell is the part of the code that actually does something?!" being perpetually lost in layer among layer of abstraction with the relevant connecting pieces far far apart.
- nxobject 1y agoSometimes I dream about a language with a “blessed” editor that just had a rich 2D formula and matrix notation editor. Having context in the form of a formula is sometimes helpful in remembering what a pesky one-off variable name might mean…
- bentt 1y agoThis was such a thorough and entertaining writeup. Felt like art in a way. Utterly useless, but great historical reference and really funny at parts.
- vesrah 1y agoI agree, this was a great read.
- gopla 1y agoGreat writeup! Here is the result of my take on the same process - but translating to JavaScript instead so the simulator runs in the browser. I later added the high fidelity flight dynamics model by translating C code. https://github.com/kristoffer-dyrkorn/flightsimulator https://github.com/kristoffer-dyrkorn/flightsimulator
- throwaway2037 1y agoThis is an epic blog post! In the words of Jerry Maguire: "You had me at hello." This early sentence really hooked me: > While I am a professional software engineer and I have worked in the aerospace industry, that doesn’t mean that I understand what I’m doing. My favourite part: The image comparing X/Y/Z axis between different 3D modelling products: https://vazgriz.com/wp-content/uploads/2025/05/EmVSW5AW8AAoDD9-2048x2048.jpg https://vazgriz.com/wp-content/uploads/2025/05/EmVSW5AW8AAoD... Plus the comment below can make you laugh hard enough to get Coca Cola up your nose! > Mathematically speaking, these are all equally valid. But we all know that Unreal made the worst possible choice
- psunavy03 1y agoThe fact that this person put a snarky (???) next to the concept of measuring airspeed in knots makes me wonder just how familiar they are with aerospace in general. A knot is a standard measurement in part because one nautical mile is equal to one minute of latitude. Which is useful until the day we decide to start measuring lat/long in radians. I know it's fashionable in some circles to dump on everything non-metric, but these things are they way they are because of reasons, and airspeed is generally measured in either knots or Mach.
- fsckboy 1y ago>airspeed is generally measured in either knots or Mach boatspeed is also measure in knots... but only very rarely in Mach (and not even primarily because the speed of sound in water is substantially higher than in air)
- psunavy03 1y agoHistorically, I'm fairly certain airspeed was measured in knots because of boatspeed. In software terms, the problem of navigating over the Earth's surface was forked from boats to planes, and why re-invent the wheel? It also tends to be more of a standard in professional aviation, whereas some small civilian bugsmashers in the US use MPH, presumably because it's easier for the doctors and lawyers of the world to understand after driving their cars, and if you're VFR, who really cares?
- p_l 1y agoUS customary is prevalent because USA after WW2 was the China of aviation - market got flooded by aircraft that had us customary units. Nautical miles and knots were present in long range navigation, especially oceanic
- justsid 1y agoAs someone who works in flight simulation I was also taken back hard by this. We are internally metric all the way, but even so the knot is not a weird unit in this space at all. I also never heard about those coordinate conventions.
- Stevvo 1y agoOf interest: https://github.com/ericstoneking/42 https://github.com/ericstoneking/42 A serious spacecraft simulator. Likewise developed from ancient FORTRAN code, in this case ported to C.
- larholm 1y agoAirplanes need air to fly [citation needed].
- somat 1y agoOn the subject of coordinate axis. I am pretty firmly in the Z-up camp, I mean I understand the Y-up camp, take a normal picture, or perhaps a side-scroller game, Y is up and down, the logical extension to three dimensions is to push z as depth. But I can't do it, I see X and Y as a in a map where the obvious Z direction is up and down. yes minecraft triggers me so hard, don't even get me started.
- burnt-resistor 1y agoIn the late 90's, I worked on porting a FORTRAN reactor simulator to Windows 95/NT/XP. On the order of 30 MLoC for an industry/research joint project that was around 40 years old at the time. It took a long time to compile, but even longer to run. It turned out that disabling swap on Windows was the single biggest runtime performance improvement on machines with around 128-258 MiB of RAM. Windows would cheerfully page out the working set when there was no other non-system source of memory pressure. PS: The time for SMRs was 40 years ago. Renewables radically transformed the economics such that only fusion reactors, geothermal, and tidal are part of a short list of viable alternatives because fossil fuels and fission need to go the way of whale oil and hunting passenger pigeons.
- hdkgijtkr 1y agoI’d heard at least one FBW system was written in Lisp or an interface for it was. I don’t remember which aircraft, but I think the one of the F-15s. It seems like that it was used at that time for some flight system development.