mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-27 03:35:27 +00:00
Let the default controller function use absolute input
And convert the VisController to use it.
This commit is contained in:
parent
fe9a7f12b6
commit
ab5980ae18
@ -75,24 +75,33 @@ private:
|
|||||||
float mStopTime;
|
float mStopTime;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DefaultFunction(const Nif::Controller *ctrl)
|
DefaultFunction(const Nif::Controller *ctrl, bool deltaInput)
|
||||||
: Ogre::ControllerFunction<Ogre::Real>(false)
|
: Ogre::ControllerFunction<Ogre::Real>(deltaInput)
|
||||||
, mFrequency(ctrl->frequency)
|
, mFrequency(ctrl->frequency)
|
||||||
, mPhase(ctrl->phase)
|
, mPhase(ctrl->phase)
|
||||||
, mStartTime(ctrl->timeStart)
|
, mStartTime(ctrl->timeStart)
|
||||||
, mStopTime(ctrl->timeStop)
|
, mStopTime(ctrl->timeStop)
|
||||||
{
|
{
|
||||||
mDeltaCount = mPhase;
|
if(mDeltaInput)
|
||||||
while(mDeltaCount < mStartTime)
|
{
|
||||||
mDeltaCount += (mStopTime-mStartTime);
|
mDeltaCount = mPhase;
|
||||||
|
while(mDeltaCount < mStartTime)
|
||||||
|
mDeltaCount += (mStopTime-mStartTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Ogre::Real calculate(Ogre::Real value)
|
virtual Ogre::Real calculate(Ogre::Real value)
|
||||||
{
|
{
|
||||||
mDeltaCount += value*mFrequency;
|
if(mDeltaInput)
|
||||||
mDeltaCount = std::fmod(mDeltaCount - mStartTime,
|
{
|
||||||
mStopTime - mStartTime) + mStartTime;
|
mDeltaCount += value*mFrequency;
|
||||||
return mDeltaCount;
|
mDeltaCount = std::fmod(mDeltaCount - mStartTime,
|
||||||
|
mStopTime - mStartTime) + mStartTime;
|
||||||
|
return mDeltaCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = std::min(mStopTime, std::max(mStartTime, value+mPhase));
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -103,6 +112,20 @@ public:
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Ogre::Bone *mTarget;
|
Ogre::Bone *mTarget;
|
||||||
|
std::vector<Nif::NiVisData::VisData> mData;
|
||||||
|
|
||||||
|
virtual bool calculate(Ogre::Real time)
|
||||||
|
{
|
||||||
|
if(mData.size() == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for(size_t i = 1;i < mData.size();i++)
|
||||||
|
{
|
||||||
|
if(mData[i].time > time)
|
||||||
|
return mData[i-1].isSet;
|
||||||
|
}
|
||||||
|
return mData.back().isSet;
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: We are not getting all objects here. Skinned meshes get
|
// FIXME: We are not getting all objects here. Skinned meshes get
|
||||||
// attached to the object's root node, and won't be connected via a
|
// attached to the object's root node, and won't be connected via a
|
||||||
@ -126,7 +149,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Value(Ogre::Bone *target) : mTarget(target)
|
Value(Ogre::Bone *target, const Nif::NiVisData *data)
|
||||||
|
: mTarget(target)
|
||||||
|
, mData(data->mVis)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual Ogre::Real getValue() const
|
virtual Ogre::Real getValue() const
|
||||||
@ -135,39 +160,14 @@ public:
|
|||||||
return 1.0f;
|
return 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void setValue(Ogre::Real value)
|
virtual void setValue(Ogre::Real time)
|
||||||
{
|
{
|
||||||
int vis = static_cast<int>(value);
|
bool vis = calculate(time);
|
||||||
setVisible(mTarget, vis);
|
setVisible(mTarget, vis);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Function : public Ogre::ControllerFunction<Ogre::Real>
|
typedef DefaultFunction Function;
|
||||||
{
|
|
||||||
private:
|
|
||||||
std::vector<Nif::NiVisData::VisData> mData;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Function(const Nif::NiVisData *data)
|
|
||||||
: Ogre::ControllerFunction<Ogre::Real>(false),
|
|
||||||
mData(data->mVis)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
virtual Ogre::Real calculate(Ogre::Real value)
|
|
||||||
{
|
|
||||||
if(mData.size() == 0)
|
|
||||||
return 1.0f;
|
|
||||||
|
|
||||||
if(mData[0].time >= value)
|
|
||||||
return mData[0].isSet;
|
|
||||||
for(size_t i = 1;i < mData.size();i++)
|
|
||||||
{
|
|
||||||
if(mData[i].time > value)
|
|
||||||
return mData[i-1].isSet;
|
|
||||||
}
|
|
||||||
return mData.back().isSet;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class UVController
|
class UVController
|
||||||
@ -1543,9 +1543,9 @@ class NIFObjectLoader : Ogre::ManualResourceLoader
|
|||||||
|
|
||||||
int trgtid = NIFSkeletonLoader::lookupOgreBoneHandle(mName, ctrl->target->recIndex);
|
int trgtid = NIFSkeletonLoader::lookupOgreBoneHandle(mName, ctrl->target->recIndex);
|
||||||
Ogre::Bone *trgtbone = objectlist.mSkelBase->getSkeleton()->getBone(trgtid);
|
Ogre::Bone *trgtbone = objectlist.mSkelBase->getSkeleton()->getBone(trgtid);
|
||||||
Ogre::SharedPtr<Ogre::ControllerValue<Ogre::Real> > srcval; /* Filled in later */
|
Ogre::ControllerValueRealPtr srcval; /* Filled in later */
|
||||||
Ogre::SharedPtr<Ogre::ControllerValue<Ogre::Real> > dstval(OGRE_NEW VisController::Value(trgtbone));
|
Ogre::ControllerValueRealPtr dstval(OGRE_NEW VisController::Value(trgtbone, vis->data.getPtr()));
|
||||||
Ogre::SharedPtr<Ogre::ControllerFunction<Ogre::Real> > func(OGRE_NEW VisController::Function(vis->data.getPtr()));
|
Ogre::ControllerFunctionRealPtr func(OGRE_NEW VisController::Function(vis, false));
|
||||||
|
|
||||||
objectlist.mControllers.push_back(Ogre::Controller<Ogre::Real>(srcval, dstval, func));
|
objectlist.mControllers.push_back(Ogre::Controller<Ogre::Real>(srcval, dstval, func));
|
||||||
}
|
}
|
||||||
@ -1599,7 +1599,7 @@ class NIFObjectLoader : Ogre::ManualResourceLoader
|
|||||||
const Ogre::MaterialPtr &material = entity->getSubEntity(0)->getMaterial();
|
const Ogre::MaterialPtr &material = entity->getSubEntity(0)->getMaterial();
|
||||||
Ogre::ControllerValueRealPtr srcval(Ogre::ControllerManager::getSingleton().getFrameTimeSource());
|
Ogre::ControllerValueRealPtr srcval(Ogre::ControllerManager::getSingleton().getFrameTimeSource());
|
||||||
Ogre::ControllerValueRealPtr dstval(OGRE_NEW UVController::Value(material, uv->data.getPtr()));
|
Ogre::ControllerValueRealPtr dstval(OGRE_NEW UVController::Value(material, uv->data.getPtr()));
|
||||||
Ogre::ControllerFunctionRealPtr func(OGRE_NEW UVController::Function(uv));
|
Ogre::ControllerFunctionRealPtr func(OGRE_NEW UVController::Function(uv, true));
|
||||||
|
|
||||||
objectlist.mControllers.push_back(Ogre::Controller<Ogre::Real>(srcval, dstval, func));
|
objectlist.mControllers.push_back(Ogre::Controller<Ogre::Real>(srcval, dstval, func));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user