GuidanceAgent.cpp

Go to the documentation of this file.
00001 /*
00002  * This file is part of Micole Architecture
00003  *
00004  * Copyright (C) 2007 Micole partners
00005  *
00006  * Micole Architecture is free software: you can redistribute it 
00007  * and/or modify it under the terms of the GNU Lesser General 
00008  * Public License as published by the Free Software Foundation, 
00009  * either version 3 of the License, or (at your option) any 
00010  * later version.
00011  *
00012  * Micole Architecture is distributed in the hope that it will be 
00013  * useful, * but WITHOUT ANY WARRANTY; without even the implied 
00014  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00015  * PURPOSE.  See the GNU Lesser General Public License for more 
00016  * details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Micole Architecture.  If not, see
00020  * <http://www.gnu.org/licenses/>.
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                 // change the point if the current position is close to the
00052                 // current point
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                 // add the current position if the position is far enough
00075                 // from the last point added
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 // add a point in the list
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 // play the recording or resumes
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 // pauses the recording
00118 void GuidanceAgent::handlePause( MicoleBus *app, int argc, const char **argv )
00119 {
00120         _state = PAUSED;
00121         sendMessage("OUT FF3D GUIDE : none;");
00122 }
00123 
00124 // stop the playing or the recording
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 // starts the recording
00133 void GuidanceAgent::handleRecord( MicoleBus *app, int argc, const char **argv )
00134 {
00135         _state = RECORDING;
00136         _pointlist.clear();
00137         _pointListIterator = _pointlist.begin();
00138 }

Generated on Tue Oct 16 17:10:42 2007 for Micole by  doxygen 1.4.7