• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

3D gauges code sample

#1
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
 

n4gix

Resource contributor
#2
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:
 

JB3DG

Resource contributor
#3
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.
 
#4
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
 

n4gix

Resource contributor
#5
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:
 

JB3DG

Resource contributor
#6
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.
 

DragonflightDesign

Resource contributor
#7
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:

n4gix

Resource contributor
#8

JB3DG

Resource contributor
#9
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.
 
#10
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