forked from mirror/openmw-tes3mp
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;
|
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)
|
if(time <= keys.begin()->first)
|
||||||
return keys.begin()->second.mValue;
|
return keys.begin()->second.mValue;
|
||||||
|
@ -125,7 +125,7 @@ osg::Quat KeyframeController::Value::interpKey(const Nif::QuaternionKeyMap::MapT
|
||||||
return keys.rbegin()->second.mValue;
|
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 xrot = interpKey(mXRotations->mKeys, time);
|
||||||
float yrot = interpKey(mYRotations->mKeys, time);
|
float yrot = interpKey(mYRotations->mKeys, time);
|
||||||
|
@ -136,7 +136,7 @@ osg::Quat KeyframeController::Value::getXYZRotation(float time) const
|
||||||
return (zr*yr*xr);
|
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)
|
osg::Quat initialQuat, float initialScale)
|
||||||
: NodeTargetValue(target)
|
: NodeTargetValue(target)
|
||||||
, mRotations(&data->mRotations)
|
, mRotations(&data->mRotations)
|
||||||
|
@ -150,7 +150,7 @@ KeyframeController::Value::Value(osg::Node *target, const Nif::NIFFilePtr &nif,
|
||||||
, mInitialScale(initialScale)
|
, mInitialScale(initialScale)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
osg::Vec3f KeyframeController::Value::getTranslation(float time) const
|
osg::Vec3f KeyframeControllerValue::getTranslation(float time) const
|
||||||
{
|
{
|
||||||
if(mTranslations->mKeys.size() > 0)
|
if(mTranslations->mKeys.size() > 0)
|
||||||
return interpKey(mTranslations->mKeys, time);
|
return interpKey(mTranslations->mKeys, time);
|
||||||
|
@ -158,7 +158,7 @@ osg::Vec3f KeyframeController::Value::getTranslation(float time) const
|
||||||
return trans->getMatrix().getTrans();
|
return trans->getMatrix().getTrans();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyframeController::Value::setValue(float time)
|
void KeyframeControllerValue::setValue(float time)
|
||||||
{
|
{
|
||||||
osg::MatrixTransform* trans = static_cast<osg::MatrixTransform*>(mNode);
|
osg::MatrixTransform* trans = static_cast<osg::MatrixTransform*>(mNode);
|
||||||
osg::Matrix mat = trans->getMatrix();
|
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)
|
: mGeom(geom)
|
||||||
, mMorphs(morphData->mMorphs)
|
, mMorphs(morphData->mMorphs)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeomMorpherController::Value::setValue(float time)
|
void GeomMorpherControllerValue::setValue(float time)
|
||||||
{
|
{
|
||||||
if (mMorphs.size() <= 1)
|
if (mMorphs.size() <= 1)
|
||||||
return;
|
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)
|
: mStateSet(target)
|
||||||
, mUTrans(data->mKeyList[0])
|
, mUTrans(data->mKeyList[0])
|
||||||
, mVTrans(data->mKeyList[1])
|
, 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 uTrans = interpKey(mUTrans.mKeys, value, 0.0f);
|
||||||
float vTrans = interpKey(mVTrans.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)
|
if(mData.size() == 0)
|
||||||
return true;
|
return true;
|
||||||
|
@ -265,7 +265,7 @@ bool VisController::Value::calculate(float time) const
|
||||||
return mData.back().isSet;
|
return mData.back().isSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisController::Value::setValue(float time)
|
void VisControllerValue::setValue(float time)
|
||||||
{
|
{
|
||||||
bool vis = calculate(time);
|
bool vis = calculate(time);
|
||||||
mNode->setNodeMask(vis ? ~0 : 0);
|
mNode->setNodeMask(vis ? ~0 : 0);
|
||||||
|
|
|
@ -114,14 +114,11 @@ namespace NifOsg
|
||||||
{ return mNode; }
|
{ return mNode; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class GeomMorpherController
|
class GeomMorpherControllerValue : public ControllerValue, public ValueInterpolator
|
||||||
{
|
|
||||||
public:
|
|
||||||
class Value : public ControllerValue, public ValueInterpolator
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// FIXME: don't copy the morph data?
|
// FIXME: don't copy the morph data?
|
||||||
Value(osgAnimation::MorphGeometry* geom, const Nif::NiMorphData *data);
|
GeomMorpherControllerValue(osgAnimation::MorphGeometry* geom, const Nif::NiMorphData *data);
|
||||||
|
|
||||||
virtual void setValue(float time);
|
virtual void setValue(float time);
|
||||||
|
|
||||||
|
@ -129,12 +126,8 @@ namespace NifOsg
|
||||||
osgAnimation::MorphGeometry* mGeom;
|
osgAnimation::MorphGeometry* mGeom;
|
||||||
std::vector<Nif::NiMorphData::MorphData> mMorphs;
|
std::vector<Nif::NiMorphData::MorphData> mMorphs;
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
class KeyframeController
|
class KeyframeControllerValue : public NodeTargetValue, public ValueInterpolator
|
||||||
{
|
|
||||||
public:
|
|
||||||
class Value : public NodeTargetValue, public ValueInterpolator
|
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const Nif::QuaternionKeyMap* mRotations;
|
const Nif::QuaternionKeyMap* mRotations;
|
||||||
|
@ -157,19 +150,15 @@ namespace NifOsg
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// @note The NiKeyFrameData must be valid as long as this KeyframeController exists.
|
/// @note The NiKeyFrameData must be valid as long as this KeyframeController exists.
|
||||||
Value(osg::Node *target, const Nif::NIFFilePtr& nif, const Nif::NiKeyframeData *data,
|
KeyframeControllerValue(osg::Node *target, const Nif::NIFFilePtr& nif, const Nif::NiKeyframeData *data,
|
||||||
osg::Quat initialQuat, float initialScale);
|
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
|
||||||
{
|
|
||||||
public:
|
|
||||||
class Value : public ControllerValue, ValueInterpolator
|
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
osg::StateSet* mStateSet;
|
osg::StateSet* mStateSet;
|
||||||
|
@ -180,16 +169,12 @@ namespace NifOsg
|
||||||
std::set<int> mTextureUnits;
|
std::set<int> mTextureUnits;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Value(osg::StateSet* target, const Nif::NiUVData *data, std::set<int> textureUnits);
|
UVControllerValue(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
|
||||||
{
|
|
||||||
public:
|
|
||||||
class Value : public NodeTargetValue
|
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<Nif::NiVisData::VisData> mData;
|
std::vector<Nif::NiVisData::VisData> mData;
|
||||||
|
@ -197,7 +182,7 @@ namespace NifOsg
|
||||||
bool calculate(float time) const;
|
bool calculate(float time) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Value(osg::Node *target, const Nif::NiVisData *data)
|
VisControllerValue(osg::Node *target, const Nif::NiVisData *data)
|
||||||
: NodeTargetValue(target)
|
: NodeTargetValue(target)
|
||||||
, mData(data->mVis)
|
, mData(data->mVis)
|
||||||
{ }
|
{ }
|
||||||
|
@ -207,7 +192,6 @@ namespace NifOsg
|
||||||
|
|
||||||
virtual void setValue(float time);
|
virtual void setValue(float time);
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -400,7 +400,7 @@ namespace NifOsg
|
||||||
std::set<int> texUnits;
|
std::set<int> texUnits;
|
||||||
for (std::map<int, int>::const_iterator it = boundTextures.begin(); it != boundTextures.end(); ++it)
|
for (std::map<int, int>::const_iterator it = boundTextures.begin(); it != boundTextures.end(); ++it)
|
||||||
texUnits.insert(it->first);
|
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));
|
, uvctrl->data.getPtr(), texUnits));
|
||||||
createController(uvctrl, dest, 0);
|
createController(uvctrl, dest, 0);
|
||||||
}
|
}
|
||||||
|
@ -422,7 +422,7 @@ namespace NifOsg
|
||||||
std::cerr << "Warning: multiple KeyframeControllers on the same node" << std::endl;
|
std::cerr << "Warning: multiple KeyframeControllers on the same node" << std::endl;
|
||||||
continue;
|
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));
|
transformNode->getMatrix().getRotate(), nifNode->trafo.scale));
|
||||||
|
|
||||||
createController(key, dest, 0);
|
createController(key, dest, 0);
|
||||||
|
@ -432,7 +432,7 @@ namespace NifOsg
|
||||||
else if (ctrl->recType == Nif::RC_NiVisController)
|
else if (ctrl->recType == Nif::RC_NiVisController)
|
||||||
{
|
{
|
||||||
const Nif::NiVisController* visctrl = static_cast<const Nif::NiVisController*>(ctrl.getPtr());
|
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);
|
createController(visctrl, dest, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -532,7 +532,7 @@ namespace NifOsg
|
||||||
{
|
{
|
||||||
geometry = handleMorphGeometry(static_cast<const Nif::NiGeomMorpherController*>(ctrl.getPtr()));
|
geometry = handleMorphGeometry(static_cast<const Nif::NiGeomMorpherController*>(ctrl.getPtr()));
|
||||||
boost::shared_ptr<ControllerValue> value(
|
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()));
|
static_cast<const Nif::NiGeomMorpherController*>(ctrl.getPtr())->data.getPtr()));
|
||||||
createController(ctrl.getPtr(), value, 0);
|
createController(ctrl.getPtr(), value, 0);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue