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 "InputAgentExample.h" 00025 #include "ReachinMicoleApplication.h" 00026 00027 #include "MicoleStringStream.h" 00028 00029 #include "FF3DPointForceModel.h" 00030 00031 #include <sstream> 00032 00033 00034 using namespace std; 00035 00036 InputAgentExample::InputAgentExample() 00037 { 00038 /* 00039 _timePassed= 0; 00040 _recording = 0; 00041 _replay = 0;*/ 00042 } 00043 00044 InputAgentExample::~InputAgentExample(void) 00045 { 00046 } 00047 00048 void InputAgentExample::onKey(int keycode) 00049 { 00050 switch(keycode) 00051 { 00052 // P 00053 case 112: 00054 sendMessage("GUIDE PLAY;"); 00055 break; 00056 // S 00057 case 115: 00058 sendMessage("GUIDE STOP;"); 00059 break; 00060 // L 00061 case 108: 00062 sendMessage("GUIDE PAUSE;"); 00063 break; 00064 // R 00065 case 114: 00066 sendMessage("GUIDE REC;"); 00067 break; 00068 // A 00069 case 97: 00070 sendMessage("GUIDE ADD : pos=(0.0, 0.0, 0.0);"); 00071 break; 00072 } 00073 /* 00074 if (keycode==114) { 00075 FF3DDeviceInputAgent::sendMessage("OUT FF3D : none;"); 00076 FF3DDeviceInputAgent::sendMessage("OUT FF3D GUIDE : none;"); 00077 _recording = (!_recording); 00078 _replay = 0; 00079 00080 if (_recording) { 00081 FF3DDeviceInputAgent::sendMessage("OUT VTP : right=(1110100111101001);"); 00082 } else { 00083 FF3DDeviceInputAgent::sendMessage("OUT VTP : right=(0000000000000000);"); 00084 } 00085 } 00086 else 00087 if (keycode==112) { 00088 FF3DDeviceInputAgent::sendMessage("OUT FF3D : none;"); 00089 FF3DDeviceInputAgent::sendMessage("OUT FF3D GUIDE : none;"); 00090 00091 _replay = (!_replay); 00092 _recording = 0; 00093 00094 if (_path.size() > 0) { 00095 _magneticPoint = _path.front(); 00096 _path.pop_front(); 00097 00098 MicoleStringStream s; 00099 s << "OUT FF3D GUIDE : point=("<<_magneticPoint.x<<", "<<_magneticPoint.y<<", "<<_magneticPoint.z<<");"; 00100 FF3DDeviceInputAgent::sendMessage(s.str()); 00101 00102 00103 FF3DDeviceInputAgent::sendMessage("OUT VTP : right=(1110100111101000);"); 00104 } else { //no record 00105 _magneticPoint = Vec3f(0,0,0); 00106 } 00107 }*/ 00108 } 00109 00110 #if 0 00111 void InputAgentExample::onInput() 00112 { 00113 00114 if (_recording) { 00115 _path.push_back(_position); 00116 } 00117 00118 if (_replay) { 00119 00120 Vec3f _diff = _magneticPoint - _position; 00121 if (_diff.length()<=0.025) { 00122 00123 if (_path.size() > 0) { 00124 _magneticPoint = _path.front(); 00125 _path.pop_front(); 00126 00127 MicoleStringStream s; 00128 s << "OUT FF3D GUIDE : point=("<<_magneticPoint.x<<", "<<_magneticPoint.y<<", "<<_magneticPoint.z<<");"; 00129 FF3DDeviceInputAgent::sendMessage(s.str()); 00130 } else { //no more point in path 00131 _replay = 0; 00132 FF3DDeviceInputAgent::sendMessage("OUT FF3D GUIDE : none;"); 00133 FF3DDeviceInputAgent::sendMessage("OUT VTP : left=(0000000000000000);"); 00134 FF3DDeviceInputAgent::sendMessage("OUT VTP : right=(0000000000000000);"); 00135 } 00136 } 00137 } 00138 00139 } 00140 00141 void InputAgentExample::onButtonDown() 00142 { 00143 /*_grab = Vec3f(_position.x,_position.y,_position.z); 00144 FF3DDeviceInputAgent::sendMessage("OUT FF3D : none;"); 00145 FF3DDeviceInputAgent::sendMessage("OUT FF3D GUIDE : none;");*/ 00146 } 00147 00148 void InputAgentExample::onButtonUp() 00149 { 00150 //MicoleStringStream s; 00151 //s << "OUT FF3D : point=("<<_position.x<<", "<<_position.y<<", "<<_position.z<<");"; 00152 //s << "OUT FF3D : sphere=("<<_position.x<<", "<<_position.y<<", "<<_position.z<<", "<< 0.02 <<");"; 00153 //s << "OUT FF3D : line=(("<<_grab.x<<", "<<_grab.y<<", "<<_grab.z<<"),("<<_position.x<<", "<<_position.y<<", "<<_position.z<<"));"; 00154 /*s << "OUT FF3D : picobhg=(("<<_grab.x<<", "<<_grab.y<<", "<<_grab.z<<"),("<<_position.x<<", "<<_position.y<<", "<<_position.z<<")); bumps=((0, 1, 0),(0, -0.5, 0)); bumplength=0.1; pauselength=0.001;"; 00155 FF3DDeviceInputAgent::sendMessage(s.str()); 00156 s.flush(); 00157 00158 s << "OUT FF3D GUIDE : point=("<<_grab.x<<", "<<_grab.y<<", "<<_grab.z<<");"; 00159 FF3DDeviceInputAgent::sendMessage(s.str());*/ 00160 //s << "OUT FF3D : plan=(("<<_position.x<<", "<<_position.y<<", "<<_position.z<<"),("<<_grab.x<<", "<<_grab.y<<", "<<_grab.z<<"));"; 00161 //s << "OUT FF3D : disc=(("<<_position.x<<", "<<_position.y<<", "<<_position.z<<"),("<<_grab.x<<", "<<_grab.y<<", "<<_grab.z<<"),"<< 0.03 <<");"; 00162 //s << "OUT FF3D : picobhg=(("<<_grab.x<<", "<<_grab.y<<", "<<_grab.z<<"),("<<_position.x<<", "<<_position.y<<", "<<_position.z<<")); bumps=((0, 0, 0.005),(0, 0, 0.01),(0, 0.005, 0),(0, 0.01, 0),(0.005, 0, 0),(0.01, 0, 0));"; 00163 //s << "OUT FF3D : picobhg=(("<<_grab.x<<", "<<_grab.y<<", "<<_grab.z<<"),("<<_position.x<<", "<<_position.y<<", "<<_position.z<< \ 00164 ")); bumps=((0, 0, 0.005),(0, 0, 0.01));"; 00165 //s << "OUT FF3D : picobhg=(("<<_grab.x<<", "<<_grab.y<<", "<<_grab.z<<"),("<<_position.x<<", "<<_position.y<<", "<<_position.z<<")); bumps=((0, 0.005, 0),(0, 0.01, 0));"; 00166 //s << "OUT FF3D : picobhg=(("<<_grab.x<<", "<<_grab.y<<", "<<_grab.z<<"),("<<_position.x<<", "<<_position.y<<", "<<_position.z<<")); bumps=((0.005, 0, 0),(0.01, 0, 0));"; 00167 00168 } 00169 00170 00171 void InputAgentExample::onMove(Vec2f pos) 00172 { 00173 MicoleStringStream ss; 00174 ss << "OUT FF3D GUIDE : point=("<<_pos.x<< ", " << _pos.y << ", 0.0);"; 00175 MouseInputAgent::sendMessage(ss.getString().c_str()); 00176 } 00177 00178 void InputAgentExample::onEvt(string evt) 00179 { 00180 if(evt.compare("BT1_PRESSED")==0) 00181 { 00182 } 00183 } 00184 00185 void InputAgentExample::onTimer() 00186 { 00187 /*MicoleStringStream ss; 00188 ss << "Net: elapsed time: "<<_timePassed++; 00189 MouseInputAgent::sendMessage(ss.getString().c_str());*/ 00190 } 00191 #endif