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 "FF3DDeviceOutputAgent.h"
00025 #include "define.h"
00026
00027
00028 #include "FF3DSphericalForceModel.h"
00029 #include "FF3DPointForceModel.h"
00030 #include "FF3DDiscForceModel.h"
00031 #include "FF3DLinearForceModel.h"
00032 #include "FF3DPlanarForceModel.h"
00033 #include "FF3DPicobHGForceModel.h"
00034 #include "FF3DPicobGForceModel.h"
00035
00036
00037
00038
00039
00040 #include <FrictionalSurface.h>
00041
00042
00043 FF3DDeviceOutputAgent::FF3DDeviceOutputAgent()
00044 : Child( new FF3DDeviceOutputAgentCollider ), MicoleAgent("FF3DDeviceOutputAgent","Output"), _fm(NULL), _transform(new Transform())
00045 {
00046 static_cast<FF3DDeviceOutputAgentCollider *>(this->collider.get())->_parent = this;
00047
00048
00049 Display * dis = static_cast<Display *>(ReachinMicoleApplication::getInstance()->getDisplay());
00050
00051
00052 _transform->children->add(this);
00053 dis->children->add( _transform );
00054
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 bindMessage( "^OUT FF3D : point=\\((.*), (.*), (.*)\\);$",
00083 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handlePointForceModel ));
00084 bindMessage( "^OUT FF3D : sphere=\\((.*), (.*), (.*), (.*)\\);$",
00085 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handleSphericalForceModel ));
00086 bindMessage( "^OUT FF3D : line=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\)\\);$",
00087 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handleLinearForceModel ));
00088 bindMessage( "^OUT FF3D : plan=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\)\\);$",
00089 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handlePlanarForceModel ));
00090 bindMessage( "^OUT FF3D : disc=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\),(.*)\\);$",
00091 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handleDiscForceModel ));
00092 bindMessage( "^OUT FF3D : none;$",
00093 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handleNoForceModel ));
00094 bindMessage( "^OUT FF3D : picobhg=\\(\\((.*), (.*), (.*)\\),\\((.*), (.*), (.*)\\)\\); bumps=\\((.*)\\); bumplength=(.*); pauselength=(.*);$",
00095 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handlePicobHgForceModel ));
00096 bindMessage( "^OUT FF3D : picobg=\\((.*), (.*), (.*)\\); bumps=\\((.*)\\); bumplength=(.*); pauselength=(.*);$",
00097 BUS_CALLBACK_OF(FF3DDeviceOutputAgent, handlePicobGForceModel ));
00098
00099 pb = new Playback();
00100 pb->SetPlaybackSpeed(100);
00101 pb->CreateControllersForOmni();
00102
00103
00104 pb->SetErrorThreshold(8);
00105
00106
00107 pb->SetIntegratorForceCap(2);
00108
00109
00110 pb->LoadGestureFile("SavedTrajectory.txt");
00111 fopen_s(&log, "d3.txt", "a");
00112 }
00113
00114 FF3DDeviceOutputAgent::~FF3DDeviceOutputAgent()
00115 {
00116 delete _fm;
00117 delete pb;
00118
00119 }
00120
00121 void FF3DDeviceOutputAgent::handlePointForceModel(MicoleBus *app, int argc, const char **argv)
00122 {
00123 if (argc < 3)
00124 return;
00125 Vec3f position;
00126 try
00127 {
00128 position.x = atof(argv[0]);
00129 position.y = atof(argv[1]);
00130 position.z = atof(argv[2]);
00131 fprintf(log, "%f, %f, %f\n", position.x, position.y, position.z);
00132 }
00133 catch (...)
00134 {
00135 return;
00136 }
00137
00138 _transform->translation->set(Vec3f(0,0,0));
00139 _transform->rotation->set( Rotation( Vec3f(0, 0, 0), 0 ) );
00140
00141 setForceModel(new FF3DPointForceModel(pb, position));
00142 }
00143
00144 void FF3DDeviceOutputAgent::handleLinearForceModel(MicoleBus *app, int argc, const char **argv)
00145 {
00146 if (argc < 6)
00147 return;
00148 Vec3f pt1;
00149 Vec3f pt2;
00150 try
00151 {
00152 pt1.x = atof(argv[0]);
00153 pt1.y = atof(argv[1]);
00154 pt1.z = atof(argv[2]);
00155
00156
00157 pt2.x = atof(argv[3]);
00158 pt2.y = atof(argv[4]);
00159 pt2.z = atof(argv[5]);
00160 }
00161 catch (...)
00162 {
00163 return;
00164 }
00165
00166 setForceModel(new FF3DLinearForceModel(pt1,pt2));
00167
00168
00169 Vec3f vec_line = pt1 - pt2;
00170 _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00171 _transform->translation->set( (pt1+pt2)/2 );
00172 }
00173
00174 void FF3DDeviceOutputAgent::handlePlanarForceModel(MicoleBus *app, int argc, const char **argv)
00175 {
00176 if (argc < 6)
00177 return;
00178
00179 Vec3f pt1;
00180 Vec3f pt2;
00181 Vec3f pt3;
00182 try
00183 {
00184 pt1.x = atof(argv[0]);
00185 pt1.y = atof(argv[1]);
00186 pt1.z = atof(argv[2]);
00187 _transform->translation->set(pt1);
00188
00189 pt2.x = atof(argv[3]);
00190 pt2.y = atof(argv[4]);
00191 pt2.z = atof(argv[5]);
00192 }
00193 catch (...)
00194 {
00195 return;
00196 }
00197
00198
00199
00200
00201
00202 Vec3f vec_line = pt1 - pt2;
00203 _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00204 _transform->translation->set( pt1 );
00205
00206 setForceModel(new FF3DPlanarForceModel(pt1,pt2));
00207 }
00208
00209 void FF3DDeviceOutputAgent::handleSphericalForceModel(MicoleBus *app, int argc, const char **argv)
00210 {
00211 if (argc < 4)
00212 return;
00213
00214 Vec3f position;
00215 mgFloat range;
00216 try
00217 {
00218 position.x = atof(argv[0]);
00219 position.y = atof(argv[1]);
00220 position.z = atof(argv[2]);
00221 range = atof(argv[3]);
00222 }
00223 catch (...)
00224 {
00225 return;
00226 }
00227
00228 _transform->translation->set(position);
00229 _transform->rotation->set( Rotation( Vec3f(0, 0, 0), 0 ) );
00230
00231
00232 setForceModel( new FF3DSphericalForceModel(Vec3f(0,0,0),range) );
00233 }
00234
00235 void FF3DDeviceOutputAgent::handleDiscForceModel(MicoleBus *app, int argc, const char **argv)
00236 {
00237 if (argc < 7)
00238 return;
00239
00240 Vec3f pt1;
00241 Vec3f pt2;
00242 Vec3f pt3;
00243 try
00244 {
00245 pt1.x = atof(argv[0]);
00246 pt1.y = atof(argv[1]);
00247 pt1.z = atof(argv[2]);
00248 _transform->translation->set(pt1);
00249
00250 pt2.x = atof(argv[3]);
00251 pt2.y = atof(argv[4]);
00252 pt2.z = atof(argv[5]);
00253 }
00254 catch (...)
00255 {
00256 return;
00257 }
00258
00259 mgFloat range = atof(argv[6]);
00260
00261 Vec3f vec_line = pt1 - pt2;
00262 _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00263 _transform->translation->set( pt1 );
00264
00265 setForceModel(new FF3DDiscForceModel(pt1,pt2,range));
00266 }
00267
00268 void FF3DDeviceOutputAgent::handleNoForceModel(MicoleBus *app, int argc, const char **argv)
00269 {
00270 setForceModel(NULL);
00271 }
00272
00273 void FF3DDeviceOutputAgent::handlePicobHgForceModel(MicoleBus *app, int argc, const char **argv)
00274 {
00275 if (argc < 9)
00276 return;
00277
00278 Vec3f pt1;
00279 Vec3f pt2;
00280 try
00281 {
00282 pt1.x = atof(argv[0]);
00283 pt1.y = atof(argv[1]);
00284 pt1.z = atof(argv[2]);
00285
00286
00287 pt2.x = atof(argv[3]);
00288 pt2.y = atof(argv[4]);
00289 pt2.z = atof(argv[5]);
00290 }
00291 catch (...)
00292 {
00293 }
00294
00295
00296 Vec3f vec_line = pt1 - pt2;
00297 _transform->rotation->set( Rotation( Vec3f(vec_line.z, 0, -vec_line.x), acos( vec_line.y / vec_line.length() ) ) );
00298 _transform->translation->set( (pt1+pt2)/2 );
00299
00300 vector<Vec3f> bumpList;
00301 Picob::readPicobList(argv[6], bumpList);
00302 setForceModel(new FF3DPicobHGForceModel(pt1, pt2, bumpList, atof(argv[7]), atof(argv[8])));
00303 }
00304
00305 void FF3DDeviceOutputAgent::handlePicobGForceModel(MicoleBus *app, int argc, const char **argv)
00306 {
00307 if (argc < 6)
00308 return;
00309
00310 Vec3f pt;
00311 try
00312 {
00313 pt.x = atof(argv[0]);
00314 pt.y = atof(argv[1]);
00315 pt.z = atof(argv[2]);
00316 }
00317 catch (...)
00318 {
00319 }
00320
00321 vector<Vec3f> bumpList;
00322 Picob::readPicobList(argv[3], bumpList);
00323 setForceModel(new FF3DPicobGForceModel(pt, bumpList, atof(argv[4]), atof(argv[5])));
00324
00325 _transform->rotation->set( Rotation( Vec3f(0, 0, 0), 0 ) );
00326 _transform->translation->set(Vec3f(0,0,0));
00327 }