Melchior FRANZ wrote:
> How will this sample code react, if the door has already opened half
> way and a second trigger happens? Will it stop immediately (like the
> current code does) and start to close?
Yes. I forgot to mention that feature of your original: it was very
slick. If all you want to do is interpolate from the current value to
the desired value over N seconds, then it would be a one-liner. I
have to calculate the delta time value based on the current property
value to make the swing rate constant, which is why the function isn't
completely trivial.
Here's another variant (XML snipped this time) that uses a Node object
to be just a little cleaner. Note that the swingTime is modulated by
the amount of "distance" the property has to travel though to get to
its target.
prop = props.globals.getNode("/controls/rear/door", 1);
prop.setDoubleValue(0);
swingTime = 2.5; # Time to swing from open to closed
target = 1; # Start closed, so initial target is "open"
toggleDoor = func {
val = prop.getValue();
time = abs(val - target) * swingTime;
interpolate(prop, target, time);
target = !target;
}
_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel