1 #ifndef COMPONENTS_NIFOSG_CONTROLLER_H
2 #define COMPONENTS_NIFOSG_CONTROLLER_H
12 #include <boost/shared_ptr.hpp>
17 #include <osg/Texture2D>
18 #include <osg/ref_ptr>
20 #include <osg/StateSet>
21 #include <osg/NodeCallback>
22 #include <osg/Drawable>
36 namespace osgAnimation
45 template <
typename MapT,
typename InterpolationFunc>
49 typedef typename MapT::ValueType
ValueT;
72 const typename MapT::MapType & keys =
mKeys->mKeys;
74 if(time <= keys.begin()->first)
75 return keys.begin()->second.mValue;
79 typename MapT::MapType::const_iterator it =
mLastHighKey;
90 it = keys.lower_bound(time);
93 it = keys.lower_bound(time);
98 float aTime = it->first;
99 const typename MapT::KeyType* aKey = &it->second;
104 assert (it != keys.begin());
106 typename MapT::MapType::const_iterator last = --it;
108 float aLastTime = last->first;
109 const typename MapT::KeyType* aLastKey = &last->second;
111 float a = (time - aLastTime) / (aTime - aLastTime);
113 return InterpolationFunc()(aLastKey->mValue, aKey->mValue, a);
116 return keys.rbegin()->second.mValue;
128 boost::shared_ptr<const MapT>
mKeys;
135 template <
typename ValueType>
136 inline ValueType
operator()(
const ValueType& a,
const ValueType& b,
float fraction)
138 return a + ((b - a) * fraction);
144 inline osg::Quat
operator()(
const osg::Quat& a,
const osg::Quat& b,
float fraction)
147 result.slerp(fraction, a, b);
189 virtual
void update(osg::NodeVisitor* nv, osg::Drawable* drawable);
204 virtual osg::Vec3f getTranslation(
float time)
const;
206 virtual void operator() (osg::Node*, osg::NodeVisitor*);
218 osg::Quat getXYZRotation(
float time)
const;
230 virtual void setDefaults(osg::StateSet* stateset);
231 virtual void apply(osg::StateSet *stateset, osg::NodeVisitor *nv);
244 std::vector<Nif::NiVisData::VisData>
mData;
246 bool calculate(
float time)
const;
255 virtual
void operator() (osg::Node* node, osg::NodeVisitor* nv);
268 virtual void setDefaults(osg::StateSet* stateset);
270 virtual void apply(osg::StateSet* stateset, osg::NodeVisitor* nv);
287 virtual
void setDefaults(osg::StateSet* stateset);
289 virtual
void apply(osg::StateSet* stateset, osg::NodeVisitor* nv);
301 FlipController(
int texSlot,
float delta, std::vector<osg::ref_ptr<osg::Texture2D> > textures);
307 std::vector<osg::ref_ptr<osg::Texture2D> >& getTextures() {
return mTextures; }
309 virtual void apply(osg::StateSet *stateset, osg::NodeVisitor *nv);
321 virtual
void operator() (osg::Node* node, osg::NodeVisitor* nv);
ExtrapolationMode mExtrapolationMode
Definition: controller.hpp:169
FloatInterpolator mYRotations
Definition: controller.hpp:212
GeomMorpherController()
Definition: controller.cpp:172
META_Object(NifOsg, FlipController) std
Definition: controller.hpp:305
boost::shared_ptr< const MapT > mKeys
Definition: controller.hpp:128
float mPhase
Definition: controller.hpp:160
Definition: controller.hpp:312
ValueInterpolator()
Definition: controller.hpp:51
ControllerFunction(const Nif::Controller *ctrl)
Definition: controller.cpp:20
Implements efficient per-frame updating of StateSets.
Definition: statesetupdater.hpp:19
Definition: controller.hpp:167
Definition: controller.hpp:147
Definition: controller.hpp:32
float mFrequency
Definition: controller.hpp:159
MapT::ValueType ValueT
Definition: controller.hpp:49
ValueInterpolator< Nif::FloatKeyMap, LerpFunc > FloatInterpolator
Definition: controller.hpp:153
bool empty() const
Definition: controller.hpp:119
float mDelta
Definition: controller.hpp:296
Definition: controller.hpp:133
Definition: controller.hpp:156
Definition: controller.hpp:292
Definition: controller.hpp:241
MapT::MapType::const_iterator mLastLowKey
Definition: controller.hpp:125
std::vector< Nif::NiVisData::VisData > mData
Definition: controller.hpp:244
FloatInterpolator mUScale
Definition: controller.hpp:236
Vec3Interpolator mData
Definition: controller.hpp:278
Controller()
Definition: controller.cpp:12
ValueT mDefaultVal
Definition: controller.hpp:130
Definition: controller.hpp:36
FloatInterpolator mScales
Definition: controller.hpp:216
Definition: controller.hpp:195
FloatInterpolator mData
Definition: controller.hpp:261
std::vector< FloatInterpolator > mKeyFrames
Definition: controller.hpp:187
Definition: controller.hpp:46
FloatInterpolator mXRotations
Definition: controller.hpp:211
Definition: controller.hpp:258
Definition: controller.hpp:221
osg::Quat operator()(const osg::Quat &a, const osg::Quat &b, float fraction)
Definition: controller.hpp:144
ValueInterpolator(boost::shared_ptr< const MapT > keys, ValueT defaultVal=ValueT())
Definition: controller.hpp:56
std::vector< osg::ref_ptr< osg::Texture2D > > mTextures
Definition: controller.hpp:297
FloatInterpolator mVScale
Definition: controller.hpp:237
int mTexSlot
Definition: controller.hpp:295
ExtrapolationMode
Definition: controller.hpp:163
Definition: controller.hpp:142
Vec3Interpolator mTranslations
Definition: controller.hpp:215
Definition: controller.hpp:166
ValueInterpolator< Nif::Vector3KeyMap, LerpFunc > Vec3Interpolator
Definition: controller.hpp:154
FloatInterpolator mZRotations
Definition: controller.hpp:213
ValueType operator()(const ValueType &a, const ValueType &b, float fraction)
Definition: controller.hpp:136
FloatInterpolator mUTrans
Definition: controller.hpp:234
Definition: controller.hpp:26
float mStartTime
Definition: controller.hpp:161
ValueT interpKey(float time) const
Definition: controller.hpp:67
QuaternionInterpolator mRotations
Definition: controller.hpp:209
FloatInterpolator mVTrans
Definition: controller.hpp:235
float mStopTime
Definition: controller.hpp:162
virtual float getMaximum() const
Definition: controller.cpp:66
std::set< int > mTextureUnits
Definition: controller.hpp:238
Must be set on an osgAnimation::MorphGeometry.
Definition: controller.hpp:180
Definition: controller.hpp:165
float calculate(float value) const
Definition: controller.cpp:29
Definition: controller.hpp:275
MapT::MapType::const_iterator mLastHighKey
Definition: controller.hpp:126
ValueInterpolator< Nif::QuaternionKeyMap, QuaternionSlerpFunc > QuaternionInterpolator
Definition: controller.hpp:152