FlightGear飞行模拟器

标题: 摇杆配置与XML编写 [打印本页]

作者: VeyronC    时间: 2016-11-8 21:04
标题: 摇杆配置与XML编写
本帖最后由 VeyronC 于 2016-11-8 21:16 编辑

      USB 接上 Mad-Catz-FLY5-Stick 摇杆之后能自动识别到,默认状态下,油门、副翼、升降舵可用,方向舵等其他操作需要自己配置 xml 文件。
      进入 FG 后,点 Help -> Joystick Configuration,可以进入摇杆配置界面,里面可以查看路径和配置操作。
      若点击 ResetConfiguration,会自动使用 C:\ProgramFiles\FlightGear2.10.0.3\data\Input\Joysticks\Default\joystick.xml 下的配置文件。
      若更改配置后,会自动跳到 C:\FlightGear\flightgear-debug\Input\Joysticks\Mad-Catz-FLY5-Stick.xml (这个路径是之前用另一个版本自己编译的路径,为何跳这了?)
      点击 Refresh Joysticks 可以将更改保存。
      Configuration File 处显示了文件路径。
file:///C:/Users/cpr/AppData/Local/Temp/msohtmlclip1/01/clip_image002.png
      摇杆里的移动杆对应 xml 里的标签 <axis n="几"></axis>
      摇杆里的按键对应 xml 里的标签 <button n="几"></button>,对于赛钛客FLY5这款,对应按键上的数字是这里的 几+1。这个可以在上面的 Joystick Configuration 中试出来。
      根据示例代码设置,并参考FG文件夹里面的 data\keyboard.xml 文件来配置。因为FLY5这款的移动杆有限,那么方向舵我想用按键来设置,就先看 keybord.xml 中内容和方向舵移动有关的按键项<key>,对应移植过去给<button>标签之内即可。
   
<key n="364">
  
  <name>Insert</name>
  
  <desc>Move rudder left</desc>
  
  <repeatable type="bool">true</repeatable>
  
  <binding>
  
   <command>property-adjust</command>
  
   <property>/controls/flight/rudder</property>
  
   <step type="double">-0.05</step>
  
  </binding>
  
  
</key>
  
   
<button n="9">
  
    <desc type="string">Custom</desc>
  
    <repeatable type="bool">true</repeatable>
  
    <binding>
  
      <command type="string">property-adjust</command>
  
      <property type="string">/controls/flight/rudder</property>
  
      <step type="double">-0.05</step>
  
    </binding>
  
  
  </button>
  
      设置视角切换,可以在 JoysickConfiguration 中设置某个按键为 View Cycle Forwards。
      一套简易实用的自定义 xml 摇杆配置代码如下:
   
<?xml version="1.0"?>
  
  
<PropertyList>
  
  <name type="string">Mad Catz  F.L.Y.5 Stick</name>
  
  <axis>     <!--若不写n值,默认为0-->
  
    <desc type="string">Aileron</desc>
  
    <binding>
  
      <command type="string">property-scale</command>
  
      <property type="string">/controls/flight/aileron</property>
  
      <dead-band type="double">0</dead-band>
  
      <factor type="double">1</factor>
  
      <offset type="double">0</offset>
  
    </binding>
  
  </axis>
  
  
  <axis n="1">
  
    <desc type="string">Elevator</desc>
  
    <binding>
  
      <command type="string">property-scale</command>
  
      <property type="string">/controls/flight/elevator</property>
  
      <dead-band type="double">0</dead-band>
  
      <factor type="double">-1</factor>
  
      <offset type="double">0</offset>
  
    </binding>
  
  </axis>
  
  
  <axis n="2">
  
    <desc type="string">Throttle</desc>
  
    <binding>
  
      <command type="string">nasal</command>
  
      <script type="string">controls.throttleAxis();</script>
  
    </binding>
  
  </axis>
  
  
  <axis n="6">
  
    <desc type="string">View  (horizontal)</desc>
  
    <low>
  
      <binding>
  
        <command type="string">nasal</command>
  
        <script type="string">setprop("/sim/current-view/goal-heading-offset-deg", getprop("/sim/current-view/goal-heading-offset-deg") + 30);</script>
  
      </binding>
  
    </low>
  
    <high>
  
      <binding>
  
        <command type="string">nasal</command>
  
        <script type="string">setprop("/sim/current-view/goal-heading-offset-deg", getprop("/sim/current-view/goal-heading-offset-deg") - 30);</script>
  
      </binding>
  
    </high>
  
  </axis>
  
  
  <axis n="7">
  
    <desc type="string">View  (vertical)</desc>
  
    <low>
  
      <binding>
  
        <command type="string">nasal</command>
  
        <script type="string">setprop("/sim/current-view/goal-pitch-offset-deg", getprop("/sim/current-view/goal-pitch-offset-deg") - 20);</script>
  
      </binding>
  
    </low>
  
    <high>
  
      <binding>
  
        <command type="string">nasal</command>
  
        <script type="string">setprop("/sim/current-view/goal-pitch-offset-deg", getprop("/sim/current-view/goal-pitch-offset-deg") + 20);</script>
  
      </binding>
  
    </high>
  
  </axis>
  
  
  <button>
  
    <desc type="string">Brakes</desc>
  
    <repeatable type="string">false</repeatable>
  
    <binding>
  
      <command type="string">nasal</command>
  
      <script type="string">controls.applyBrakes(1);</script>
  
    </binding>
  
    <mod-up>
  
      <binding>
  
        <command type="string">nasal</command>
  
        <script type="string">controls.applyBrakes(0);</script>
  
      </binding>
  
    </mod-up>
  
  </button>
  
  
  <button n="9">  <!--对应FLY5摇杆上按键10-->
  
    <desc type="string">Custom</desc>
  
    <repeatable type="bool">true</repeatable>
  
    <binding>
  
      <command type="string">property-adjust</command>
  
      <property type="string">/controls/flight/rudder</property>
  
      <step type="double">-0.05</step>
  
    </binding>
  
  </button>
  
  
  <button n="10">
  
    <desc type="string">Custom</desc>
  
    <repeatable type="bool">true</repeatable>
  
    <binding>
  
      <command type="string">property-adjust</command>
  
      <property type="string">/controls/flight/rudder</property>
  
      <step type="double">0.05</step>
  
    </binding>
  
  </button>
  
  
  <button n="13">
  
    <desc type="string">View Cycle  Forwards</desc>
  
    <binding>
  
      <command type="string">nasal</command>
  
      <script type="string">view.stepView(1);</script>
  
    </binding>
  
    <repeatable type="double">0</repeatable>
  
  </button>
  
</PropertyList>
  
  

FlightGear摇杆配置与XML编写.pdf

422.36 KB, 下载次数: 18, 下载积分: 金钱 -2


作者: sunka1982    时间: 2018-4-8 17:20
讲的很清楚,谢谢分享!
作者: ZHANNAH    时间: 2018-4-9 11:19
写的很好,多谢楼主分享
作者: handsomeSun    时间: 2021-5-13 21:40
FEWDFER





欢迎光临 FlightGear飞行模拟器 (https://www.flightgear.org.cn/) Powered by Discuz! X3.2