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