Live data from Hacker News

Translating a Fortran F-16 Simulator to Unity3D

vazgriz.com

21–30 of 129 posts

Re: Translating a Fortran F-16 Simulator to Unity3D

#21
post #6

> 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!

not sure why would i want that.

Now to get the 3rd element from array, you have to know the start index, so another parameter to pass to function.

Re: Translating a Fortran F-16 Simulator to Unity3D

#22

I'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?

They 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.

Re: Translating a Fortran F-16 Simulator to Unity3D

#23

I'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?

Would 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? :)

Ok but if you did a global find-replace for "meters" with "smoots" do you think that the simulated plane would crash?

Re: Translating a Fortran F-16 Simulator to Unity3D

#25

Earlier quoted context omitted.

Would 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? :)

Ok but if you did a global find-replace for "meters" with "smoots" do you think that the simulated plane would crash?

Ah but smoots would still follow the same maths as a meter right?

Re: Translating a Fortran F-16 Simulator to Unity3D

#26
post #6

> 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!

not sure why would i want that. Now to get the 3rd element from array, you have to know the start index, so another parameter to pass to function.

Your issue is you are trying to work out how use to this feature as a zero based array.

EDIT (for more explanation): I have an input value from -10 to 100. I want to use this value to lookup something in a table. IN a ero indexed world I have to know what the lowest value is and subtract that from the input value to get to zero (so "another parameter to pass to function").

With an arbitrary start index the array is just indexed from the lowest value (-10). There is nothing more needing to be passed in.

Re: Translating a Fortran F-16 Simulator to Unity3D

#27

I'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?

They don‘t, but they have to be consistent. You wouldn‘t want to apply a hundred-fold torque because you mixed up your units.

Re: Translating a Fortran F-16 Simulator to Unity3D

#28
post #18
post #6

> 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!

I'd agree with 1-based indexing problems, but not 0-based, which seems very natural. And if you have -2-based, I'd argue that perhaps you don't want an array.

I think it's down to personal preferences/how you think. I haven't actually used any languages that didn't have 0 based indexing, but I remember it being very painful and super unintuitive to learn, it just didn't make sense at all (still doesn't, but it's not a problem for me anymore). I always thought 1 based would make a lot more sense and be way easier to learn.

Re: Translating a Fortran F-16 Simulator to Unity3D

#29
post #6

> 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!

.NET supports this because [Visual] Basic supports it. This can be used from C# - and other languages - but there is no nice syntax supporting it.

  // This also supports multidimensional arrays, that is why the parameters are arrays.
  var array = Array.CreateInstance(elementType: typeof(Int32), lengths: [ 5 ], lowerBounds: [ -2 ]);

  // This does not compile, the type is Int32[*], not Int32[].
  // Console.WriteLine(array[0]);

  array.SetValue(value: 42, index: -2);

  Console.WriteLine(array.GetValue(-2));
Post reply on HN