void PlayerCamera::update(float deltaTime) { //move player camera vec3f dirFront(sin(rot.y*DEG_TO_RAD)*cos(rot.x*DEG_TO_RAD), -sin(rot.x*DEG_TO_RAD), -cos(rot.y*DEG_TO_RAD)*cos(rot.x*DEG_TO_RAD)); vec3f dirRight(-cos(rot.y*DEG_TO_RAD), 0, -sin(rot.y*DEG_TO_RAD)); float vel = 10.0f; if(Input::isKeyDown(sf::Keyboard::S)) pos -= dirFront*deltaTime*vel; if(Input::isKeyDown(sf::Keyboard::W)) pos += dirFront*deltaTime*vel; if(Input::isKeyDown(sf::Keyboard::D)) pos -= dirRight*deltaTime*vel; if(Input::isKeyDown(sf::Keyboard::A)) pos += dirRight*deltaTime*vel; if(Input::getMouseDisplacement() != vec2i(0,0)) rot += vec3f(Input::getMouseDisplacement().y*0.1f,Input::getMouseDisplacement().x*0.1f,0); //center mouse Input::setMousePos(SCRWIDTH/2,SCRHEIGHT/2,getGame()->getWindow()); Camera::update(deltaTime); }
int main(int argc, char * argv[]) { if(argc < 2) { showUsage(); } bool inv = false; for(int i=1; i<argc-1; ++i) { if(strcmp(argv[i], "-inv") == 0) { inv = true; printf(" Inversing option activated...\n"); continue; } if(argc > 3) { showUsage(); printf(" Not recognized option: \"%s\"\n", argv[i]); } } std::string path, pathRight; if(argc == 3 && !inv) { //two paths path = argv[1]; pathRight = argv[2]; printf(" Path left = %s\n", path.c_str()); printf(" Path right = %s\n", pathRight.c_str()); } else { path = argv[argc-1]; printf(" Path = %s\n", path.c_str()); } UDirectory dir(path, "jpg bmp png tiff jpeg"); UDirectory dirRight(pathRight, "jpg bmp png tiff jpeg"); if(!dir.isValid() || (!pathRight.empty() && !dirRight.isValid())) { printf("Path invalid!\n"); exit(-1); } std::string targetDirectory = path+"_joined"; UDirectory::makeDir(targetDirectory); printf(" Creating directory \"%s\"\n", targetDirectory.c_str()); std::string fileNameA = dir.getNextFilePath(); std::string fileNameB; if(dirRight.isValid()) { fileNameB = dirRight.getNextFilePath(); } else { fileNameB = dir.getNextFilePath(); } int i=1; while(!fileNameA.empty() && !fileNameB.empty()) { if(inv) { std::string tmp = fileNameA; fileNameA = fileNameB; fileNameB = tmp; } std::string ext = UFile::getExtension(fileNameA); std::string targetFilePath = targetDirectory+UDirectory::separator()+uNumber2Str(i++)+"."+ext; cv::Mat imageA = cv::imread(fileNameA.c_str()); cv::Mat imageB = cv::imread(fileNameB.c_str()); fileNameA.clear(); fileNameB.clear(); if(!imageA.empty() && !imageB.empty()) { cv::Size sizeA = imageA.size(); cv::Size sizeB = imageB.size(); cv::Size targetSize(0,0); targetSize.width = sizeA.width + sizeB.width; targetSize.height = sizeA.height > sizeB.height ? sizeA.height : sizeB.height; cv::Mat targetImage(targetSize, imageA.type()); cv::Mat roiA(targetImage, cv::Rect( 0, 0, sizeA.width, sizeA.height )); imageA.copyTo(roiA); cv::Mat roiB( targetImage, cvRect( sizeA.width, 0, sizeB.width, sizeB.height ) ); imageB.copyTo(roiB); if(!cv::imwrite(targetFilePath.c_str(), targetImage)) { printf("Error : saving to \"%s\" goes wrong...\n", targetFilePath.c_str()); } else { printf("Saved \"%s\" \n", targetFilePath.c_str()); } fileNameA = dir.getNextFilePath(); if(dirRight.isValid()) { fileNameB = dirRight.getNextFilePath(); } else { fileNameB = dir.getNextFilePath(); } } else { printf("Error: loading images failed!\n"); } } printf("%d files processed\n", i-1); return 0; }
void FunnelPlanner::computeCrossing( float radius, const Vector2 & startPos, PortalPath * path, size_t startPortal ) { assert( path->getPortalCount() > 0 && "Funnel planner should only be applied to PortalPaths with at least one portal" ); FunnelApex apex( startPortal - 1, startPos ); // if startPortal is zero, this should go to all 1s...i.e. -1 > all other size_t values const WayPortal * portal = path->getPortal( startPortal ); Vector2 pLeft( portal->getLeft( radius ) ); Vector2 pRight( portal->getRight( radius ) ); Vector2 dirLeft( pLeft - apex._pos ); Vector2 dirRight( pRight - apex._pos ); #ifdef SIMPLE_FUNNEL FunnelEdge funnelLeft( startPortal, dirLeft ); FunnelEdge funnelRight( startPortal, dirRight ); size_t currPortal = startPortal + 1; const size_t PORTAL_COUNT = path->getPortalCount(); while ( currPortal < PORTAL_COUNT ) { portal = path->getPortal( currPortal ); pLeft.set( portal->getLeft( radius ) ); pRight.set( portal->getRight( radius ) ); dirLeft.set( pLeft - apex._pos ); dirRight.set( pRight - apex._pos ); // test left side of the funnel if ( funnelRight.isOnRight( dirLeft ) ) { // the portal's funnel is on the right of the current funnel Vector2 oldApex = apex._pos; Vector2 newApex = funnelRight._dir + apex._pos; //if ( apex._id != -1 && apex._id < currPortal ) { path->setWaypoints( apex._id + 1, funnelRight._id + 1, newApex, norm( funnelRight._dir ) ); //} apex.set( funnelRight._id, newApex ); currPortal = funnelRight._id + 1; portal = path->getPortal( currPortal ); pLeft.set( portal->getLeft( radius ) ); pRight.set( portal->getRight( radius ) ); dirLeft.set( pLeft - apex._pos ); dirRight.set( pRight - apex._pos ); funnelLeft.set( currPortal, dirLeft ); funnelRight.set( currPortal, dirRight ); ++currPortal; continue; } else if ( funnelLeft.isOnRight( dirLeft ) ) { funnelLeft.set( currPortal, dirLeft ); } // test right side of the funnel if ( funnelLeft.isOnLeft( dirRight ) ) { // the portal's funnel is on the left of the current funnel Vector2 oldApex = apex._pos; Vector2 newApex = funnelLeft._dir + apex._pos; //if ( apex._id != -1 && apex._id < currPortal ) { path->setWaypoints( apex._id + 1, funnelLeft._id + 1, newApex, norm( funnelLeft._dir ) ); //} apex.set( funnelLeft._id, newApex ); currPortal = funnelLeft._id + 1; portal = path->getPortal( currPortal ); pLeft.set( portal->getLeft( radius ) ); pRight.set( portal->getRight( radius ) ); dirLeft.set( pLeft - apex._pos ); dirRight.set( pRight - apex._pos ); funnelLeft.set( currPortal, dirLeft ); funnelRight.set( currPortal, dirRight ); ++currPortal; continue; } else if ( funnelRight.isOnLeft( dirRight ) ) { funnelRight.set( currPortal, dirRight ); } ++currPortal; } // Now handle goal const Vector2 goalPt = path->getGoalCentroid(); Vector2 goalDir( goalPt - apex._pos ); if ( funnelLeft.isOnLeft( goalDir ) ) { // The goal point is on the left side of the funnel if ( apex._id != -1 && apex._id < PORTAL_COUNT ) { path->setWaypoints( apex._id + 1, PORTAL_COUNT, apex._pos + funnelLeft._dir, norm( funnelLeft._dir ) ); } } else if ( funnelRight.isOnRight( goalDir ) ) { // The goal point is on the right side of the funnel if ( apex._id != -1 && apex._id < PORTAL_COUNT ) { path->setWaypoints( apex._id + 1, PORTAL_COUNT, apex._pos + funnelRight._dir, norm( funnelRight._dir ) ); } } if ( apex._id + 1 < PORTAL_COUNT ) { path->setWaypoints( (size_t)apex._id + 1, (size_t)PORTAL_COUNT, goalPt, norm( goalPt - apex._pos ) ); } #else _left.push_back( FunnelEdge( startPortal - 1, startPortal, dirLeft, startPos ) ); _right.push_back( FunnelEdge( startPortal - 1, startPortal, dirRight, startPos ) ); const size_t PORTAL_COUNT = path->getPortalCount(); for ( size_t i = startPortal + 1; i < PORTAL_COUNT; ++i ) { portal = path->getPortal( i ); // investigate the left point pLeft.set( portal->getLeft( radius ) ); bool apexMoved = false; while ( !_right.empty() ) { std::list< FunnelEdge >::iterator itr = _right.begin(); Vector2 dir = pLeft - itr->_origin; if ( itr->isOnRight( dir ) ) { apexMoved = true; Vector2 newApex = itr->_origin + itr->_dir; path->setWaypoints( itr->_id + 1, itr->_endID + 1, newApex, norm( itr->_dir ) ); apex.set( itr->_endID, newApex ); _right.pop_front(); } else { break; } } if ( apexMoved ) { _left.clear(); _left.push_back( FunnelEdge( apex._id, i, pLeft - apex._pos, apex._pos ) ); } else { std::list< FunnelEdge >::reverse_iterator itr = _left.rbegin(); while ( ! _left.empty() ) { Vector2 dir = pLeft - itr->_origin; if ( itr->isOnRight( dir ) ) { _left.pop_back(); itr = _left.rbegin(); } else { break; } } if ( _left.empty() ) { _left.push_back( FunnelEdge( apex._id, i, pLeft - apex._pos, apex._pos ) ); } else { Vector2 origin( itr->_origin + itr->_dir ); _left.push_back( FunnelEdge( itr->_endID, i, pLeft - origin, origin ) ); } } // investigate the right point pRight.set( portal->getRight( radius ) ); apexMoved = false; while ( !_left.empty() ) { std::list< FunnelEdge >::iterator itr = _left.begin(); Vector2 dir = pRight - itr->_origin; if ( itr->isOnLeft( dir ) ) { apexMoved = true; Vector2 newApex = itr->_origin + itr->_dir; path->setWaypoints( itr->_id + 1, itr->_endID + 1, newApex, norm( itr->_dir ) ); apex.set( itr->_endID, newApex ); _left.pop_front(); } else { break; } } if ( apexMoved ) { _right.clear(); _right.push_back( FunnelEdge( apex._id, i, pRight - apex._pos, apex._pos ) ); } else { std::list< FunnelEdge >::reverse_iterator itr = _right.rbegin(); while ( ! _right.empty() ) { Vector2 dir = pRight - itr->_origin; if ( itr->isOnLeft( dir ) ) { _right.pop_back(); itr = _right.rbegin(); } else { break; } } if ( _right.empty() ) { _right.push_back( FunnelEdge( apex._id, i, pRight - apex._pos, apex._pos ) ); } else { Vector2 origin( itr->_origin + itr->_dir ); _right.push_back( FunnelEdge( itr->_endID, i, pRight - origin, origin ) ); } } } // handle the goal const Vector2 goalPt = path->getGoalCentroid(); Vector2 goalDir; bool apexMoved = false; while ( !_left.empty() ) { std::list< FunnelEdge >::iterator itr = _left.begin(); goalDir.set( goalPt - itr->_origin ); if ( itr->isOnLeft( goalDir ) ) { apexMoved = true; Vector2 newApex = itr->_origin + itr->_dir; apex.set( itr->_endID, newApex ); path->setWaypoints( itr->_id + 1, itr->_endID + 1, newApex, norm( itr->_dir ) ); _left.pop_front(); } else { break; } } if ( apexMoved ) { goalDir.set( goalPt - apex._pos ); path->setWaypoints( apex._id + 1, PORTAL_COUNT, goalPt, norm( goalDir ) ); } else { // apexMoved is already false -- it is the only way to reach this branch while ( !_right.empty() ) { std::list< FunnelEdge >::iterator itr = _right.begin(); goalDir.set( goalPt - itr->_origin ); if ( itr->isOnRight( goalDir ) ) { apexMoved = true; Vector2 newApex = itr->_origin + itr->_dir; apex.set( itr->_endID, newApex ); path->setWaypoints( itr->_id + 1, itr->_endID + 1, newApex, norm( itr->_dir ) ); _right.pop_front(); } else { break; } } goalDir.set( goalPt - apex._pos ); path->setWaypoints( apex._id + 1, PORTAL_COUNT, goalPt, norm( goalDir ) ); } #endif // SIMPLE_FUNNEL }