From 3839d6f777d629ed8d330f07d43ff4681cbcb328 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 23 Feb 2015 21:21:19 +0100 Subject: [PATCH] Simplify controller classes --- components/nifosg/controller.cpp | 22 +++--- components/nifosg/controller.hpp | 118 +++++++++++++------------------ components/nifosg/nifloader.cpp | 8 +-- 3 files changed, 66 insertions(+), 82 deletions(-) diff --git a/components/nifosg/controller.cpp b/components/nifosg/controller.cpp index 4e600c3a1..086e679d6 100644 --- a/components/nifosg/controller.cpp +++ b/components/nifosg/controller.cpp @@ -92,7 +92,7 @@ float ControllerFunction::calculate(float value) return value; } -osg::Quat KeyframeController::Value::interpKey(const Nif::QuaternionKeyMap::MapType &keys, float time) +osg::Quat KeyframeControllerValue::interpKey(const Nif::QuaternionKeyMap::MapType &keys, float time) { if(time <= keys.begin()->first) return keys.begin()->second.mValue; @@ -125,7 +125,7 @@ osg::Quat KeyframeController::Value::interpKey(const Nif::QuaternionKeyMap::MapT return keys.rbegin()->second.mValue; } -osg::Quat KeyframeController::Value::getXYZRotation(float time) const +osg::Quat KeyframeControllerValue::getXYZRotation(float time) const { float xrot = interpKey(mXRotations->mKeys, time); float yrot = interpKey(mYRotations->mKeys, time); @@ -136,7 +136,7 @@ osg::Quat KeyframeController::Value::getXYZRotation(float time) const return (zr*yr*xr); } -KeyframeController::Value::Value(osg::Node *target, const Nif::NIFFilePtr &nif, const Nif::NiKeyframeData *data, +KeyframeControllerValue::KeyframeControllerValue(osg::Node *target, const Nif::NIFFilePtr &nif, const Nif::NiKeyframeData *data, osg::Quat initialQuat, float initialScale) : NodeTargetValue(target) , mRotations(&data->mRotations) @@ -150,7 +150,7 @@ KeyframeController::Value::Value(osg::Node *target, const Nif::NIFFilePtr &nif, , mInitialScale(initialScale) { } -osg::Vec3f KeyframeController::Value::getTranslation(float time) const +osg::Vec3f KeyframeControllerValue::getTranslation(float time) const { if(mTranslations->mKeys.size() > 0) return interpKey(mTranslations->mKeys, time); @@ -158,7 +158,7 @@ osg::Vec3f KeyframeController::Value::getTranslation(float time) const return trans->getMatrix().getTrans(); } -void KeyframeController::Value::setValue(float time) +void KeyframeControllerValue::setValue(float time) { osg::MatrixTransform* trans = static_cast(mNode); osg::Matrix mat = trans->getMatrix(); @@ -200,14 +200,14 @@ void Controller::update() } } -GeomMorpherController::Value::Value(osgAnimation::MorphGeometry *geom, const Nif::NiMorphData* morphData) +GeomMorpherControllerValue::GeomMorpherControllerValue(osgAnimation::MorphGeometry *geom, const Nif::NiMorphData* morphData) : mGeom(geom) , mMorphs(morphData->mMorphs) { } -void GeomMorpherController::Value::setValue(float time) +void GeomMorpherControllerValue::setValue(float time) { if (mMorphs.size() <= 1) return; @@ -223,7 +223,7 @@ void GeomMorpherController::Value::setValue(float time) } } -UVController::Value::Value(osg::StateSet *target, const Nif::NiUVData *data, std::set textureUnits) +UVControllerValue::UVControllerValue(osg::StateSet *target, const Nif::NiUVData *data, std::set textureUnits) : mStateSet(target) , mUTrans(data->mKeyList[0]) , mVTrans(data->mKeyList[1]) @@ -233,7 +233,7 @@ UVController::Value::Value(osg::StateSet *target, const Nif::NiUVData *data, std { } -void UVController::Value::setValue(float value) +void UVControllerValue::setValue(float value) { float uTrans = interpKey(mUTrans.mKeys, value, 0.0f); float vTrans = interpKey(mVTrans.mKeys, value, 0.0f); @@ -252,7 +252,7 @@ void UVController::Value::setValue(float value) } } -bool VisController::Value::calculate(float time) const +bool VisControllerValue::calculate(float time) const { if(mData.size() == 0) return true; @@ -265,7 +265,7 @@ bool VisController::Value::calculate(float time) const return mData.back().isSet; } -void VisController::Value::setValue(float time) +void VisControllerValue::setValue(float time) { bool vis = calculate(time); mNode->setNodeMask(vis ? ~0 : 0); diff --git a/components/nifosg/controller.hpp b/components/nifosg/controller.hpp index e45bc7fea..d916f894f 100644 --- a/components/nifosg/controller.hpp +++ b/components/nifosg/controller.hpp @@ -114,99 +114,83 @@ namespace NifOsg { return mNode; } }; - class GeomMorpherController + class GeomMorpherControllerValue : public ControllerValue, public ValueInterpolator { public: - class Value : public ControllerValue, public ValueInterpolator - { - public: - // FIXME: don't copy the morph data? - Value(osgAnimation::MorphGeometry* geom, const Nif::NiMorphData *data); + // FIXME: don't copy the morph data? + GeomMorpherControllerValue(osgAnimation::MorphGeometry* geom, const Nif::NiMorphData *data); - virtual void setValue(float time); + virtual void setValue(float time); - private: - osgAnimation::MorphGeometry* mGeom; - std::vector mMorphs; - }; + private: + osgAnimation::MorphGeometry* mGeom; + std::vector mMorphs; }; - class KeyframeController + class KeyframeControllerValue : public NodeTargetValue, public ValueInterpolator { - public: - class Value : public NodeTargetValue, public ValueInterpolator - { - private: - const Nif::QuaternionKeyMap* mRotations; - const Nif::FloatKeyMap* mXRotations; - const Nif::FloatKeyMap* mYRotations; - const Nif::FloatKeyMap* mZRotations; - const Nif::Vector3KeyMap* mTranslations; - const Nif::FloatKeyMap* mScales; - Nif::NIFFilePtr mNif; // Hold a SharedPtr to make sure key lists stay valid + private: + const Nif::QuaternionKeyMap* mRotations; + const Nif::FloatKeyMap* mXRotations; + const Nif::FloatKeyMap* mYRotations; + const Nif::FloatKeyMap* mZRotations; + const Nif::Vector3KeyMap* mTranslations; + const Nif::FloatKeyMap* mScales; + Nif::NIFFilePtr mNif; // Hold a SharedPtr to make sure key lists stay valid - osg::Quat mInitialQuat; - float mInitialScale; + osg::Quat mInitialQuat; + float mInitialScale; - using ValueInterpolator::interpKey; + using ValueInterpolator::interpKey; - osg::Quat interpKey(const Nif::QuaternionKeyMap::MapType &keys, float time); + osg::Quat interpKey(const Nif::QuaternionKeyMap::MapType &keys, float time); - osg::Quat getXYZRotation(float time) const; + osg::Quat getXYZRotation(float time) const; - public: - /// @note The NiKeyFrameData must be valid as long as this KeyframeController exists. - Value(osg::Node *target, const Nif::NIFFilePtr& nif, const Nif::NiKeyframeData *data, - osg::Quat initialQuat, float initialScale); + public: + /// @note The NiKeyFrameData must be valid as long as this KeyframeController exists. + KeyframeControllerValue(osg::Node *target, const Nif::NIFFilePtr& nif, const Nif::NiKeyframeData *data, + osg::Quat initialQuat, float initialScale); - virtual osg::Vec3f getTranslation(float time) const; + virtual osg::Vec3f getTranslation(float time) const; - virtual void setValue(float time); - }; + virtual void setValue(float time); }; - class UVController + class UVControllerValue : public ControllerValue, ValueInterpolator { + private: + osg::StateSet* mStateSet; + Nif::FloatKeyMap mUTrans; + Nif::FloatKeyMap mVTrans; + Nif::FloatKeyMap mUScale; + Nif::FloatKeyMap mVScale; + std::set mTextureUnits; + public: - class Value : public ControllerValue, ValueInterpolator - { - private: - osg::StateSet* mStateSet; - Nif::FloatKeyMap mUTrans; - Nif::FloatKeyMap mVTrans; - Nif::FloatKeyMap mUScale; - Nif::FloatKeyMap mVScale; - std::set mTextureUnits; - - public: - Value(osg::StateSet* target, const Nif::NiUVData *data, std::set textureUnits); - - virtual void setValue(float value); - }; + UVControllerValue(osg::StateSet* target, const Nif::NiUVData *data, std::set textureUnits); + + virtual void setValue(float value); }; - class VisController + class VisControllerValue : public NodeTargetValue { - public: - class Value : public NodeTargetValue - { - private: - std::vector mData; + private: + std::vector mData; - bool calculate(float time) const; + bool calculate(float time) const; - public: - Value(osg::Node *target, const Nif::NiVisData *data) - : NodeTargetValue(target) - , mData(data->mVis) - { } + public: + VisControllerValue(osg::Node *target, const Nif::NiVisData *data) + : NodeTargetValue(target) + , mData(data->mVis) + { } - virtual osg::Vec3f getTranslation(float time) const - { return osg::Vec3f(); } + virtual osg::Vec3f getTranslation(float time) const + { return osg::Vec3f(); } - virtual void setValue(float time); - }; + virtual void setValue(float time); }; } diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index b895f8e13..abeb17b6f 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -400,7 +400,7 @@ namespace NifOsg std::set texUnits; for (std::map::const_iterator it = boundTextures.begin(); it != boundTextures.end(); ++it) texUnits.insert(it->first); - boost::shared_ptr dest(new UVController::Value(transformNode->getOrCreateStateSet() + boost::shared_ptr dest(new UVControllerValue(transformNode->getOrCreateStateSet() , uvctrl->data.getPtr(), texUnits)); createController(uvctrl, dest, 0); } @@ -422,7 +422,7 @@ namespace NifOsg std::cerr << "Warning: multiple KeyframeControllers on the same node" << std::endl; continue; } - boost::shared_ptr dest(new KeyframeController::Value(transformNode, mNif, key->data.getPtr(), + boost::shared_ptr dest(new KeyframeControllerValue(transformNode, mNif, key->data.getPtr(), transformNode->getMatrix().getRotate(), nifNode->trafo.scale)); createController(key, dest, 0); @@ -432,7 +432,7 @@ namespace NifOsg else if (ctrl->recType == Nif::RC_NiVisController) { const Nif::NiVisController* visctrl = static_cast(ctrl.getPtr()); - boost::shared_ptr dest(new VisController::Value(transformNode, visctrl->data.getPtr())); + boost::shared_ptr dest(new VisControllerValue(transformNode, visctrl->data.getPtr())); createController(visctrl, dest, 0); } } @@ -532,7 +532,7 @@ namespace NifOsg { geometry = handleMorphGeometry(static_cast(ctrl.getPtr())); boost::shared_ptr value( - new GeomMorpherController::Value(static_cast(geometry.get()), + new GeomMorpherControllerValue(static_cast(geometry.get()), static_cast(ctrl.getPtr())->data.getPtr())); createController(ctrl.getPtr(), value, 0); break;