00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "stdafx.h"
00024 #include "GuidanceAgent.h"
00025
00026 #include "MicoleStringStream.h"
00027
00028 GuidanceAgent::GuidanceAgent(const float &replayDistance, const float &_recordDistance)
00029 :_state(STOPPED), _replayDistance(replayDistance), _recordDistance(_recordDistance)
00030 {
00031 _pointListIterator = _pointlist.begin();
00032 bindMessage("^GUIDE PLAY;", BUS_CALLBACK_OF(GuidanceAgent, handlePlay));
00033 bindMessage("^GUIDE STOP;", BUS_CALLBACK_OF(GuidanceAgent, handleStop));
00034 bindMessage("^GUIDE PAUSE;", BUS_CALLBACK_OF(GuidanceAgent, handlePause));
00035 bindMessage("^GUIDE REC;", BUS_CALLBACK_OF(GuidanceAgent, handleRecord));
00036 bindMessage("^GUIDE ADD : pos=\\((.*), (.*), (.*)\\);", BUS_CALLBACK_OF(GuidanceAgent, handleAdd));
00037 }
00038
00039 GuidanceAgent::~GuidanceAgent()
00040 {
00041 }
00042
00043 void GuidanceAgent::onInput()
00044 {
00045 Vec3f p;
00046 if (!_pointlist.empty())
00047 p = _position - (*_pointListIterator);;
00048
00049 switch(_state)
00050 {
00051
00052
00053 case PLAYING:
00054 if (_pointlist.empty())
00055 return;
00056 if (p.length() < _replayDistance)
00057 {
00058 _pointListIterator++;
00059 if (_pointListIterator == _pointlist.end())
00060 {
00061 sendMessage("OUT FF3D GUIDE : none;");
00062 _state = STOPPED;
00063 _pointListIterator = _pointlist.begin();
00064 return;
00065 }
00066 MicoleStringStream s;
00067 s << "OUT FF3D GUIDE : point=("
00068 << (*_pointListIterator).x << ", "
00069 << (*_pointListIterator).y << ", "
00070 << (*_pointListIterator).z << ");";
00071 sendMessage(s.getString());
00072 }
00073 break;
00074
00075
00076 case RECORDING:
00077 if (_pointlist.empty() || p.length() > _recordDistance)
00078 {
00079 _pointlist.push_front(_position);
00080 _pointListIterator = _pointlist.begin();
00081 }
00082 break;
00083 default:
00084 break;
00085 }
00086 }
00087
00088
00089 void GuidanceAgent::handleAdd( MicoleBus *app, int argc, const char **argv )
00090 {
00091 if (argc < 3)
00092 return;
00093 _pointListIterator = _pointlist.insert(_pointListIterator, Vec3f(atof(argv[0]), atof(argv[1]), atof(argv[2])));
00094 MicoleStringStream s;
00095 s << "OUT FF3D GUIDE : point=("
00096 << atof(argv[0]) << ", "
00097 << atof(argv[1]) << ", "
00098 << atof(argv[2]) << ");";
00099 sendMessage(s.getString());
00100 }
00101
00102
00103 void GuidanceAgent::handlePlay( MicoleBus *app, int argc, const char **argv )
00104 {
00105 _state = PLAYING;
00106 _pointListIterator = _pointlist.begin();
00107 if (_pointlist.empty())
00108 return;
00109 MicoleStringStream s;
00110 s << "OUT FF3D GUIDE : point=("
00111 << (*_pointListIterator).x << ", "
00112 << (*_pointListIterator).y << ", "
00113 << (*_pointListIterator).z << ");";
00114 sendMessage(s.getString());
00115 }
00116
00117
00118 void GuidanceAgent::handlePause( MicoleBus *app, int argc, const char **argv )
00119 {
00120 _state = PAUSED;
00121 sendMessage("OUT FF3D GUIDE : none;");
00122 }
00123
00124
00125 void GuidanceAgent::handleStop( MicoleBus *app, int argc, const char **argv )
00126 {
00127 _state = STOPPED;
00128 _pointListIterator = _pointlist.begin();
00129 sendMessage("OUT FF3D GUIDE : none;");
00130 }
00131
00132
00133 void GuidanceAgent::handleRecord( MicoleBus *app, int argc, const char **argv )
00134 {
00135 _state = RECORDING;
00136 _pointlist.clear();
00137 _pointListIterator = _pointlist.begin();
00138 }