From 8f1d2f7bc9f5949f8c22b07f27fe7c5a131a8168 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 26 Feb 2002 14:30:04 +0000 Subject: [PATCH] Added rotation animations, and a factor parameter for scaling. --- src/Main/model.cxx | 28 +++++++++++++++++++++++++++- src/Main/model.hxx | 4 +++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Main/model.cxx b/src/Main/model.cxx index cd2866bb0..d1b4233f4 100644 --- a/src/Main/model.cxx +++ b/src/Main/model.cxx @@ -182,6 +182,13 @@ FGAircraftModel::read_animation (const SGPropertyNode * node) if (type_name == "spin") { SG_LOG(SG_INPUT, SG_INFO, "Reading spin animation"); animation.type = Animation::Spin; + } else if (type_name == "rotate") { + SG_LOG(SG_INPUT, SG_INFO, "Reading rotate animation"); + animation.type = Animation::Rotate; + } else if (type_name == "none") { + SG_LOG(SG_INPUT, SG_INFO, "Reading disabled animation"); + animation.type = Animation::None; + return animation; } else { animation.type = Animation::None; SG_LOG(SG_INPUT, SG_ALERT, "Unknown animation type " << type_name); @@ -213,6 +220,9 @@ FGAircraftModel::read_animation (const SGPropertyNode * node) animation.prop = fgGetNode(node->getStringValue("property", "/null"), true); + animation.position = node->getFloatValue("initial-position", 0); + animation.factor = node->getFloatValue("factor", 1); + // Get the center and axis animation.center_x = node->getFloatValue("center/x-m", 0); animation.center_y = node->getFloatValue("center/y-m", 0); @@ -231,7 +241,8 @@ FGAircraftModel::do_animation (Animation &animation, long elapsed_ms) case Animation::None: return; case Animation::Spin: { - float velocity_rpms = animation.prop->getDoubleValue() / 60000.0; + float velocity_rpms = animation.prop->getDoubleValue() + * animation.factor / 60000.0; animation.position += (elapsed_ms * velocity_rpms * 360); while (animation.position >= 360) animation.position -= 360; @@ -248,6 +259,21 @@ FGAircraftModel::do_animation (Animation &animation, long elapsed_ms) animation.transform->setTransform(animation.matrix); return; } + case Animation::Rotate: { + animation.position = animation.prop->getFloatValue() * animation.factor; + sgMakeTransMat4(animation.matrix, -animation.center_x, + -animation.center_y, -animation.center_z); + sgVec3 axis; + sgSetVec3(axis, animation.axis_x, animation.axis_y, animation.axis_z); + sgMat4 tmp; + sgMakeRotMat4(tmp, animation.position, axis); + sgPostMultMat4(animation.matrix, tmp); + sgMakeTransMat4(tmp, animation.center_x, + animation.center_y, animation.center_z); + sgPostMultMat4(animation.matrix, tmp); + animation.transform->setTransform(animation.matrix); + return; + } default: return; } diff --git a/src/Main/model.hxx b/src/Main/model.hxx index c68bcc75d..651462a3e 100644 --- a/src/Main/model.hxx +++ b/src/Main/model.hxx @@ -38,13 +38,15 @@ private: { enum Type { None, - Spin + Spin, + Rotate }; string name; Type type; ssgTransform * transform; sgMat4 matrix; SGPropertyNode * prop; + float factor; float position; float center_x; float center_y;