We have all seen them, whether it be a Hobbs gauge, a "digital drum" on a PFD, or the odometer in your old car. Most of time these show up in FS, they are not very smooth. While an instant movement from one number to the next might be a desired effect, I wanted a smooth rolling drum, like the mechanical one in your old car.
There are some Hobbs gauges out there that achieve this effect, however, I found there logic extremely complex. I am not a highly skilled computer programmer, but I can usually grasp the logic behind something fairly easily. So I decided to give my own logic a try.
For those of you out there like me, that can't always look at code and immediately figure it out, I am going to take you through my logic step by step. A tutorial of sorts.
Here we go:
Lets make a 3 digit drum, that displays your current airspeed. To keep the code easier to read, we will use a macro named IAS that simply refers to the indicated airspeed (A:Airspeed indicated, knots).
Setting up the drum:
Not going to go into detail here, because every drum will be different. Basically, what you need to do is use a image that has a strip of numbers. The strip must start with 0 and end with 0 for the motion to be fluid ( 0 1 2 3 4 5 6 7 8 9 0 ). If you want you drum to rotate downward, you need the 1 towards the bottom and 9 towards the top, on a vertical strip. Other configurations would be possible, but that is how this one is set up. Apply a mask so only one digit shows, then use a shift to move the numbers. A non-linear table makes setup easier, but isn't necessary if you use the scale argument. Either way works. Make 3 identical elements, shifting the float position over for each one.
From here on, lets assume @IAS is 139.932, unless otherwise noted.
Digit 1:
**NOTE: I'll refer to the rightmost digit as digit 1. ie, in the number 321, digit 1 is the 1, digit 2 is the 2, and digit 3 is the 3
This is the easy one, since it is always rotating if the airspeed is changing. All we have to do here is feed the single digit and it's decimal to the shift expression. Even though the decimal isn't shown on the drum, it is needed so that the motion is fluid. It is also important in the other 2 digits, as you will see later. Anyways, chopping off the hundreds and tens is easy, all you have to do is divide by 10, and keep only the remainder. This is called taking the modulo, and the SDK provides that function with % operator. Note that the SDK has a misprint on how this operator works, so don't get confused. Taking the modulo requires 2 numbers to be on the stack, it divides them, and puts the remainder on the stack.
Stack: 10 3 %
Stack: 1
But we will only be modulo'ing
(don't think that is a word) by 10 and 100, which will strip the nubmer to only single digit, or double digits respectivly, also leaving the decimal in both cases.
So our script for the digit 1
gives us:
Stack: 139.932 10 %
Stack: 9.932
The stack is done, so our image is shifted 9.932, or just about to the top 0.
BTW, the shift function must be capped 9.999 max value, so that it will start over at 0. This "start over" is surprisingly smooth.
continued...
There are some Hobbs gauges out there that achieve this effect, however, I found there logic extremely complex. I am not a highly skilled computer programmer, but I can usually grasp the logic behind something fairly easily. So I decided to give my own logic a try.
For those of you out there like me, that can't always look at code and immediately figure it out, I am going to take you through my logic step by step. A tutorial of sorts.
Here we go:
Lets make a 3 digit drum, that displays your current airspeed. To keep the code easier to read, we will use a macro named IAS that simply refers to the indicated airspeed (A:Airspeed indicated, knots).
Code:
<Macro id="Indicated Airspeed" Name="IAS">
<MacroValue>(A:Airspeed indicated, knots)</MacroValue>
</Macro>
Setting up the drum:
Not going to go into detail here, because every drum will be different. Basically, what you need to do is use a image that has a strip of numbers. The strip must start with 0 and end with 0 for the motion to be fluid ( 0 1 2 3 4 5 6 7 8 9 0 ). If you want you drum to rotate downward, you need the 1 towards the bottom and 9 towards the top, on a vertical strip. Other configurations would be possible, but that is how this one is set up. Apply a mask so only one digit shows, then use a shift to move the numbers. A non-linear table makes setup easier, but isn't necessary if you use the scale argument. Either way works. Make 3 identical elements, shifting the float position over for each one.
Code:
<Element id="Airspeed Digit 1">
<FloatPosition>68.000,246.000</FloatPosition>
<Image id="drum_digits.bmp" Name="drum_digits.bmp">
<Transparent>True</Transparent>
<Axis>0.000,249.000</Axis>
<Bright>True</Bright>
</Image>
<MaskImage id="drum_digits_mask.bmp" Name="drum_digits_mask.bmp">
</MaskImage>
<Shift id="Shift">
<Scale>0.000,24.000</Scale>
<Expression id="Expression">
<Minimum>0.000</Minimum>
<Maximum>9.999</Maximum>
<Script>@IAS 10 %</Script>
</Expression>
</Shift>
</Element>
From here on, lets assume @IAS is 139.932, unless otherwise noted.
Digit 1:
**NOTE: I'll refer to the rightmost digit as digit 1. ie, in the number 321, digit 1 is the 1, digit 2 is the 2, and digit 3 is the 3
This is the easy one, since it is always rotating if the airspeed is changing. All we have to do here is feed the single digit and it's decimal to the shift expression. Even though the decimal isn't shown on the drum, it is needed so that the motion is fluid. It is also important in the other 2 digits, as you will see later. Anyways, chopping off the hundreds and tens is easy, all you have to do is divide by 10, and keep only the remainder. This is called taking the modulo, and the SDK provides that function with % operator. Note that the SDK has a misprint on how this operator works, so don't get confused. Taking the modulo requires 2 numbers to be on the stack, it divides them, and puts the remainder on the stack.
Stack: 10 3 %
Stack: 1
But we will only be modulo'ing
So our script for the digit 1
Code:
@IAS 10 %
Stack: 139.932 10 %
Stack: 9.932
The stack is done, so our image is shifted 9.932, or just about to the top 0.
BTW, the shift function must be capped 9.999 max value, so that it will start over at 0. This "start over" is surprisingly smooth.
continued...


