DynamicMotionSequence.hGo to the documentation of this file.00001
00002 #ifndef INCLUDED_DynamicMotionSequenceMC_h_
00003 #define INCLUDED_DynamicMotionSequenceMC_h_
00004
00005 #include "MotionSequenceEngine.h"
00006 #include "MotionCommand.h"
00007 #include "MotionManager.h"
00008 #include <vector>
00009 #include "MotionManager.h"
00010
00011
00012
00013 class DynamicMotionSequence : public MotionCommand, public MotionSequenceEngine {
00014 public:
00015
00016 DynamicMotionSequence() : MotionCommand(), MotionSequenceEngine(), moves(), erased() {clear();}
00017
00018 explicit DynamicMotionSequence(const char* filename) : MotionCommand(), MotionSequenceEngine(), moves(), erased() {clear();LoadFile(filename);setTime(1);}
00019
00020 virtual ~DynamicMotionSequence() {}
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 virtual int isDirty() { return isPlaying(); }
00037 virtual int isAlive() { return (playspeed>0) ? (playtime<=endtime) : (playtime>0); }
00038
00039 virtual int updateOutputs() {
00040 MotionSequenceEngine::updateOutputs();
00041 if(!isPlaying()) {
00042 for(unsigned int i=0; i<NumOutputs; i++)
00043 motman->setOutput(this,i,getOutputCmd(i));
00044 } else {
00045 for(unsigned int i=0; i<NumOutputs; i++) {
00046 Move_idx_t prev=prevs[i],next=nexts[i];
00047 OutputCmd frames[NumFrames];
00048 frames[0]=getOutputCmd(i);
00049 for(unsigned int t=playtime+FrameTime,j=1;j<NumFrames;j++,t+=FrameTime) {
00050 setRange(t,prev,next);
00051 if(next!=invalid_move)
00052 calcOutput(frames[j],t,moves[prev],moves[next]);
00053 else
00054 frames[j].unset();
00055 }
00056 motman->setOutput(this,i,frames);
00057 }
00058 }
00059 return NumOutputs;
00060
00061
00062 }
00063
00064 virtual void clear() {
00065 moves.clear();
00066 erased.clear();
00067 for(unsigned int i=0; i<NumOutputs; i++) {
00068 moves.push_back(Move());
00069 moves.back().cmd.unset();
00070 moves.back().next=invalid_move;
00071 moves.back().prev=invalid_move;
00072 prevs[i]=starts[i]=moves.size()-1;
00073 nexts[i]=invalid_move;
00074 }
00075 setTime(1);
00076 }
00077 virtual unsigned int getMaxFrames() const { return -1U; }
00078 virtual unsigned int getUsedFrames() const { return moves.size()-erased.size(); }
00079
00080 protected:
00081
00082 typedef std::vector<Move> list_t;
00083
00084
00085 list_t moves;
00086 std::vector<Move_idx_t> erased;
00087
00088 virtual Move& getKeyFrame(Move_idx_t x) { return moves[x]; }
00089 virtual const Move& getKeyFrame(Move_idx_t x) const { return moves[x]; }
00090 virtual Move_idx_t newKeyFrame() {
00091 if(erased.empty()) {
00092 moves.push_back(Move());
00093 return moves.size()-1;
00094 } else {
00095 Move_idx_t x=erased.back();
00096 erased.pop_back();
00097 return x;
00098 }
00099 }
00100
00101 virtual void eraseKeyFrame(Move_idx_t x) { erased.push_back(x); }
00102
00103 void setRange(unsigned int t,Move_idx_t& prev, Move_idx_t& next) const {
00104 if(next!=invalid_move && moves[next].starttime<=t) {
00105 do {
00106 prev=next;
00107 next=moves[prev].next;
00108 } while(next!=invalid_move && moves[next].starttime<=t);
00109 } else if(t<moves[prev].starttime) {
00110 do {
00111 next=prev;
00112 prev=moves[next].prev;
00113 } while(t<moves[prev].starttime);
00114 }
00115 }
00116 };
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 #endif
|