From 39c82918cd53edba93cdb0592807fa8a69a73581 Mon Sep 17 00:00:00 2001 From: ehofman Date: Tue, 29 Mar 2005 11:26:49 +0000 Subject: [PATCH] Melchior has already a nice collection of animation type nasal classes. These will be converted in a Nasal toolbox so everybody can use them without reinventing the wheel. --- Nasal/aircraft.nas | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Nasal/aircraft.nas diff --git a/Nasal/aircraft.nas b/Nasal/aircraft.nas new file mode 100644 index 000000000..a7e2dd177 --- /dev/null +++ b/Nasal/aircraft.nas @@ -0,0 +1,61 @@ +# door: class for objects moving at constant speed, with the ability to +# reverse moving direction at any point. Appropriate for doors, canopies, etc. +# +# SYNOPSIS: +# door.new(, [, ]); +# +# property ... parent property (available as door.base) +# swingtime ... time in seconds for full movement (0 -> 1) +# startpos ... initial position (default: 0) +# +# PROPERTIES: +# /position-norm (type="double") +# /enabled (type="bool") +# +# EXAMPLE: +# canopy = aircraft.door.new("sim/model/foo/canopy", 5); +# canopy.open(); +# +door = { + new : func { + d = { parents: [door] }; + d.base = props.globals.getNode(arg[0], 1); + d.pos = d.base.getNode("position-norm", 1); + d.enabled = d.base.getNode("enabled", 1); + d.enabled.setBoolValue(1); + + d.swingtime = arg[1]; + pos = if (size(arg) > 2 and arg[2] != nil) { arg[2] } else { 0 }; + d.pos.setDoubleValue(pos); + d.target = pos < 0.5; + return d; + }, + + # door.enable(bool) -> set /enabled + enable : func { me.enabled.setBoolValue(arg[0]) }, + + # door.setpos(double) -> set /position-norm without movement + setpos : func { me.pos.setValue(arg[0]); me.target = arg[0] < 0.5 }, + + # double door.getpos() -> return current position as double + getpos : func { me.pos.getValue() }, + + # door.close() -> move to closed state + close : func { me.move(0) }, + + # door.open() -> move to open state + open : func { me.move(1) }, + + # door.toggle() -> move to farther away end position + # (0 -> 1, 1 -> 0, 0.3 -> 1, 0.6 -> 0) + toggle : func { me.move(me.target) }, + + # door.move(double) -> move to arbitrary position + move : func { + time = abs(me.getpos() - arg[0]) * me.swingtime; + interpolate(me.pos, arg[0], time); + me.target = !me.target; + }, +}; + +