資源簡介
該算法可躲避多個移動的物體,進(jìn)行路徑規(guī)劃,由北卡的教授編寫,此代碼至可讀,可以為需要的朋友借鑒。

代碼片段和文件信息
#ifndef?_WIN32_WINNT????//?Allow?use?of?features?specific?to?Windows?XP?or?later.
#define?_WIN32_WINNT?0x0501??//?Change?this?to?the?appropriate?value?to?target?other?versions?of?Windows.
#endif
#include?
#include?
#ifdef?_MSC_VER
#include?
#else
#define?_TCHAR?char
#define?_tmain?main
#endif
#include?“RVOSimulator.h“
void?setupScenario(?RVO::RVOSimulator?*?sim?)?{
??//?Specify?global?time?step?of?the?simulation
??sim->setTimeStep(?0.25f?);
??//?Specify?default?parameters?for?agents?that?are?subsequently?added
??sim->setAgentDefaults(?250?15.0f?10?2.0f?3.0f?1.0f?2.0f?7.5f?1.0f?);
??//?Add?agents?(and?simulataneously?their?goals)?specifying?their?start?position?and?goal?ID
??sim->addAgent(?RVO::Vector2(-50.0f?-50.0f)?sim->addGoal(?RVO::Vector2(50.0f?50.0f)?)?);
??sim->addAgent(?RVO::Vector2(50.0f?-50.0f)?sim->addGoal(?RVO::Vector2(-50.0f?50.0f)?)?);
??sim->addAgent(?RVO::Vector2(50.0f?50.0f)?sim->addGoal(?RVO::Vector2(-50.0f?-50.0f)?)?);
??sim->addAgent(?RVO::Vector2(-50.0f?50.0f)?sim->addGoal(?RVO::Vector2(50.0f?-50.0f)?)?);
??//?Add?(line?segment)?obstacles?specifying?both?endpoints?of?the?line?segments
??sim->addObstacle(?RVO::Vector2(-7.0f?-20.0f)?RVO::Vector2(-7.0f?20.0f)?);
??sim->addObstacle(?RVO::Vector2(-7.0f?20.0f)?RVO::Vector2(7.0f?20.0f)?);
??sim->addObstacle(?RVO::Vector2(7.0f?20.0f)?RVO::Vector2(7.0f?-20.0f)?);
??sim->addObstacle(?RVO::Vector2(7.0f?-20.0f)?RVO::Vector2(-7.0f?-20.0f)?);
??//?Add?roadmap?vertices?specifying?their?position
??sim->addRoadmapVertex(?RVO::Vector2(-10.0f?-23.0f)?);
??sim->addRoadmapVertex(?RVO::Vector2(-10.0f?23.0f)?);
??sim->addRoadmapVertex(?RVO::Vector2(10.0f?23.0f)?);
??sim->addRoadmapVertex(?RVO::Vector2(10.0f?-23.0f)?);
??//?Do?not?automatically?create?edges?between?mutually?visible?roadmap?vertices
??sim->setRoadmapAutomatic(?-1?);
??//?Manually?specify?edges?between?vertices?specifying?the?ID‘s?of?the?vertices?the?edges?connect
??sim->addRoadmapEdge(?0?1?);
??sim->addRoadmapEdge(?1?2?);
??sim->addRoadmapEdge(?2?3?);
??sim->addRoadmapEdge(?3?0?);
}
void?updateVisualization(?RVO::RVOSimulator?*?sim?)?{
??//?Output?the?current?global?time
??std::cout?<getGlobalTime()?<“?“;
??//?Output?the?position?and?orientation?for?all?the?agents
??for?(int?i?=?0;?i?getNumAgents();?++i)?{
????std::cout?<getAgentPosition(?i?)?<“?“?<getAgentOrientation(?i?)?<“?“;
??}
??std::cout?<}
int?_tmain(int?argc?_TCHAR*?argv[])
{
??//?Create?a?simulator?instance
??RVO::RVOSimulator?*?sim?=?RVO::RVOSimulator::Instance();
??//?Set?up?the?scenario
??setupScenario(?sim?);
??//?Initialize?the?simulation
??sim->initSimulation();
??//?Perform?(and?manipulate)?the?simulation
??do?{
????updateVisualization(?sim?);
????sim->doStep();
??}?while?(?!sim->getReachedGoal()?);
??delete?sim;
??return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-05-08?23:50??RVO\
?????文件?????????117??2013-02-08?01:03??RVO\AUTHORS
?????文件????????2039??2014-05-08?23:48??RVO\COPYING
?????文件??????????81??2009-02-14?20:52??RVO\Makefile.am
?????文件???????23068??2013-02-08?01:34??RVO\Makefile.in
?????文件??????????64??2013-02-08?01:26??RVO\README
?????目錄???????????0??2013-02-08?01:34??RVO\RVOLIB\
?????文件???????11146??2009-02-14?20:52??RVO\RVOLIB\Agent.cpp
?????文件????????5695??2009-02-14?20:52??RVO\RVOLIB\Agent.h
?????文件????????1724??2009-02-14?20:52??RVO\RVOLIB\Goal.cpp
?????文件?????????831??2009-01-26?19:44??RVO\RVOLIB\Goal.h
?????文件???????11734??2009-02-14?20:52??RVO\RVOLIB\KDTree.cpp
?????文件????????1881??2009-02-14?20:52??RVO\RVOLIB\KDTree.h
?????文件?????????614??2009-02-14?20:52??RVO\RVOLIB\Makefile.am
?????文件???????19181??2013-02-08?01:34??RVO\RVOLIB\Makefile.in
?????文件?????????255??2009-01-26?19:44??RVO\RVOLIB\Obstacle.cpp
?????文件?????????869??2009-02-14?20:52??RVO\RVOLIB\Obstacle.h
?????文件????????4208??2009-02-14?20:52??RVO\RVOLIB\RVODef.h
?????文件????????1083??2009-01-26?19:44??RVO\RVOLIB\RVOLIB.sln
?????文件????????6772??2009-02-14?20:52??RVO\RVOLIB\RVOLIB.vcproj
?????文件???????11805??2009-02-14?20:52??RVO\RVOLIB\RVOSimulator.cpp
?????文件???????38946??2009-02-14?20:52??RVO\RVOLIB\RVOSimulator.h
?????文件?????????818??2009-02-14?20:52??RVO\RVOLIB\RoadmapVertex.cpp
?????文件????????1456??2009-02-14?20:52??RVO\RVOLIB\RoadmapVertex.h
?????文件????????5796??2009-02-14?20:53??RVO\RVOLIB\vector2.h
?????文件???????38531??2013-02-08?01:33??RVO\aclocal.m4
?????目錄???????????0??2013-02-08?01:34??RVO\build-aux\
?????文件????????5826??2013-02-08?01:34??RVO\build-aux\ar-lib
?????文件???????23491??2013-02-08?01:34??RVO\build-aux\depcomp
?????文件???????13997??2013-02-08?01:34??RVO\build-aux\install-sh
?????文件????????6873??2013-02-08?01:34??RVO\build-aux\missing
............此處省略41個文件信息
評論
共有 條評論