DynamicMotionSequenceNode.h
Go to the documentation of this file.00001
00002 #ifndef _DynamicMotionSequenceNode_h_
00003 #define _DynamicMotionSequenceNode_h_
00004
00005 #include "MCNode.h"
00006 #include "Motion/DynamicMotionSequence.h"
00007 #include "Motion/MotionManager.h"
00008 #include "Shared/get_time.h"
00009 #include "Shared/debuget.h"
00010 #include "Shared/MarkScope.h"
00011
00012
00013
00014 extern const char defDynamicMotionSequenceNodeName[];
00015
00016
00017 extern const char defDynamicMotionSequenceNodeDesc[];
00018
00019
00020
00021 class DynamicMotionSequenceNode : public MCNode<DynamicMotionSequence,defDynamicMotionSequenceNodeName,defDynamicMotionSequenceNodeDesc,true> {
00022 public:
00023
00024 DynamicMotionSequenceNode()
00025 : MCNode<DynamicMotionSequence,defDynamicMotionSequenceNodeName,defDynamicMotionSequenceNodeDesc,true>(),
00026 looping(false), filename() {}
00027
00028
00029 DynamicMotionSequenceNode(const std::string& name, const std::string& file="", bool loop=false)
00030 : MCNode<DynamicMotionSequence,defDynamicMotionSequenceNodeName,defDynamicMotionSequenceNodeDesc,true>(name),
00031 looping(loop), filename(file) {}
00032
00033 virtual void preStart() {
00034 MCNode<DynamicMotionSequence,defDynamicMotionSequenceNodeName,defDynamicMotionSequenceNodeDesc,true>::preStart();
00035 if(event!=NULL) {
00036 const DataEvent<std::string>* ev = dynamic_cast<const DataEvent<std::string>*>(event);
00037 if ( ev != NULL )
00038 filename = ev->getData();
00039 }
00040 update(filename);
00041 }
00042
00043 virtual void postStart() {
00044 MCNode<DynamicMotionSequence,defDynamicMotionSequenceNodeName,defDynamicMotionSequenceNodeDesc,true>::postStart();
00045 getMC()->play();
00046 }
00047
00048
00049 virtual void setFile(const std::string& file) {
00050 if ( StateNode::isActive() )
00051 update(file);
00052 else
00053 filename=file;
00054 }
00055
00056
00057 virtual void setLooping(bool loop) { looping=loop; }
00058
00059 virtual void doEvent() {
00060 ASSERTRET(event->getGeneratorID()==EventBase::motmanEGID,"Unknown event");
00061 if ( event->getSourceID() == MCNodeBase::getMC_ID() ) {
00062 if(looping)
00063 getMC()->setTime(1);
00064 StateNode::postStateCompletion();
00065 }
00066 }
00067
00068
00069 virtual bool getLooping() { return looping; }
00070
00071 protected:
00072
00073
00074 void update(const std::string& file) {
00075 if ( file.size() > 0 ) {
00076 filename=file;
00077 MMAccessor<DynamicMotionSequence> dms_acc = getMC();
00078 dms_acc->clear();
00079 dms_acc->loadFile(filename.c_str());
00080 dms_acc->setTime(1);
00081 }
00082 }
00083
00084 bool looping;
00085 std::string filename;
00086
00087 };
00088
00089 #endif