mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-01 20:15:33 +00:00
Simplify controller classes
This commit is contained in:
parent
74dfb23e7b
commit
3839d6f777
3 changed files with 71 additions and 87 deletions
|
@ -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<osg::MatrixTransform*>(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<int> textureUnits)
|
||||
UVControllerValue::UVControllerValue(osg::StateSet *target, const Nif::NiUVData *data, std::set<int> 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);
|
||||
|
|
|
@ -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<Nif::NiMorphData::MorphData> mMorphs;
|
||||
};
|
||||
private:
|
||||
osgAnimation::MorphGeometry* mGeom;
|
||||
std::vector<Nif::NiMorphData::MorphData> mMorphs;
|
||||
};
|
||||
|
||||
class KeyframeController
|
||||
class KeyframeControllerValue : 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
|
||||
|
||||
osg::Quat mInitialQuat;
|
||||
float mInitialScale;
|
||||
|
||||
using ValueInterpolator::interpKey;
|
||||
|
||||
|
||||
osg::Quat interpKey(const Nif::QuaternionKeyMap::MapType &keys, float time);
|
||||
|
||||
osg::Quat getXYZRotation(float time) const;
|
||||
|
||||
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
|
||||
/// @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);
|
||||
|
||||
osg::Quat mInitialQuat;
|
||||
float mInitialScale;
|
||||
virtual osg::Vec3f getTranslation(float time) const;
|
||||
|
||||
using ValueInterpolator::interpKey;
|
||||
|
||||
|
||||
osg::Quat interpKey(const Nif::QuaternionKeyMap::MapType &keys, float time);
|
||||
|
||||
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);
|
||||
|
||||
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<int> 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<int> mTextureUnits;
|
||||
UVControllerValue(osg::StateSet* target, const Nif::NiUVData *data, std::set<int> textureUnits);
|
||||
|
||||
public:
|
||||
Value(osg::StateSet* target, const Nif::NiUVData *data, std::set<int> textureUnits);
|
||||
|
||||
virtual void setValue(float value);
|
||||
};
|
||||
virtual void setValue(float value);
|
||||
};
|
||||
|
||||
class VisController
|
||||
class VisControllerValue : public NodeTargetValue
|
||||
{
|
||||
private:
|
||||
std::vector<Nif::NiVisData::VisData> mData;
|
||||
|
||||
bool calculate(float time) const;
|
||||
|
||||
public:
|
||||
class Value : public NodeTargetValue
|
||||
{
|
||||
private:
|
||||
std::vector<Nif::NiVisData::VisData> mData;
|
||||
VisControllerValue(osg::Node *target, const Nif::NiVisData *data)
|
||||
: NodeTargetValue(target)
|
||||
, mData(data->mVis)
|
||||
{ }
|
||||
|
||||
bool calculate(float time) const;
|
||||
virtual osg::Vec3f getTranslation(float time) const
|
||||
{ return osg::Vec3f(); }
|
||||
|
||||
public:
|
||||
Value(osg::Node *target, const Nif::NiVisData *data)
|
||||
: NodeTargetValue(target)
|
||||
, mData(data->mVis)
|
||||
{ }
|
||||
|
||||
virtual osg::Vec3f getTranslation(float time) const
|
||||
{ return osg::Vec3f(); }
|
||||
|
||||
virtual void setValue(float time);
|
||||
};
|
||||
virtual void setValue(float time);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -400,7 +400,7 @@ namespace NifOsg
|
|||
std::set<int> texUnits;
|
||||
for (std::map<int, int>::const_iterator it = boundTextures.begin(); it != boundTextures.end(); ++it)
|
||||
texUnits.insert(it->first);
|
||||
boost::shared_ptr<ControllerValue> dest(new UVController::Value(transformNode->getOrCreateStateSet()
|
||||
boost::shared_ptr<ControllerValue> 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<ControllerValue> dest(new KeyframeController::Value(transformNode, mNif, key->data.getPtr(),
|
||||
boost::shared_ptr<ControllerValue> 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<const Nif::NiVisController*>(ctrl.getPtr());
|
||||
boost::shared_ptr<ControllerValue> dest(new VisController::Value(transformNode, visctrl->data.getPtr()));
|
||||
boost::shared_ptr<ControllerValue> dest(new VisControllerValue(transformNode, visctrl->data.getPtr()));
|
||||
createController(visctrl, dest, 0);
|
||||
}
|
||||
}
|
||||
|
@ -532,7 +532,7 @@ namespace NifOsg
|
|||
{
|
||||
geometry = handleMorphGeometry(static_cast<const Nif::NiGeomMorpherController*>(ctrl.getPtr()));
|
||||
boost::shared_ptr<ControllerValue> value(
|
||||
new GeomMorpherController::Value(static_cast<osgAnimation::MorphGeometry*>(geometry.get()),
|
||||
new GeomMorpherControllerValue(static_cast<osgAnimation::MorphGeometry*>(geometry.get()),
|
||||
static_cast<const Nif::NiGeomMorpherController*>(ctrl.getPtr())->data.getPtr()));
|
||||
createController(ctrl.getPtr(), value, 0);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue