Howto:Animate canopy or doors: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(add link)
m (Added link to nasal implementation for further reference)
 
Line 1: Line 1:
Example: A canopy
==Nasal implementation==
The default door implementation features simple door movement.
It also supports advanced features like init with positions other than "closed", as well as transition methods for arbitary movement.
See [https://sourceforge.net/p/flightgear/fgdata/ci/next/tree/Nasal/aircraft.nas FGDATA Nasal/aircraft.nas]
 
==Example: A canopy==


Create a canopy object that uses the method in aircraft.door for animation.
Create a canopy object that uses the method in aircraft.door for animation.
Line 41: Line 46:
</syntaxhighlight>
</syntaxhighlight>
The Nasal code runs the toggle method of object canopy created above.
The Nasal code runs the toggle method of object canopy created above.


[[Category:Aircraft enhancement|Animate models]]
[[Category:Aircraft enhancement|Animate models]]
[[Category:Howto|Animate models]]
[[Category:Howto|Animate models]]
[[Category:Modeling|Animate models]]
[[Category:Modeling|Animate models]]

Latest revision as of 07:41, 5 October 2018

Nasal implementation

The default door implementation features simple door movement. It also supports advanced features like init with positions other than "closed", as well as transition methods for arbitary movement. See FGDATA Nasal/aircraft.nas

Example: A canopy

Create a canopy object that uses the method in aircraft.door for animation. In a Nasal file of the aircraft that loads at start-up add:

var canopy = aircraft.door.new ("/controls/canopy/", 5);

This creates a node in the property tree that contains two properties, /controls/canopy/position-norm and /controls/canopy/enabled, and sets the transition time to 5 seconds.

In the model file add the animation:

 <animation>
  <type>rotate</type>
  <object-name>canopy</object-name>
  <property>/controls/canopy/position-norm</property>
  <factor>55</factor> <!-- The rotation in degrees -->
  <center>
   <x-m>-2.7165</x-m>
   <y-m>0.0</y-m>
   <z-m>1.2040</z-m>
  </center>
  <axis>
   <x>0</x>
   <y>1</y>
   <z>0</z>
  </axis>
 </animation>

In the -set file add a binding to open/close the canopy. Eg.

	<key n="4">
		<name>Ctrl-d</name>
	        <desc>Toggle Canopy</desc>
	          <binding> 
	          	<command>nasal</command>
			<script>MyAircraft.canopy.toggle();</script>
		  </binding>
	</key>

The Nasal code runs the toggle method of object canopy created above.