Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
  Signup for free on our forum and benefit from new features!

FFDS Home | TIPS Section | Tutorials Section | Resources Section | Utilities Section

Military | FSDS | Jetliners | Real Planes Section | Gmax | Rotorcraft | Business | Civilian

  HomeHelpSearchLoginRegister  
 
 
Page Index Toggle Pages: 1
Send Topic Print
Gauge needles for tens and hundreds code snippet (Read 2629 times)
11th Jun, 2010 at 12:32pm

Willem   Offline
LDV Engineer
Gmax... can't live with
it, can't live without
it.
Netherlands

Posts: 266
****
 
Hi all,
this may be old news to some (if not most) of you, but i thought i'd post anyway. Maybe someone trying to understand XML has some use for it.

As an excersise for creating 3d gauges which are controlled via a master gauge which contains all the code i tried to make an rpm indicator with two needles.
One of which indicates the hundreds, the other the tens of rpm. (2350 rpm -> large needle between 2300 and 2400, small needle at 50)

The large needle is just a function of the prop rpm but the small needle i created some code for, so i'll focus on that:
Code:
<Value>(A:Prop1 RPM,RPM) (A:Prop1 RPM,RPM) 100 /  flr 100 * - (&gt;L:Prop Needle 10, number)</Value> 


The code above puts a value of 50 into L: Prop Needle 10, number, if the prop rpm is 2350 as it is in this example.

This part rounds off the rpm to the hundred below the actual value (so an rpm of 2350 returns 2300 here) which subsequently gets subtracted from the actual rpm:
Code:
(A:Prop1 RPM,RPM) 100 /  flr 100 * 


How does it work? First divide the rpm by 100 (result 23.50)
Code:
(A:Prop1 RPM,RPM) 100 / 


then apply a flr (floor) to that value (rounds off to the nearest lower integer, result 23)
Code:
(A:Prop1 RPM,RPM) 100 / flr 


then multiply that by 100 (result 2300)
Code:
A:Prop1 RPM,RPM) 100 /  flr 100 * 



Finally this value is subtracted from the actual rpm which in the example results in a value of 50.
Code:
(A:Prop1 RPM,RPM) (A:Prop1 RPM,RPM) 100 /  flr 100 * - 


and that is than inserted into an L:Variable (a user defined variable, shared throughout the model)
Code:
<Value>(A:Prop1 RPM,RPM) (A:Prop1 RPM,RPM) 100 /  flr 100 * - (&gt;L:Prop Needle 10, number)</Value> 


This L:variable can now be used to control 3D-animations or gauge needles in a panel.

In 3d the small gauge needle is animated through a rotation of 359 degrees with 5 keyframes (0-25-50-75-100) and in modeldef.xml (the code that drives the 3d animations) the following code was added:

Code:
 <PartInfo>
        <Name>g1_LhRpm_10_Needle</Name>
        <AnimLength>100</AnimLength>
        <Animation>
            <Parameter>
              <Code>(L:Prop Needle 10, number)</Code>
            </Parameter>
        </Animation>
           </PartInfo> 


What this actually does is associate the L:Variable we just defined in the master gauge to a 3d animation.

For that you need to associate the new entry in modeldef.xml to the animated part in Gmax/Max using the animation manager.
This is explained in the SDK, which by the way is a lot improved over the previous incarnations.

Note:if you make alterations in the Modeldef.xml, do not forget to restart Gmax/Max before you assign the animation or export the model. Otherwise the changes will not be visible. No need to restart if you did not change Modeldef.xml between assigning the animation and exporting the model though.


Hope this is of help to those struggling to understand XML and the strange Reverse Polish Notation it uses.

grt
Willem.


 

Multimedia File Viewing and Clickable Links are available for Registered Members only!!  You need to Login or Register
IP Logged
 
Reply #1 - 22nd Jun, 2010 at 6:48am

anthony31   Offline
Point Pusher
I Love FFDS!

Posts: 28
*
 
Thanks Willem but allow me to introduce to you the magic of modulo.

Code:
(A:Indicated Altitude,feet) 100 %  



Will give you hundreds of feet from the Indicated Altitude variable.

This is how modulo works. It divides Indicated Altitude by 100 and returns the remainder.

So if the Indicated Altitude is 13254' it will return 54 (note that the example given in the SDK is incorrect).

Using modulo saves you the convulted process of dividing the prop1 rpm by 100, rounding off and then multiplying by a hunderd and then subtracting form the original value.

Rewriting your code using modulo it would look like this

Code:
(A:Prop1 RPM,RPM) 100 % (&gt;L:Prop Needle 10, number) 



To extract the 100's value you could use:

Code:
(A:Prop1 RPM,RPM) 100 / flr 10 % 100 * 



If your Prop1 rpm is 2345 the above code would return 300. Note how I've converted to an integer before performing the modulo. I think you have to do this but I'm not sure.
 
IP Logged
 
Reply #2 - 26th Jun, 2010 at 3:55am

Willem   Offline
LDV Engineer
Gmax... can't live with
it, can't live without
it.
Netherlands

Posts: 266
****
 
Roll Eyes

Ah well, me and my cunning elaborate schemes that i thought up when waking up in a sweat one night... Embarrassed

Thanks a lot for pointing that out to us!!
Yours is obviously the way to go.

Thanks!  Smiley
grt
Willem.

 

Multimedia File Viewing and Clickable Links are available for Registered Members only!!  You need to Login or Register
IP Logged
 
Reply #3 - 27th Jun, 2010 at 1:14am

anthony31   Offline
Point Pusher
I Love FFDS!

Posts: 28
*
 
No problems Willem.

Actually, looking through some of the gauges for the aircraft I have shows that quite a few developers use something like the method you describe. It's just that I remember modulo from my old programming days so I knew when it came time to do the altitude needles I would need it. I looked it up in the SDK and was confused as the example given in SDK is just plain wrong. I had to look modulo up on wikipedia just to make sure I was right.

Here is what the FSX SDK says about modulo which looks like they got it mixed up with the flr command:

%  taking modulo
parameters: 1
example:  5.3 %
result: 5

The example above from the SDK is not correct. A correct expression for modulo requires 2 parameters with the first parameter being divided by the second parameter and the remainder returned as the result: eg:

5 3 % = 2.

5 is divided by 3 and the remainder 2 is returned as the result:


Another example would be 25 4 % = 1 (25 divided by 4 with the remainder being 1)
 
IP Logged
 
Reply #4 - 27th Jun, 2010 at 9:31am

Fr. Bill   Offline
YaBB Moderator
I used to have a life:
now I have GMax...
Hammond, IN

Gender: male
Posts: 5426
*****
 
Several years ago I posted an explanation of modulus at AVSIM:

Multimedia File Viewing and Clickable Links are available for Registered Members only!!  You need to Login or Register

Now posted as a Wiki article at FS-Developer:
Multimedia File Viewing and Clickable Links are available for Registered Members only!!  You need to Login or Register

and at Flightsim.com's Wiki:
Multimedia File Viewing and Clickable Links are available for Registered Members only!!  You need to Login or Register
 

Fr. Bill
Gauge Programming - 3d Modeling Eaglesoft Development Group Intel Core 2 Quad Q6600-4 GB DDRII Crucial PC6400-500 GB SATA-ATI Radeon HD2400 Pro 256MB
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print