int main(int, char const**) { // Create the main window sf::RenderWindow window(sf::VideoMode(800, 600), "Gemini", sf::Style::Close); srand(std::chrono::system_clock::now().time_since_epoch()/std::chrono::milliseconds(1)%10000); window.setFramerateLimit(40); unsigned int maxNumberOfThreads = std::thread::hardware_concurrency(); maxNumberOfThreads = 1; // Set the Icon sf::Image icon; if (!icon.loadFromFile(resourcePath() + "icon.png")) { return EXIT_FAILURE; } window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr()); Board board; board.setRandomArr(); HashTable transpositionTable; RunAIInput input; input.shouldAiBeRunning = false; input.transpositionTable = &transpositionTable; SearchAICommunicator searchCommunicator[4]; if(maxNumberOfThreads != 1) { while(input.lock.try_lock()){} for(int i=0; i<maxNumberOfThreads; i++) { searchCommunicator[i].transpositionTable = &transpositionTable; input.communicator.push_back(&searchCommunicator[i]); } input.lock.unlock(); } Controller controller = Controller(&input); pthread_t aiThread; pthread_create(&aiThread, NULL, startAI, (void *)(&input)); bool commandLeft = false; bool commandRight = false; while (window.isOpen()) { // Process events sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { window.close(); } else if(event.type == sf::Event::KeyPressed) { if(event.key.code == sf::Keyboard::Escape) { // Escape pressed : exit while(input.lock.try_lock()){} input.shouldAiBeRunning = false; input.lock.unlock(); struct timespec tim, tim2; tim.tv_sec = 0; tim.tv_nsec = 10; // milliseconds tim.tv_nsec *= 1000000; nanosleep(&tim , &tim2); window.close(); } else if(event.key.code == sf::Keyboard::LSystem) { commandLeft = true; } else if(event.key.code == sf::Keyboard::RSystem) { commandRight = true; } else if((commandLeft || commandRight) && (event.key.code == sf::Keyboard::W || event.key.code == sf::Keyboard::Q)) { window.close(); } else if(event.key.code == sf::Keyboard::W) { if(commandLeft || commandRight) { window.close(); } } else { controller.keyDown(event.key.code); } } else if(event.type == sf::Event::KeyReleased) { if(event.key.code == sf::Keyboard::LSystem) { commandLeft = false; } else if(event.key.code == sf::Keyboard::RSystem) { commandRight = false; } else { controller.keyUp(event.key.code); } } else if(event.type == sf::Event::MouseMoved) { controller.mouseMove(event.mouseMove); } else if(event.type == sf::Event::MouseButtonPressed) { controller.mouseDown(event.mouseButton); } else if(event.type == sf::Event::MouseButtonReleased) { controller.mouseUp(event.mouseButton); } else if(event.type == sf::Event::Resized) { controller.resized(event.size); } else if(event.type == sf::Event::TextEntered) { controller.textEntered(event.text.unicode); } } // Clear screen window.clear(); controller.frame(&window); // Update the window window.display(); } return EXIT_SUCCESS; }
void Menu::process_input() { int menu_height = (int) get_height(); if (menu_height > SCREEN_HEIGHT) { // Scrolling int scroll_offset = (menu_height - SCREEN_HEIGHT) / 2 + 32; pos.y = SCREEN_HEIGHT/2 - scroll_offset * ((float(active_item) / (items.size()-1)) - 0.5f) * 2.0f; } MenuAction menuaction = MENU_ACTION_NONE; Controller* controller = InputManager::current()->get_controller(); /** check main input controller... */ if(controller->pressed(Controller::UP)) { menuaction = MENU_ACTION_UP; menu_repeat_time = real_time + MENU_REPEAT_INITIAL; } if(controller->hold(Controller::UP) && menu_repeat_time != 0 && real_time > menu_repeat_time) { menuaction = MENU_ACTION_UP; menu_repeat_time = real_time + MENU_REPEAT_RATE; } if(controller->pressed(Controller::DOWN)) { menuaction = MENU_ACTION_DOWN; menu_repeat_time = real_time + MENU_REPEAT_INITIAL; } if(controller->hold(Controller::DOWN) && menu_repeat_time != 0 && real_time > menu_repeat_time) { menuaction = MENU_ACTION_DOWN; menu_repeat_time = real_time + MENU_REPEAT_RATE; } if(controller->pressed(Controller::LEFT)) { menuaction = MENU_ACTION_LEFT; menu_repeat_time = real_time + MENU_REPEAT_INITIAL; } if(controller->hold(Controller::LEFT) && menu_repeat_time != 0 && real_time > menu_repeat_time) { menuaction = MENU_ACTION_LEFT; menu_repeat_time = real_time + MENU_REPEAT_RATE; } if(controller->pressed(Controller::RIGHT)) { menuaction = MENU_ACTION_RIGHT; menu_repeat_time = real_time + MENU_REPEAT_INITIAL; } if(controller->hold(Controller::RIGHT) && menu_repeat_time != 0 && real_time > menu_repeat_time) { menuaction = MENU_ACTION_RIGHT; menu_repeat_time = real_time + MENU_REPEAT_RATE; } if(controller->pressed(Controller::ACTION) || controller->pressed(Controller::MENU_SELECT)) { menuaction = MENU_ACTION_HIT; } if(controller->pressed(Controller::ESCAPE) || controller->pressed(Controller::START) || controller->pressed(Controller::MENU_BACK)) { menuaction = MENU_ACTION_BACK; } if(items.size() == 0) return; // The menu_action() call can pop() the menu from the stack and thus // delete it, so it's important that no further member variables are // accessed after this call process_action(menuaction); }
void LeapListener::onFrame(const Controller &controller){ const Frame frame = controller.frame(); HandList hands = frame.hands(); std::vector<HandModel> myhands; BoneModel mybone; HandModel myhand; //printf("frame: %d\n", frame.id()); float scale = 0.025; float disp = 3.5f; bool record = true; for (int i = 0; i < hands.count(); i++){ FingerList fingers = hands[i].fingers(); myhand.bones.clear(); myhand.references.clear(); Vector handPosition = hands[i].palmPosition(); handPosition *= scale; handPosition.y -= disp; Vector wrist = hands[i].wristPosition(); wrist *= scale; wrist.y -= disp; myhand.palmPosition = handPosition; myhand.palmNormal = hands[i].palmNormal(); myhand.direction = hands[i].direction(); for (int j = 0; j < fingers.count(); j++){ Bone bone; Bone::Type boneType; Vector currentPosition = fingers[j].tipPosition(); currentPosition *= scale; currentPosition.y -= disp; Vector lastPosition = m_lastFrame.finger(fingers[j].id()).tipPosition(); lastPosition *= scale; lastPosition.y -= disp; Vector diff = currentPosition - lastPosition; //printf("%f, %f, %f\n", abs(diff.x), abs(diff.y), abs(diff.z)); //if (abs(diff.x) > 0.2 || abs(diff.y) > 0.2 || abs(diff.z) > 0.2) record = false; if (abs(diff.x) < 0.0001 || abs(diff.y) < 0.0001 || abs(diff.z) < 0.0001) record = false; for (int k = 0; k < 4; k++){ boneType = static_cast<Bone::Type>(k); bone = fingers[j].bone(boneType); if (fingers[j].type() == Finger::Type::TYPE_THUMB && k == 0) continue; Vector prevPos = bone.prevJoint(); prevPos *= scale; prevPos.y -= disp; Vector nextPos = bone.nextJoint(); nextPos *= scale; nextPos.y -= disp; mybone.direction = nextPos - prevPos; mybone.position = (prevPos + nextPos) / 2; mybone.prevJoint = prevPos; mybone.nextJoint = nextPos; mybone.length = bone.length() * scale; if (boneType == Bone::Type::TYPE_PROXIMAL){ if (fingers[j].type() == Finger::Type::TYPE_THUMB){ myhand.thumb = prevPos; //myhand.references.push_back(nextPos); } else{ myhand.references.push_back(prevPos); } } myhand.bones.push_back(mybone); } } myhand.base = myhand.references[3] - myhand.references[0]; Vector disp = myhand.base.normalized() * 0.3f; myhand.references[3] += disp; myhand.references[0] -= disp; //for (int i = 1; i < 5; i++){ // printf("%f\n", myhand.references[i - 1].distanceTo(myhand.references[i])); //} myhands.push_back(myhand); } if (record){ m_hands.clear(); for (int i = 0; i < myhands.size(); i++){ m_hands.push_back(myhands[i]); } } m_lastFrame = frame; }
void SampleListener::onFrame(const Controller& controller) { // Get the most recent frame and report some basic information const Frame frame = controller.frame(); /* std::cout << "Frame id: " << frame.id() << ", timestamp: " << frame.timestamp() << ", hands: " << frame.hands().count() << ", fingers: " << frame.fingers().count() << ", tools: " << frame.tools().count() << std::endl; */ if (!frame.hands().empty()) { // get mutex boost::mutex::scoped_lock lk(mtx); // clear last datas rhand.clear(); //vhand.clear(); //mhand.clear(); //vfinger.clear(); // set new datas Vector3f v, x, y, z; Matrix3f m; Vector tmp, normal, direction; capture_time.pop_front(); capture_time.push_back(frame.timestamp()); const HandList hlist = frame.hands(); // for(int i=0;i<hlist.count();i++){ int i=0; rhand.push_back(hlist[i].sphereRadius()); tmp = hlist[i].palmPosition(); v << -tmp[2]/1000.0f, -tmp[0]/1000.0f, tmp[1]/1000.0f; vhand.pop_front(); vhand.push_back(v); tmp = hlist[i].palmVelocity(); v << -tmp[2]/1000.0f, -tmp[0]/1000.0f, tmp[1]/1000.0f; vvhand.pop_front(); vvhand.push_back(v); /* normal = hlist[i].palmNormal(); direction = hlist[i].direction(); y << -normal[2], -normal[0], normal[1]; z << -direction[2], -direction[0], direction[1]; z = -z; x = y.cross(z); z = x.cross(y); m << x[0], x[1], x[2], y[0], y[1], y[2], z[0], z[1], z[2]; mhand.push_back(m); */ // } /* // Check if the hand has any fingers const FingerList fingers = frame.fingers(); for(int i=0;i<fingers.count();i++){ tmp = fingers[i].tipPosition(); v << -tmp[2]/1000.0f, -tmp[0]/1000.0f, tmp[1]/1000.0f; vfinger.push_back(v); } */ } }
//============================== int startGame() { initExternLibrary(); initSDL(); initDecoder(); initTunnelNetwork(); initController(); SDL_Event event; _beginthread(networkThread,NULL,NULL); _beginthread(SDL_VideoDisplayThread,NULL,NULL); runFlag=true; while(runFlag) { Sleep(GUISLEEPTIME); while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: if(event.key.keysym.sym==SDLK_F2) { SDL_WM_GrabInput(SDL_GRAB_OFF); break; } //printf("%d%d\n",event.key.keysym.sym,event.key.keysym.mod); controller.sendKeyEvent(event.key.keysym.sym,event.key.keysym.mod); break; case SDL_MOUSEMOTION: //printf("Mouse moved by %d,%d to (%d,%d)\n",event.motion.xrel, event.motion.yrel,event.motion.x, event.motion.y); controller.sendMouseEvent(event.motion.xrel, event.motion.yrel,0,0); break; case SDL_MOUSEBUTTONDOWN: if(SDL_WM_GrabInput(SDL_GRAB_QUERY)==SDL_GRAB_OFF) { SDL_WM_GrabInput(SDL_GRAB_ON); break; } //printf("Mouse button %d pressed at (%d,%d,%d,%d)\n",event.button.button, event.button.x, event.button.y,event.motion.xrel,event.motion.yrel); controller.sendMouseEvent(0,0,event.button.button,PRESSDOWNDIRECTION); break; case SDL_MOUSEBUTTONUP: controller.sendMouseEvent(0,0,event.button.button,PRESSUPDIRECTION); break; case SDL_QUIT: runFlag = false; break; default: break; } } } tunnel.stopTunnelLoop(); Sleep(2000); WSACleanup(); return 0; }
int main(int argc, char* argv[]) { // parameter uint32_t drv_num = 5; uint64_t max_drv_bytes = (uint64_t)32*(1024*1024*1024); //double avg_cmp_ratio = 0.5; double ctl_op_ratio = 1.25; uint32_t ctl_cmp_chunk = 16; double ssd_op_ratio = 1.25; uint64_t ttl_io = 32*1024*1024 ; // uint64_t ttl_io = 1 ; uint32_t io_size_sect = 8; COMP_MODE mode = CTL_SIDE; std::string trace_file = "osdb_comp_trace.txt"; bool single_ssd_mode = true; bool skip_ssd_mode = false; { // analyze input argument int i; if( argc == 1 ) { printf("#_no_opt:_load_default_parameter\n"); } else { for( i = 1; i < argc; i++ ) { if( strcmp(argv[i], "--drive_num") == 0 || strcmp(argv[i], "-d") ==0 ) { if( !CheckAdditionalOpt(++i, argc, argv) ) return 0; else drv_num = atoi(argv[i]); } else if( strcmp(argv[i], "--max_drive_bytes") == 0 || strcmp(argv[i], "-b") ==0 ) { if( !CheckAdditionalOpt(++i, argc, argv) ) return 0; else max_drv_bytes = std::stoull(argv[i]); } // else if( strcmp(argv[i], "--avg_cmp_ratio") == 0 || strcmp(argv[i], "-c") ==0 ) // { // if( !CheckAdditionalOpt(++i, argc, argv) ) return 0; // else avg_cmp_ratio = std::stod(argv[i]); // } else if( strcmp(argv[i], "--comp_mode") == 0 || strcmp(argv[i], "-m") ==0 ) { if( !CheckAdditionalOpt(++i, argc, argv) ) return 0; else if( strcmp(argv[i], "c") == 0 ) mode = CTL_SIDE; else if( strcmp(argv[i], "s") == 0 ) mode = SSD_SIDE; else { printf("invalid option for mode%s\n", argv[i] ); return false; } } else if( strcmp(argv[i], "--ctl_op_ratio") == 0 || strcmp(argv[i], "-R") ==0 ) { if( !CheckAdditionalOpt(++i, argc, argv) ) return 0; else ctl_op_ratio = std::stod(argv[i]); } else if( strcmp(argv[i], "--ctl_cmp_chunk") == 0 || strcmp(argv[i], "-C") ==0 ) { if( !CheckAdditionalOpt(++i, argc, argv) ) return 0; else ctl_cmp_chunk = std::stol(argv[i]); } else if( strcmp(argv[i], "--ssd_op_ratio") == 0 || strcmp(argv[i], "-r") ==0 ) { if( !CheckAdditionalOpt(++i, argc, argv) ) return 0; else ssd_op_ratio = std::stod(argv[i]); } //else if( strcmp(argv[i], "--ttl_io_cnt") == 0 || strcmp(argv[i], "-i") ==0 ) //{ // if( !CheckAdditionalOpt(++i, argc, argv) ) return 0; // else ttl_io = std::stoll(argv[i]); //} else if( strcmp(argv[i], "--trace_file") == 0 || strcmp(argv[i], "-t") ==0 ) { if( !CheckAdditionalOpt(++i, argc, argv) ) return 0; else trace_file = argv[i]; } else if( strcmp(argv[i], "--skip_ssd") == 0 ) { skip_ssd_mode = true; } else if( strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0 ) { HowtoUse(argv[0]); return 0; } else { printf("Invalid option -- %s\n", argv[i]); HowtoUse(argv[0]); return 0; } } } } Controller* ctl; std::vector<SSD*> ssd_list; std::vector<DriveInfo*> drv_list; CompEngine cmp_engine; ssd_list.resize(drv_num); drv_list.resize(drv_num); // initialization if( !cmp_engine.init_engine(trace_file.c_str()) ) ERR_AND_RTN; if( mode == CTL_SIDE ) { // controller side compression for( uint32_t i = 0; i < drv_num; i++ ) { ssd_list[i] = new SSD; drv_list[i] = new DriveInfo; if( !ssd_list[i]->simple_init( max_drv_bytes, ssd_op_ratio)) ERR_AND_RTN; drv_list[i]->max_lba = ssd_list[i]->get_max_lba(); } CompController* c_ctl = new CompController; if( !c_ctl->build_raid(RAID5, drv_list) ) ERR_AND_RTN; if( !c_ctl->init(&cmp_engine, 1 - 1/ctl_op_ratio, ctl_cmp_chunk) ) ERR_AND_RTN; ctl = c_ctl; } else { // ssd side compression for( uint32_t i = 0; i < drv_num; i++ ) { CompSSD* c_ssd = new CompSSD; bool enable_virt = true; uint32_t buffered_page_num = 4; if( !c_ssd->setup_compression(enable_virt, &cmp_engine, A_CC_FTL, buffered_page_num ) ) ERR_AND_RTN; if( !c_ssd->simple_init( max_drv_bytes, ssd_op_ratio ) ) ERR_AND_RTN; ssd_list[i] = c_ssd; drv_list[i] = new DriveInfo; drv_list[i]->max_lba = ssd_list[i]->get_max_lba(); } ctl = new Controller; if( !ctl->build_raid(RAID5, drv_list) ) ERR_AND_RTN; } // sim start time_t now = time(NULL); struct tm *pnow = localtime(&now); std::cout << "#start time: " << pnow->tm_hour << ":" << pnow->tm_min << ":" << pnow->tm_sec << std::endl; // print settings std::cout << "#settings, mode, dnum, drive_sect, drive_lba, cmp_ratio, ctl_opr, ctl_chunk, ssd_opr, ttl_io, comp_trace, skip_ssd" << std::endl; std::cout << "," << (mode == CTL_SIDE ? "C" : "S") << "," << drv_num << ","<< ssd_list[0]->get_phy_sect() << "," << ssd_list[0]->get_max_lba() << ","<< cmp_engine.get_avg_cmp_ratio() << ","<< ctl_op_ratio << ","<< ctl_cmp_chunk << ","<< ssd_op_ratio << ","<< ttl_io << "," << trace_file << "," << ((skip_ssd_mode)? "on":"off") << std::endl; // main CommandInfo cmd; DriveCommandInfo drv_cmd; //const uint64_t check_point = ttl_io / 100; //uint64_t check_count = 0; sim_srand(0); uint32_t round = 2; ttl_io = (ctl->get_max_lba()/io_size_sect); uint64_t io_align = (ctl->get_max_lba()/io_size_sect) - 1; //std::cout << "caution: test code included" << std::endl; for( uint32_t r = 0; r < round ; r++ ) { for( uint64_t i = 0; i < ttl_io; i++ ) { //if( check_count > check_point ) { // printf(" %ld / %ld, ", i , ttl_io ); // fflush(stdout); // check_count = 0; //} // check_count++; cmd.opcode = IO_WRITE; cmd.sector_num = io_size_sect; //cmd.lba = sim_rand64(ctl->get_max_lba() - cmd.sector_num ); cmd.lba = sim_rand64(io_align) * io_size_sect; if( !ctl->receive_command( cmd) ) return false; while( ctl->pull_next_command(drv_cmd) ) { CommandInfo& cmd2drv = drv_cmd.cmd_info; if( skip_ssd_mode ) continue; if( single_ssd_mode && drv_cmd.tgt_drive != 0 ) continue; if( cmd2drv.opcode == IO_WRITE ) { if( !ssd_list[drv_cmd.tgt_drive]->write(cmd2drv.lba, cmd2drv.sector_num) ) { ERR_AND_RTN; } } else if( cmd2drv.opcode == IO_READ ) { if( !ssd_list[drv_cmd.tgt_drive]->read(cmd2drv.lba, cmd2drv.sector_num) ) { ERR_AND_RTN; } }else ERR_AND_RTN; } } if( r == 0 ) { ctl->clear_statistics(); for( auto s : ssd_list ) s->clear_statistics(); } } //printf("\n"); ctl->print_statistics(); if( single_ssd_mode ) ssd_list[0]->print_statistics(); else { for( auto s : ssd_list ) { s->print_statistics(); } } // clean up delete ctl; for( auto s : ssd_list ) delete s; ssd_list.clear(); for( auto d : drv_list ) delete d; now = time(NULL); pnow = localtime(&now); std::cout << "#end time: " << pnow->tm_hour << ":" << pnow->tm_min << ":" << pnow->tm_sec << std::endl; return 0; }
ProtoProcessFile ( Controller<ProtoProcessFile<T>, T>& controller, const std::string& name ) : ProcessFile ( controller.getFS(), name ), controller_ ( controller ) {}
/** Sets the position in race this kart has (1<=p<=n). */ virtual void setPosition(int p) { m_controller->setPosition(p); m_race_position = p; } // setPosition
static int isAnyAvailable(lua_State *L) { Controller *c = getInstance(L, 1); lua_pushboolean(L, (bool)c->isAnyAvailable()); return 1; }
// 按位取反 void BitwiseFlip(Tape &t) { Controller c; // 如果这里看到的是0,那么S1将写1; // 如果这里看到的是1,那么S2将写0。 c.AddRule(0, '0', 1, ' ', 'R'); c.AddRule(0, '1', 2, ' ', 'R'); c.AddRule(0, '$', 4, '$', 'S'); c.AddRule(1, '0', 1, '0', 'R'); c.AddRule(1, '1', 1, '1', 'R'); c.AddRule(1, ' ', 3, '1', 'L'); c.AddRule(1, '$', 1, '$', 'R'); c.AddRule(2, '0', 2, '0', 'R'); c.AddRule(2, '1', 2, '1', 'R'); c.AddRule(2, ' ', 3, '0', 'L'); c.AddRule(2, '$', 2, '$', 'R'); // 往回移到数字开头。 c.AddRule(3, '0', 3, '0', 'L'); c.AddRule(3, '1', 3, '1', 'L'); c.AddRule(3, ' ', 0, ' ', 'R'); c.AddRule(3, '$', 3, '$', 'L'); c.MarkFinal(4); c.Run(t, true); }
// a<=b? // 必须同等长度 void Less(Tape &t) { Controller c; // 若第一位为0,则去(a) // 若第一位为1,则去(b) c.AddRule(0, '0', 1, ' ', 'R'); c.AddRule(0, '1', 4, ' ', 'R'); c.AddRule(0, '$', 6, ' ', 'R'); // 等于最后也写0 // (a) 若0,把第二个数的第一位改成$;若1,则确定小于 c.AddRule(1, '0', 1, '0', 'R'); c.AddRule(1, '1', 1, '1', 'R'); c.AddRule(1, '$', 2, '$', 'R'); c.AddRule(2, '$', 2, '$', 'R'); c.AddRule(2, '0', 3, '$', 'L'); c.AddRule(2, '1', 9, ' ', 'R'); // 移回第一个数开头。 c.AddRule(3, '0', 3, '0', 'L'); c.AddRule(3, '1', 3, '1', 'L'); c.AddRule(3, '$', 3, '$', 'L'); c.AddRule(3, ' ', 0, ' ', 'R'); // (b) 如果第二个数的第一位是1继续比较;如果是0,那确定大于 c.AddRule(4, '0', 4, '0', 'R'); c.AddRule(4, '1', 4, '1', 'R'); c.AddRule(4, '$', 5, '$', 'R'); c.AddRule(5, '$', 5, '$', 'R'); c.AddRule(5, '0', 6, ' ', 'R'); c.AddRule(5, '1', 3, '$', 'L'); // 最后写0 c.AddRule(6, '0', 6, ' ', 'R'); c.AddRule(6, '1', 6, ' ', 'R'); c.AddRule(6, '$', 6, ' ', 'R'); c.AddRule(6, ' ', 7, '0', 'R'); // 最后写1 c.AddRule(9, '0', 9, ' ', 'R'); c.AddRule(9, '1', 9, ' ', 'R'); c.AddRule(9, '$', 9, ' ', 'R'); c.AddRule(9, ' ', 7, '1', 'R'); //c.AddRule(7, ' ', 8, '$', 'L'); c.MarkFinal(7); c.Run(t, true); }
int processVideo() { VideoCapture capture(1); if (!capture.isOpened()) { cerr << "Failed to open video stream\n" << endl; return 1; } namedWindow("Main", CV_WINDOW_KEEPRATIO); //resizable window; Mat rgbFrame, grayFrame; capture.read(rgbFrame); // Try to read the pattern: cv::Mat patternImage, patternImageGray; patternImage = cv::imread(path + "/images/card.jpg"); if (patternImage.empty()) { std::cout << "Input image cannot be read" << std::endl; return 2; } cvtColor(patternImage, patternImageGray, CV_RGB2GRAY); Controller *controller = Controller::getInstance(); for (; ;) { capture.read(rgbFrame); if (rgbFrame.empty()) break; if (!controller->isInitialized) { controller->initialize(rgbFrame, path); } cvtColor(rgbFrame, grayFrame, CV_RGB2GRAY); if (grayFrame.empty()) { std::cout << "Cannot open video capture device" << std::endl; } // call display function with frame data controller->displayFunction(rgbFrame, grayFrame); imshow("Main", rgbFrame); char key = (char) waitKey(5); //delay N millis, usually long enough to display and capture input switch (key) { case 'q': controller->isModeObjectDetection(true); cout << "Recognition started.." << endl; break; case 'w': controller->isModeObjectDetection(false); cout << "Recognition stopped!" << endl; break; case 'e': controller->isModeTracking(true); cout << "Tracking started.." << endl; break; case 'r': controller->isModeTracking(false); cout << "Tracking stopped!" << endl; break; case 's': controller->createObjectPattern(patternImage, patternImageGray); cout << "Image registered" << endl; break; case 'd': controller->createObjectPattern(rgbFrame, grayFrame); cout << "Frame registered" << endl; break; case 't': cout << "Configure SURF as detector" << endl; cout << "RESULT=" << controller->setDetector("SURF"); break; case 'z': cout << "Configure SURF as extractor" << endl; cout << "RESULT=" << controller->setExtractor("SURF"); break; case 'u': cout << "Configure BF as matcher" << endl; cout << "RESULT=" << controller->setMatcher("BF"); break; case 27: //escape key return 0; default: break; } } }
int main() { int action = -1; Controller controller; TaskList* taskList = new TaskList(); taskLoader = new TaskLoader("tasks"); taskLoader->loadTasks(taskList); while(action != 0) { system("clear"); std::cout << "Wybierz opcje:\n" << std::endl; std::cout << "1 - Dodaj zadanie" << std::endl; std::cout << "2 - Wypisz listę zadań" << std::endl; std::cout << "0 - Zakończ działanie programu\n" << std::endl; std::cout << "Podaj nr opcji: "; while(!(std::cin >> action) || ((action != 1) && (action != 2) && (action != 0))) { std::cout << "Podałeś zły nr opcji i nasatąpiło wyrzucenie nic nie zaczącego wyjątku." << std::endl; try { throw std::exception(); } catch(std::exception& e) { std::cout << "Następuje obsługe nic nie zaczącego wyjątku" << std::endl; std::cout << e.what(); } std::cout << "Spróbuj jeszcze raz: "; std::cin.clear(); std::cin.ignore (1000, '\n'); } switch(action) { case 1: try { controller.addTask(taskList); } catch(std::exception& e) { std::cout << "Podałeś złą wartść. Wszystkie poprzednie zaminy zostaną zapisane i nastąpi wyjcie z programu."; taskLoader->saveLastLoadedTasks(); exit(0); } break; case 2: while(action != 0) { system("clear"); controller.showTasksList(taskList); std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << "Wybierz opcje:\n" << std::endl; std::cout << "1 - Przejdź do wybranego zadania" << std::endl; std::cout << "0 - Powróć do głównego menu" << std::endl; std::cout << "Podaj nr opcji: "; while(!(std::cin >> action) || ((action != 1) && (action != 0))) { std::cout << "Podałeś zły nr opcji. Spróbuj jeszcze raz: "; std::cin.clear(); std::cin.ignore (1000, '\n'); } switch(action) { case 1: int taskId; std::cout << "Podaj id zadania: "; while(!(std::cin >> taskId) || !((taskList->getNumberOfTasks() + 1 > taskId) && (taskId > 0))) { std::cout << "Podałeś zły nr id zadania. Spróbuj jeszcze raz: "; std::cin.clear(); std::cin.ignore (1000, '\n'); } taskId--; while(action != 0) { system("clear"); controller.showTask(taskList->getTask(taskId)); std::cout << std::endl; std::cout << std::endl; std::cout << std::endl; std::cout << "Wybierz opcje:\n" << std::endl; std::cout << "1 - Edytuj zadanie" << std::endl; std::cout << "2 - Usuń zadanie" << std::endl; std::cout << "0 - Powróć do listy zadań" << std::endl; std::cout << "Podaj nr opcji: "; while(!(std::cin >> action) || ((action != 1) && (action != 2) && (action != 0))) { std::cout << "Podałeś zły nr opcji. Spróbuj jeszcze raz: "; std::cin.clear(); std::cin.ignore (1000, '\n'); } switch(action) { case 1: try { controller.editTask(taskList->getTask(taskId)); } catch(std::exception& e) { std::cout << "Podałeś złą wartść. Wszystkie poprzednie zaminy zostaną zapisane i nastąpi wyjcie z programu."; taskLoader->saveLastLoadedTasks(); exit(0); } break; case 2: controller.removeTask(taskList, taskId); action = 0; break; case 0: break; default: break; } } action = -1; break; case 0: break; default: break; } } action = -1; break; case 0: break; default: break; } } taskLoader->saveTasks(taskList); return 0; }
void runTest1 () { Controller controller; controller.addBook( "AAA", std::vector< std::string >( 1, "Author 1" ), "en", 2000 ); controller.addRevised( "AAA", 1, 2, 2005 ); controller.addTranslation( "le AAA", "AAA", "fr", 2012 ); controller.addBook( "BBB", std::vector< std::string >( 1, "Author 2" ), "en", 2002 ); controller.addRevised( "BBB", 1, 2, 2007 ); controller.addTranslation( "la BBB", "BBB", "it", 2008 ); controller.addBook( "CCC", std::vector< std::string >( 1, "Author 3" ), "en", 2002 ); controller.addRevised( "CCC", 1, 2, 2005 ); controller.addBook( "DDD", std::vector< std::string >( 1, "Author 4" ), "en", 2004 ); controller.addTranslation( "das DDD", "DDD", "de", 2009 ); controller.addBook( "EEE", std::vector< std::string >( 1, "Author 5" ), "en", 2007 ); std::set< std::string > result = controller.fetchBooksBothTranslatedRevised(); assert( result.size() == 2 ); assert( result.find( "AAA" ) != result.end() ); assert( result.find( "BBB" ) != result.end() ); result = controller.fetchAuthorsNotBeingTranslated(); assert( result.size() == 2 ); assert( result.find( "Author 3" ) != result.end() ); assert( result.find( "Author 5" ) != result.end() ); }
void EventStart::accept(Controller& visitor) { visitor.visit(*this); }
static int getPlayerCount(lua_State *L) { Controller *c = getInstance(L, 1); lua_pushnumber(L, c->getPlayerCount()); return 1; }
void SampleListener::onConnect(const Controller& controller) { /* printf("Connected\n"); */ controller.enableGesture(Gesture::TYPE_CIRCLE); controller.enableGesture(Gesture::TYPE_KEY_TAP); controller.enableGesture(Gesture::TYPE_SCREEN_TAP); controller.enableGesture(Gesture::TYPE_SWIPE); }
static int getControllerName(lua_State *L) { Controller *c = getInstance(L, 1); lua_pushstring(L, c->getControllerName(lua_tonumber(L, 2))); return 1; }
/*! * Haupteinstiegspunkt des Indexers * @param argc Anzahl der Kommandozeilenparameter * @param argv die eigentlichen Kommandozeilenparameter */ int main(int argc, char* argv[]) { Controller c; return c.runIndexer(argc, argv); }
static int vibrate(lua_State *L) { Controller *c = getInstance(L, 1); c->vibrate(lua_tonumber(L, 2), lua_tonumber(L, 3)); return 0; }
void ColoniseCmd::UpdateClient(const Controller& controller, const LiveGame& game) const { controller.SendMessage(Output::ChooseColonisePos(GetPositions(game)), GetPlayer(game)); }
static int loader(lua_State *L) { const luaL_Reg functionlist[] = { {"isAnyAvailable", isAnyAvailable}, {"getPlayerCount", getPlayerCount}, {"getControllerName", getControllerName}, {"getPlayers", getPlayers}, {"vibrate", vibrate}, {"setDeadZone", lSetDeadZone}, {NULL, NULL}, }; g_createClass(L, "Controller", "EventDispatcher", NULL, destruct, functionlist); // create a weak table in LUA_REGISTRYINDEX that can be accessed with the address of keyWeak luaL_newweaktable(L, "v"); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_getglobal(L, "Event"); lua_pushstring(L, RIGHT_JOYSTICK); lua_setfield(L, -2, "RIGHT_JOYSTICK"); lua_pushstring(L, LEFT_JOYSTICK); lua_setfield(L, -2, "LEFT_JOYSTICK"); lua_pushstring(L, RIGHT_TRIGGER); lua_setfield(L, -2, "RIGHT_TRIGGER"); lua_pushstring(L, LEFT_TRIGGER); lua_setfield(L, -2, "LEFT_TRIGGER"); lua_pushstring(L, AXIS_JOYSTICK); lua_setfield(L, -2, "AXIS_JOYSTICK"); lua_pushstring(L, CONNECTED); lua_setfield(L, -2, "CONNECTED"); lua_pushstring(L, DISCONNECTED); lua_setfield(L, -2, "DISCONNECTED"); lua_pop(L, 1); lua_getglobal(L, "KeyCode"); lua_pushnumber(L, DPAD_DOWN); lua_setfield(L, -2, "DPAD_DOWN"); lua_pushnumber(L, DPAD_LEFT); lua_setfield(L, -2, "DPAD_LEFT"); lua_pushnumber(L, DPAD_RIGHT); lua_setfield(L, -2, "DPAD_RIGHT"); lua_pushnumber(L, DPAD_UP); lua_setfield(L, -2, "DPAD_UP"); lua_pushnumber(L, BUTTON_L1); lua_setfield(L, -2, "BUTTON_L1"); lua_pushnumber(L, BUTTON_L2); lua_setfield(L, -2, "BUTTON_L2"); lua_pushnumber(L, BUTTON_L3); lua_setfield(L, -2, "BUTTON_L3"); lua_pushnumber(L, BUTTON_R1); lua_setfield(L, -2, "BUTTON_R1"); lua_pushnumber(L, BUTTON_R2); lua_setfield(L, -2, "BUTTON_R2"); lua_pushnumber(L, BUTTON_R3); lua_setfield(L, -2, "BUTTON_R3"); lua_pushnumber(L, BUTTON_MENU); lua_setfield(L, -2, "BUTTON_MENU"); lua_pushnumber(L, BUTTON_BACK); lua_setfield(L, -2, "BUTTON_BACK"); lua_pushnumber(L, BUTTON_A); lua_setfield(L, -2, "BUTTON_A"); lua_pushnumber(L, BUTTON_X); lua_setfield(L, -2, "BUTTON_X"); lua_pushnumber(L, BUTTON_Y); lua_setfield(L, -2, "BUTTON_Y"); lua_pushnumber(L, BUTTON_B); lua_setfield(L, -2, "BUTTON_B"); lua_pop(L, 1); Controller *c = new Controller(L); g_pushInstance(L, "Controller", c->object()); luaL_rawgetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_pushvalue(L, -2); luaL_rawsetptr(L, -2, c); lua_pop(L, 1); lua_pushvalue(L, -1); lua_setglobal(L, "controller"); return 1; }
int main() { Controller controller; controller.InitializeGame(); return 0; }
void createCommonConfiguration ( Controller & c ) { c.addCountry( "France" ); c.addLeader( "Philip IV", "King", 1268, 1314 ); c.addLeader( "Louis X", "King", 1289, 1316 ); c.addLeader( "Philip V", "King", 1291, 1322 ); c.addLeader( "Charles IV", "King", 1294, 1328 ); c.addHistoryPeriod( "France", 1285, 1313, "Philip IV", 3000000 ); c.addHistoryPeriod( "France", 1314, 1315, "Louis X", 3100000 ); c.addHistoryPeriod( "France", 1316, 1321, "Philip V", 3200000 ); c.addHistoryPeriod( "France", 1322, 1328, "Charles IV", 3300000 ); c.addCountry( "England" ); c.addLeader( "Edward I", "King", 1239, 1307 ); c.addLeader( "Edward II", "King", 1284, 1327 ); c.addLeader( "Edward III", "King", 1312, 1377 ); c.addHistoryPeriod( "England", 1272, 1306, "Edward I", 2400000 ); c.addHistoryPeriod( "England", 1307, 1326, "Edward II", 2450000 ); c.addHistoryPeriod( "England", 1327, 1377, "Edward III", 3000000 ); c.addCountry( "Germany" ); c.addLeader( "Gerhard Schroder", "Chancellor", 1944, alive ); c.addLeader( "Angela Merkel", "Chancellor", 1954, alive ); c.addHistoryPeriod( "Germany", 1998, 2004, "Gerhard Schroder", 50000000 ); c.addHistoryPeriod( "Germany", 2005, 2015, "Angela Merkel", 52000000 ); c.addLeader( "Idi Amin", "President", 1928, 2003 ); }
void AppListener::onFrame(const Controller& controller) { // Get the most recent frame and report some basic information const Frame frame = controller.frame(); ::Sleep(1); const HandList& hands = frame.hands(); const FingerList& fingers = frame.fingers(); const ToolList& tools = frame.tools(); const GestureList& gestures = frame.gestures(); if (hands.empty() && fingers.empty() && tools.empty() && gestures.empty()) return; #if 0 std::cout << "Frame id: " << frame.id() << ", timestamp: " << frame.timestamp() << " hands: " << hands.count() << " fingers: " << fingers.count() << " tools: " << tools.count() << " gestures: " << gestures.count() << std::endl; #endif ofxOscBundle bundle; ofxOscMessage alive; { alive.setAddress("/tuio/2Dcur"); alive.addStringArg("alive"); } ofxOscMessage fseq; { fseq.setAddress( "/tuio/2Dcur" ); fseq.addStringArg( "fseq" ); fseq.addIntArg(frame.id()); } if (!hands.empty()) { // Get the first hand const Hand& hand = hands[0]; // Check if the hand has any fingers const FingerList& fingers = hand.fingers(); if (!fingers.empty()) { for (int i = 0; i < fingers.count(); ++i) { const Vector& tipPos = fingers[i].tipPosition(); const Vector& tipVel = fingers[i].tipVelocity(); { #ifdef INIT_BBOX // max/min bbox bboxMax.x = std::max<float>(bboxMax.x, tipPos.x); bboxMax.y = std::max<float>(bboxMax.y, tipPos.y); bboxMax.z = std::max<float>(bboxMax.z, tipPos.z); bboxMin.x = std::min<float>(bboxMin.x, tipPos.x); bboxMin.y = std::min<float>(bboxMin.y, tipPos.y); bboxMin.z = std::min<float>(bboxMin.z, tipPos.z); #endif Vector tuioPos; tuioPos.x = normalize(tipPos.x, bboxMin.x, bboxMax.x); tuioPos.y = normalize(tipPos.y, bboxMax.y, bboxMin.y); tuioPos.z = normalize(tipPos.z, bboxMin.z, bboxMax.z); // tuio { ofxOscMessage m; m.setAddress( "/tuio/2Dcur" ); m.addStringArg("set"); m.addIntArg(fingers[i].id()); // id m.addFloatArg(tuioPos.x); // x m.addFloatArg(tuioPos.y); // y // TOTO m.addFloatArg(tipVel.x / 400); // dX m.addFloatArg(tipVel.y / 400); // dY m.addFloatArg(0); // maccel bundle.addMessage(m); alive.addIntArg(fingers[i].id()); // add blob to list of ALL active IDs } } } #ifdef INIT_BBOX std::cout << "min: " << bboxMin << std::endl; std::cout << "max: " << bboxMax << std::endl; #endif } #if 0 // Get the hand's sphere radius and palm position std::cout << "Hand sphere radius: " << hand.sphereRadius() << " mm, palm position: " << hand.palmPosition() << std::endl; #endif // Get the hand's normal vector and direction const Vector normal = hand.palmNormal(); const Vector direction = hand.direction(); #if 0 // Calculate the hand's pitch, roll, and yaw angles std::cout << "Hand pitch: " << direction.pitch() * RAD_TO_DEG << " degrees, " << "roll: " << normal.roll() * RAD_TO_DEG << " degrees, " << "yaw: " << direction.yaw() * RAD_TO_DEG << " degrees" << std::endl; #endif } bundle.addMessage(alive); bundle.addMessage(fseq); tuioSender.sendBundle(bundle); // Get gestures for (int g = 0; g < gestures.count(); ++g) { Gesture gesture = gestures[g]; switch (gesture.type()) { case Gesture::TYPE_CIRCLE: { CircleGesture circle = gesture; std::string clockwiseness; if (circle.pointable().direction().angleTo(circle.normal()) <= PI/4) { clockwiseness = "clockwise"; } else { clockwiseness = "counterclockwise"; } // Calculate angle swept since last frame float sweptAngle = 0; if (circle.state() != Gesture::STATE_START) { CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id())); sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI; } std::cout << "Circle id: " << gesture.id() << ", state: " << gesture.state() << ", progress: " << circle.progress() << ", radius: " << circle.radius() << ", angle " << sweptAngle * RAD_TO_DEG << ", " << clockwiseness << std::endl; break; } case Gesture::TYPE_SWIPE: { SwipeGesture swipe = gesture; std::cout << "Swipe id: " << gesture.id() << ", state: " << gesture.state() << ", direction: " << swipe.direction() << ", speed: " << swipe.speed() << std::endl; break; } case Gesture::TYPE_KEY_TAP: { KeyTapGesture tap = gesture; std::cout << "Key Tap id: " << gesture.id() << ", state: " << gesture.state() << ", position: " << tap.position() << ", direction: " << tap.direction()<< std::endl; break; } case Gesture::TYPE_SCREEN_TAP: { ScreenTapGesture screentap = gesture; std::cout << "Screen Tap id: " << gesture.id() << ", state: " << gesture.state() << ", position: " << screentap.position() << ", direction: " << screentap.direction()<< std::endl; break; } default: std::cout << "Unknown gesture type." << std::endl; break; } } #if 0 if (!hands.empty() || !gestures.empty()) { std::cout << std::endl; } #endif }
void SampleListener::onFrame(const Controller& controller) { //tictoc_stack.push(clock()); // Get the most recent frame and report some basic information const Frame frame = controller.frame(); HandList hands = frame.hands(); for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) { // Get the first hand const Hand hand = *hl; std::string handType = hand.isLeft() ? "Left hand" : "Right hand"; const Vector normal = hand.palmNormal(); const Vector direction = hand.direction(); // Get the Arm bone Arm arm = hand.arm(); // Get fingers const FingerList fingers = hand.fingers(); for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) { const Finger finger = *fl; myfile << std::string(4, ' ') << fingerNames[finger.type()] << ": " << hand.palmPosition().distanceTo(finger.tipPosition()); // Get finger bones for (int b = 0; b < 4; ++b) { Bone::Type boneType = static_cast<Bone::Type>(b); Bone bone = finger.bone(boneType); } } } // Get tools const ToolList tools = frame.tools(); for (ToolList::const_iterator tl = tools.begin(); tl != tools.end(); ++tl) { const Tool tool = *tl; } // Get gestures const GestureList gestures = frame.gestures(); for (int g = 0; g < gestures.count(); ++g) { Gesture gesture = gestures[g]; switch (gesture.type()) { case Gesture::TYPE_CIRCLE: { CircleGesture circle = gesture; std::string clockwiseness; if (circle.pointable().direction().angleTo(circle.normal()) <= PI / 2) { clockwiseness = "clockwise"; } else { clockwiseness = "counterclockwise"; } // Calculate angle swept since last frame float sweptAngle = 0; if (circle.state() != Gesture::STATE_START) { CircleGesture previousUpdate = CircleGesture(controller.frame(1).gesture(circle.id())); sweptAngle = (circle.progress() - previousUpdate.progress()) * 2 * PI; } break; } case Gesture::TYPE_SWIPE: { SwipeGesture swipe = gesture; break; } case Gesture::TYPE_KEY_TAP: { KeyTapGesture tap = gesture; break; } case Gesture::TYPE_SCREEN_TAP: { ScreenTapGesture screentap = gesture; break; } default: break; } } if (!frame.hands().isEmpty() || !gestures.isEmpty()) { std::cout << std::endl; } myfile << " Time elapsed: " << ((double)(clock() - tictoc_stack.top())) / CLOCKS_PER_SEC; tictoc_stack.pop(); myfile << endl; }
void LeapListener::onFocusGained(const Controller &controller){ m_lastFrame = controller.frame(); }
int main(int argc, char** argv) { struct sockaddr_in si_other; int s, slen = sizeof(si_other); char buf[BUFLEN]; char message[BUFLEN]; WSADATA wsa; //Initialise winsock printf("\nInitialising Winsock..."); if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) { printf("Failed. Error Code : %d", WSAGetLastError()); exit(EXIT_FAILURE); } printf("Initialised.\n"); //create socket //if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == SOCKET_ERROR) if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) { printf("socket() failed with error code : %d", WSAGetLastError()); exit(EXIT_FAILURE); } char str[INET_ADDRSTRLEN]; //setup address structure memset((char *)&si_other, 0, sizeof(si_other)); si_other.sin_family = AF_INET; si_other.sin_port = htons(PORT); //si_other.sin_addr.S_un.S_addr = inet_pton(AF_INET, SERVER, &(si_other.sin_addr)); inet_pton(AF_INET, SERVER, &(si_other.sin_addr.S_un.S_addr)); /*if (inet_pton(AF_INET, SERVER, &(si_other.sin_addr.S_un.S_addr))) { inet_ntop(AF_INET, &(si_other.sin_addr.S_un.S_addr), str, INET_ADDRSTRLEN); std::cout << ("%s\n", str); }*/ // We catch any exceptions that might occur below -- see the catch statement for more details. try { // First, we create a Hub with our application identifier. Be sure not to use the com.example namespace when // publishing your application. The Hub provides access to one or more Myos. myo::Hub hub("om.example.emg-data-sample"); std::cout << "Attempting to find a Myo..." << std::endl; // Next, we attempt to find a Myo to use. If a Myo is already paired in Myo Connect, this will return that Myo // immediately. // waitForMyo() takes a timeout value in milliseconds. In this case we will try to find a Myo for 10 seconds, and // if that fails, the function will return a null pointer. myo::Myo* myo = hub.waitForMyo(10000); // If waitForMyo() returned a null pointer, we failed to find a Myo, so exit with an error message. if (!myo) { throw std::runtime_error("Unable to find a Myo!"); } // We've found a Myo. std::cout << "Connected to a Myo armband!" << std::endl << std::endl; // Next we enable EMG streaming on the found Myo. myo->setStreamEmg(myo::Myo::streamEmgEnabled); // Create a sample listener and controller for Leap Motion SampleListener listener; Controller controller; // Next we construct an instance of our DeviceListener, so that we can register it with the Hub. DataCollector collector; double timeElasped = 0.000; const double minMax[10] = { 32, 85, 36, 100, 37, 107, 36, 100, 36, 90 }; //T.I.M.R.P // Hub::addListener() takes the address of any object whose class inherits from DeviceListener, and will cause // Hub::run() to send events to all registered device listeners. hub.addListener(&collector); //controller.addListener(listener); if (argc > 1 && strcmp(argv[1], "--bg") == 0) controller.setPolicy(Leap::Controller::POLICY_BACKGROUND_FRAMES); myfile << std::fixed; myfile << std::setprecision(2); // Finally we enter our main loop. while (1) { //collector.tic(); // In each iteration of our main loop, we run the Myo event loop for a set number of milliseconds. // In this case, we wish to update our display 50 times a second, so we run for 1000/20 milliseconds. hub.run(1000 / 100); // After processing events, we call the print() member function we defined above to print out the values we've // obtained from any events that have occurred. collector.print(); int i = 0; int j = 1; int h = 0; double fingDis[5]; const Frame frame = controller.frame(); HandList hands = frame.hands(); for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) { // Get the first hand const Hand hand = *hl; // Get fingers const FingerList fingers = hand.fingers(); for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) { const Finger finger = *fl; //myfile << " " << hand.palmPosition().distanceTo(finger.tipPosition()); /*myfile << std::string(4, ' ') << fingerNames[finger.type()] << ": " << listener.mapping(hand.palmPosition().distanceTo(finger.tipPosition()), minMax[i + i], minMax[i + j]);*/ fingDis[h] = listener.mapping(hand.palmPosition().distanceTo(finger.tipPosition()), minMax[i + i], minMax[i + j]); //fingDis[h] = hand.palmPosition().distanceTo(finger.tipPosition()); i++; j++; h++; if (i == 5 && j == 6 && h == 5) { string tmp = to_string(fingDis[0]) + " " + to_string(fingDis[1]) + " " + to_string(fingDis[2]) + " " + to_string(fingDis[3]) + " " + to_string(fingDis[4]); //string tmp = to_string('0'); strcpy_s(message, tmp.c_str()); //send message if (sendto(s, message, strlen(message), 0, (struct sockaddr *) &si_other, slen) == SOCKET_ERROR) { printf("sendto() failed with error code : %d", WSAGetLastError()); //exit(EXIT_FAILURE); } std::cout << "Data Sent"; i = 0; j = 1; h = 0; } } } //timeElasped = timeElasped + ((double)(clock() - tictoc_stack.top())) / CLOCKS_PER_SEC; /*myfile << " Time elapsed: " << ((double)(clock() - tictoc_stack.top())) / CLOCKS_PER_SEC;*/ //tictoc_stack.pop(); //myfile << " " << timeElasped << endl; } // If a standard exception occurred, we print out its message and exit. } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; std::cerr << "Press enter to continue."; std::cin.ignore(); return 1; } closesocket(s); WSACleanup(); }
void tick_move_slider_helper( void *obj ) { Controller *me = static_cast<Controller *>( obj ); ahabassert( me ); me->tick_move_slider(); }
inline void update() { controller.update(); }