• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

3D gauges code sample

Messages
533
Country
france
Hello,

Some of you may know me as a gauge developer, I have a lot of experience in developing 2D gauges that can be used in 2D panels or in 3D panels, mapped on a texture.
Today, most people want to see the "steam gauges" in 3D, directly integrated with the 3D model. This is new to me and I would like to find a sample code that shows how to do this in C/C++. I know how to integrate XML code in a 3D model, but I hate coding in XML, coding in C++ is much easier for me.
So if you can show me a sample code for an altimeter for example, with the animation of 2 rotating needles, that would help. In my opinion, samples are the best way to learn :)

Thanks,
Eric
 
Eric, in a 3d model file you would only need to create animation entries for your needles and specify a single (L:var,unit) for each. Then your C gauge would simply supply input to the (L:var,unit).

For example, for a hundreds needle:
Code:
<Animation name="needle_altimeter_hundreds"  guid="2E99A67C-96CF-4bd1-9FFA-7CAB53671AA3"  length="360" type="Sim" typeParam2="needle_altimeter_hundreds" typeParam="AutoPlay" />

<PartInfo>
    <Name>needle_altimeter_hundreds</Name>
    <AnimLength>360</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:needle_altimeter_hundreds, number)
        </Code>
      </Parameter>
    </Animation>
  </PartInfo>
A thousand's needle would use a clone of the above, but with a different (L:Var, unit) of course. :cool:
 
I would change the AnimLength setting to 100 and have the modeller calibrate the animation key frames to run from 0 to 100 and let the full 360 deg rotation be handled by the exported animation, not the modeldef script.

That way just setting the L var to say 50 for example will put the needle right where it should be for 50.
 
Thank you Guys for your quick reply, I now fully understand.
I guess the C++ code that manages animation is in a usual "gauge", which is invisible, compiled as a DLL that is loaded with the panel.
Or is there any other way to run this code?

Eric
 
Yes, just a normal control gauge that you can place at 0,0,1,1 on the [Vcockpit01] panel.cfg entry.

Jon, I just grabbed what was handy at the moment, but truthfully the number of key frames isn't all that critical. It's a trivial matter to scale the (L:var,unit) for accuracy. One of the most understood things is that the sim will interpolate fractional frames, so it really comes down to the programmer's choice. :cool:
 
Yep. I just mentioned that in the line of keeping both the C++ and XML code as simple as possible and doing the calibration in the 3D model.
 
Eric: the biggest problem you're going to have is figuring out which bit of the C-gauge does the work and which bit does the display. Once you've done that with one or two, it's as if a light goes on and spotting the code divide suddenly becomes a lot easier. If you still want a C-gauge altimeter that is set up to drive both a 2D and a 3D display, PM me. I can't give you the 3D code because it isn't written yet.

When it comes to switches, life gets a little more difficult. All operational instructions (e.g. toggle up, toggle down) have to be done through an XML<->C interface (I call it the vc_handler). If the switch is toggled up, it sets a registered_named_variable to that state. Your display code (both L:var and C) reads the state of the named_variable and changes the display to suit. Although it's tempting inside the C-gauge to use (say) toggle_pos=1 to set the switch to up, don't do it because that can override the L:var input from the VC.

I have this tagged as a new topic for sd2gau but no release date yet. There is a brief 'how to do it' here:

https://www.fsdeveloper.com/wiki/index.php?title=C:_XML_Variables_in_C_Gauges

but I found it a little too brief as it does assume a knowledge of the XML<->C interface that the reader may not have.
 
Last edited:
I might also add, making use of enums, for loops, and const char* arrays will vastly speed up your XML L var and hex event processing as well as make your life a whole lot easier.
 
Eric: the biggest problem you're going to have is figuring out which bit of the C-gauge does the work and which bit does the display. Once you've done that with one or two, it's as if a light goes on and spotting the code divide suddenly becomes a lot easier. If you still want a C-gauge altimeter that is set up to drive both a 2D and a 3D display, PM me. I can't give you the 3D code because it isn't written yet.

When it comes to switches, life gets a little more difficult. All operational instructions (e.g. toggle up, toggle down) have to be done through an XML<->C interface (I call it the vc_handler). If the switch is toggled up, it sets a registered_named_variable to that state. Your display code (both L:var and C) reads the state of the named_variable and changes the display to suit. Although it's tempting inside the C-gauge to use (say) toggle_pos=1 to set the switch to up, don't do it because that can override the L:var input from the VC.

I have this tagged as a new topic for sd2gau but no release date yet. There is a brief 'how to do it' here:

https://www.fsdeveloper.com/wiki/index.php?title=C:_XML_Variables_in_C_Gauges

but I found it a little too brief as it does assume a knowledge of the XML<->C interface that the reader may not have.
Thank you Dai for this information. Managing switches in XML is something I already know, I used this several times to manage the virtual cockpit parts, especially in the Wilco Airbus Series overhead and pedestal. Even if they were presented in 2D, most switches and rotating knobs were also modeled in 3D for the VC and had to be animated accordingly.

Eric
 
Back
Top