From 00738f22f754ee58b8f33c17d19953b3452075cc Mon Sep 17 00:00:00 2001 From: david Date: Sat, 2 Mar 2002 16:07:42 +0000 Subject: [PATCH] Added min/max parameters to clamp range of movement. These are actually very powerful when combined with factor and offset -- for example, on the C310 model the nose wheel can now retract completely before the doors start closing. --- src/Main/model.cxx | 18 +++++++++++++++++- src/Main/model.hxx | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Main/model.cxx b/src/Main/model.cxx index 3cf6c3031..32237ee4a 100644 --- a/src/Main/model.cxx +++ b/src/Main/model.cxx @@ -231,6 +231,18 @@ FGAircraftModel::read_animation (const string &object_name, animation.position = node->getFloatValue("initial-position", 0); animation.offset = node->getFloatValue("offset", 0); + if (node->hasValue("min")) { + animation.has_min = true; + animation.min = node->getFloatValue("min"); + } else { + animation.has_min = false; + } + if (node->hasValue("max")) { + animation.has_max = true; + animation.max = node->getFloatValue("max"); + } else { + animation.has_max = false; + } animation.factor = node->getFloatValue("factor", 1); // Get the center and axis @@ -238,7 +250,7 @@ FGAircraftModel::read_animation (const string &object_name, animation.center[1] = node->getFloatValue("center/y-m", 0); animation.center[2] = node->getFloatValue("center/z-m", 0); animation.axis[0] = node->getFloatValue("axis/x", 0); - animation.axis[1] = node->getFloatValue("axis/y", 1); + animation.axis[1] = node->getFloatValue("axis/y", 0); animation.axis[2] = node->getFloatValue("axis/z", 0); sgNormalizeVec3(animation.axis); @@ -264,6 +276,10 @@ FGAircraftModel::do_animation (Animation &animation, long elapsed_ms) animation.position = ((animation.prop->getFloatValue() + animation.offset) * animation.factor); + if (animation.has_min && animation.position < animation.min) + animation.position = animation.min; + if (animation.has_max && animation.position > animation.max) + animation.position = animation.max; animation.setRotation(); return; } diff --git a/src/Main/model.hxx b/src/Main/model.hxx index 685c37d0e..ac23895c5 100644 --- a/src/Main/model.hxx +++ b/src/Main/model.hxx @@ -49,6 +49,10 @@ private: float factor; float offset; float position; + bool has_min; + float min; + bool has_max; + float max; sgVec3 center; sgVec3 axis; void setRotation ();