Cannon simulation

Eggheads talking about bytes and stuff.
Post Reply
User avatar
Krishty
Site Admin
Posts: 1271
Joined: 2022-Jan-09, 00:59

Cannon simulation

Post by Krishty »

TFXplorer gets a cannon API. It’ll be much like the engine API that was added lately.

As a start, I have repaired the rendering of bullets. (It was broken since I separated the legacy EF2000/TAW renderer away from TFXplorer’s renderer.) This commit is not yet pushed; I will probably push it after some testing together with the new API.

Unforeseen Consequence 1: Ammo

Since TFXplorer has to take care not only of managing the cannon’s recoil/SFX/GFX, but also of its bullet physics, I have to add an API for ammo as well. This lead to the question: When should ammo be assigned to a plane?

I have those vast air routes with hundreds of planes. They cannot be simulated efficiently if planes start to keep track of every round of ammo. So the ammo question should be resolved only when a plane transitions from the en route or parked state to the simulated state.

This is also a good point for dynamic campaign simulation to roll the dice over remaining ammo for flights that have taken part in combat.

There was, however, no vehicle API for all of this yet. So I had to add it. I’m still cleaning up the vast junk I found along the way.

Unforeseen Consequence 2: Vibration

TFXplorer’s screen will shake in a few situations:
  1. Rolling fast on the ground, for simulating a bumpy ride.
  2. When huge aerodynamic forces affect the vehicle.
I wanted to kindly add “firing a 20 mm gatling gun at 100 rounds per second” to the list. This was when I realized how stupid it was to add it to the F-22 code when there is already cannon physics simuation in the core.

Here’s what the F-22 code already needs to take care of:
  1. Compute vibration dependent on gear load and speed.
  2. Compute vibration dependent on aerodynamic force.
  3. Do not shake the screen if the game is paused.
  4. Do not shake the screen if in exterior view.
This is pretty hard to get right, so it’s stupid to duplicate this code for every single plane. I figured I should rather move it to the core. It could be nicely connected to the recoil computation.

This, however, uncovered a few bugs in how F-22 pilots move their heads under g load. I gotta figure this one out before I can complete the cannon API …
mikew
Data Genius
Posts: 558
Joined: 2022-Jan-09, 20:21

Re: Cannon simulation

Post by mikew »

...I figured I should rather move it to the core...
Careful! That could be a slippery slope. :)
*looks at size of Linux kernel these days*

Can you provide any top level indication how these API's might be used?
User avatar
Krishty
Site Admin
Posts: 1271
Joined: 2022-Jan-09, 00:59

Re: Cannon simulation

Post by Krishty »

mikew wrote: 2022-May-14, 12:11Can you provide any top level indication how these API's might be used?
Sure!

You define a cannon model, e.g. “M61A2”. It provides a basic description of how the cannon works – caliber, rpm, etc. Independent from any specific vehicle.

In your vehicle, e.g. “F-22”, you declare a cannon that is based on said model. You provide its position relative to the aircraft’s logical center and the direction its muzzle is pointing to.

You also define at least one model of ammunition. For the F-22, you need “20×120 mm” and “20×120 mm tracer”. This provides a description of bullet caliber, mass, muzzle velocity, tracer color, etc. It is independent of cannon.

When TFXplorer asks you to start the simulation of a type “F-22” vehicle, it already created a “M61A2” type cannon for you because that’s what you declared for vehicles of this type. You feed 480 rounds of ammunition into it (there’s a function for that) using the two models of ammunition you declared earlier.

(The parameters for that are rather clumsy to allow for “every fifth round is a tracer, and so are the last 50 rounds” …)

Finally, in your vehicle logic, you can fire the cannon at will. Since TFXplorer knows about the location of the cannon and the ammo used, it can compute the recoil and feed it back into the physics simulation. It knows about the RPM, hence it handles stuff like “100 bullets per second being fired, but physics run at 120 Hz, so there must be some interpolation done”. If you defined a “trail” in your vehicle (the same API used for contrails and wingtip vortices), you can link it to the cannon and TFXplorer will emit smoke whenever a round is fired (still under construction). If you provided sound effects, TFXplorer will play them for you.

So, you define ammunition models and cannon models. You link a cannon model to a vehicle model to instantiate a specific cannon. You link ammunition models to a cannon to instantiate bullets. Only thing left is telling TFXplorer when to fire the cannon.
mikew
Data Genius
Posts: 558
Joined: 2022-Jan-09, 20:21

Re: Cannon simulation

Post by mikew »

Thanks! Sounds like it's going to be very flexible. 8-)
User avatar
Krishty
Site Admin
Posts: 1271
Joined: 2022-Jan-09, 00:59

Re: Cannon simulation

Post by Krishty »

Cannon API is pushed.

We finally have the ability to freely assign colors to bullet tracers. (Previously, they were bound to TFX palette indices!) Can’t wait to do some fireworks 🙂

BTW, you can
  1. fire the cannon
  2. while firing, switch to Explorer mode
  3. place yourself in a nice position far away
  4. hit F5 to spawn another plane
  5. observe the bullets fly.
At least that’s what I like to do for debugging and for fun 🙂
Post Reply