• 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.

Connect C++ variable to 3d cockpit via modeldef.xml

Messages
18
Country
italy
Hi to all,

I'm working on a 3d cockpit, following this "standard" procedure:

  1. create an XML variable in modeldef.xml file, using simulator token variables. Example:
    Code:
        <PartInfo>
          <Name>needle_g_force</Name>
          <AnimLength>85</AnimLength>
          <Animation>
            <Parameter>
              <Code>(A:G FORCE, GForce) 10 * 50 + 0 max 170 min 2 /</Code>
            </Parameter>
          </Animation>
          <MouseRect>
            <Cursor>Hand</Cursor>
            <TooltipText>GFORCE %((A:G FORCE, GForce))%!2.1f! g</TooltipText>
          </MouseRect>
        </PartInfo>
  2. in 3dsmax, I link an animated object (es, a needle) with that variable via FSTools
  3. the 3d object is exported as .x file, with an associated .xanim file containing the animation description
  4. via XToMdl.exe tool, I convert the .x file in an .mdl file, to be used as internal model for my airplane
This approach works fine, but has several drawbacks (postfix notation, difficult debugging, etc).

What I would like to do is create a custom variable, to be used in substitution of default variables inside modeldef.xml. Continuing the previous example, I would create a custom variable MY_G_FORCE:
Code:
//C++
bool GForceGaugeCallback::GetPropertyValue (SINT32 id, FLOAT64* pValue)
{
   ...
   FLOAT64 gforce = aircraft_varget(get_aircraft_var_enum("G FORCE"), get_units_enum("GForce"), 0);
   gforce = 10*gforce + 50;
   *pValue = gforce < 0  ?  0 : (gforce > 170) ? 170 : gforce;
   *pValue /= 2;
...
}

and then refer it in XML:
Code:
<!--modeldef.xml-->
  <PartInfo>
   <Name>needle_g_force</Name>
   <AnimLength>85</AnimLength>
   <Animation>
       <Parameter>
         <Code>(L:MY_G_FORCE, GForce)</Code>
       </Parameter>
   </Animation>
    ...
  </PartInfo>

I worked with Cabin Comfort example, and while it works fine as 2D gauge, I was unable to use its variables in modeldef.xml for 3D gauges: I tried to connect to its variable BankAngle, using all of the following:
  1. <Code>(C:CABIN:BankAngle, degrees)</Code>
  2. <Code>(C:BankAngle, degrees)</Code>
  3. <Code>(C:CABIN:BankAngle)</Code>
  4. <Code>(L:CABIN:BankAngle, degrees)</Code>
  5. <Code>(L:BankAngle, degrees)</Code>
but no luck. It was always evaluated to zero.

Then I went in debug mode in C++, and I saw that the function bool CABINGaugeCallback :: GetPropertyValue (SINT32 id, FLOAT64* pValue) is called only for updating the 2D gauge, and not for 3D gauge.

As you can see in Cabin Comfort example, the variable is referred in this section of CabinComfort.xml:
Code:
        <Element id="Element">
            <FloatPosition>120.000,55.000</FloatPosition>
            <GaugeText id="GaugeText">
                <Bold>True</Bold>
                <FontColor>yellow</FontColor>
                <FontHeight>11</FontHeight>
                <GaugeString>%((C:CABIN:BankAngle))%!2.2f!</GaugeString>
                <HorizontalAlign>RIGHT</HorizontalAlign>
                <Size>80,13</Size>
                <Transparent>True</Transparent>
            </GaugeText>
        </Element>

Does anybody have any suggestion? I'm really interested in porting all of the logic in C++ as I'm a developer, and I feel much more comfortable with it than with XML.

Thanks very much in advance!
Mauro
 
What I would like to do is create a custom variable, to be used in substitution of default variables inside modeldef.xml

As you have already noticed, custom (C: ) vars are not supported in modeldef.xml scripts.

And the Cabin Comfort method is not a suitable example in this case.

You only need to work with LVars from inside your C++ gauge, like described in the Wiki's reference.
Also there is no problem to keep their default units instead of number, they are supported in XML scripts (modeldef included).

Tom
 
Thanks for all responses. I have an update. I kept on working on Cabin Comfort, following these steps:
  1. in modeldef I connected the animation to the variable (L:BankAngle, number)
  2. in FSX, I opened the Cabin Comfort panel, and I saw the 3d part following correctly the variable
  3. unfortunately, as I removed the Cabin Comfort panel, the 3d part stopped moving
Using C++ debugger, I saw that the update functions are called only if the Cabin Comfort panel is opened.

So, the problem is: how can I trigger a callback from modeldef to C++, in order to update the variable?

Thanks,
Mauro
 
So, the problem is: how can I trigger a callback from modeldef to C++, in order to update the variable?

You can't. Did you read my former post?

The Cabin Comfort method is for building generic .dll modules that must be declared in DLL.XML file. Not suitable for using them as gauges defined in panel.cfg.

Tom
 
Hi Tom,

I understand Cabin Comfort is not the perfect example for my needs but - as far as I know - it's the only one provided by FSX, except for the SDK example, which is even worst.

I took a look at the wiki http://www.fsdeveloper.com/wiki/index.php?title=C:_XML_Variables_in_C_Gauges, as suggested by Naruto-kun, but even there it's not clear in which method I should put the updating code. Have you any hint?

Thank you very very much, and sorry for trivial questions ;)
Mauro
 
Back
Top