int main(int argc, char* argv[]) { HAPIFloat x=0, y=0, z=0; AnyHapticsDevice hd; //initialize. return error and exit if there is a failure if (hd.initDevice() !=HAPIHapticsDevice::SUCCESS) { cerr <<hd.getLastErrorMsg() <<endl; system("PAUSE"); return 0; } hd.enableDevice(); //enable string thePosition; string theSpringConst; bool continue_trying = true; while(continue_trying) { cout<<"Enter position 0<n<10 for x, y, z (separate by spaces)"<<endl; getline(cin, thePosition); char *pEnd; x = strtod(thePosition.c_str(), &pEnd); y = strtod(pEnd, &pEnd); z = strtod(pEnd, NULL); x = x/200; y = y/200; z = z/200; cout<<"Enter spring constant:"<<endl; cout<<"100 is relatively weak, 1000 is strong"<<endl; getline(cin, theSpringConst); HAPIFloat spring_constant = strtod(theSpringConst.c_str(), NULL); //stringstream stm_x, stm_y, stm_z, stm_const; //stm_x << x; //stm_y << y; //stm_z << z; //stm_const << spring_constant; //add spring to haptics HapticSpring *spring = new HapticSpring(Vec3(x,y,z), spring_constant); hd.addEffect(spring); hd.transferObjects(); cout<<"Press enter to change position and spring constant"<<endl; getline(cin, thePosition); hd.removeEffect(spring); hd.transferObjects(); } hd.disableDevice(); hd.releaseDevice(); }
int main(int argc, char* argv[]) { // Get a connected device. AnyHapticsDevice hd; // Init the device. if( hd.initDevice() != HAPIHapticsDevice::SUCCESS ) { cerr << hd.getLastErrorMsg() << endl; return 0; } // Enable the device hd.enableDevice(); // used to loop the program until user wants to exit. bool continue_trying = true; while( continue_trying ) { // Get info from user. cout << "Enter a position as x y z (in m) then press ENTER" << endl; string thePosition; getline( cin, thePosition ); char * pEnd; HAPIFloat x, y, z; x = strtod( thePosition.c_str(), &pEnd ); y = strtod( pEnd, &pEnd ); z = strtod( pEnd, NULL ); cout << "Enter the value for a spring constant then press ENTER." << endl; cout << "A good value is 100 since HAPI uses m." << endl; cout << "Keep a firm grip of the device before pressing ENTER." << endl; getline( cin, thePosition ); HAPIFloat spring_constant = strtod( thePosition.c_str(), NULL ); cout << "The haptic device will be pulled towards position "; cout << x << " "; cout << y << " " << z << endl; cout << "The spring constant used is: " << spring_constant << endl; cout << "Any faulty input number will be replaced by 0" << endl << endl; // The spring effect with a position and spring_constant input by the user. HapticSpring *spring_effect = new HapticSpring( Vec3( x, y, z ), spring_constant ); // Add the effect to the haptics device. hd.addEffect( spring_effect ); // Send the effect to the haptics loop and from now on it will be used to // send forces to the device. hd.transferObjects(); cout << "Type q and then ENTER to exit, any other input and then "; cout << "ENTER will allow you to a new point and a new springconstant" << endl; getline( cin, thePosition ); if( thePosition == "q" ) { continue_trying = false; } // Remove the effect from the haptics device. hd.removeEffect( spring_effect ); // Transfer changes to the haptic loop. Now the haptic effect will stop // affecting the haptics device since it is removed from the haptics loop. hd.transferObjects(); } // Disable device. hd.disableDevice(); // Release device. hd.releaseDevice(); }