1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 14:37:44 +00:00

path things

This commit is contained in:
goaaats 2019-01-21 02:42:47 +01:00
parent 087cf6dd00
commit ee662ba15d
2 changed files with 91 additions and 72 deletions

View file

@ -153,6 +153,11 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
// reached destination // reached destination
return true; return true;
auto path = m_pCurrentZone->GetNaviProvider()->PathFindFollow( m_pos, pos );
//face( path[0] );
/*
float rot = Util::calcAngFrom( getPos().x, getPos().z, pos.x, pos.z ); float rot = Util::calcAngFrom( getPos().x, getPos().z, pos.x, pos.z );
float newRot = PI - rot + ( PI / 2 ); float newRot = PI - rot + ( PI / 2 );
@ -171,6 +176,7 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
setRot( newRot ); setRot( newRot );
sendPositionUpdate(); sendPositionUpdate();
*/
return false; return false;
} }

View file

@ -20,9 +20,9 @@ Sapphire::NaviProvider::NaviProvider( Sapphire::ZonePtr pZone, Sapphire::Framewo
m_naviMeshQuery( nullptr ) m_naviMeshQuery( nullptr )
{ {
// Set defaults // Set defaults
m_polyFindRange[0] = 2; m_polyFindRange[0] = 10;
m_polyFindRange[1] = 4; m_polyFindRange[1] = 20;
m_polyFindRange[2] = 2; m_polyFindRange[2] = 10;
} }
void Sapphire::NaviProvider::init() void Sapphire::NaviProvider::init()
@ -34,9 +34,11 @@ void Sapphire::NaviProvider::init()
{ {
auto baseMesh = meshFolder / std::filesystem::path( m_pZone->getInternalName() + ".nav" ); auto baseMesh = meshFolder / std::filesystem::path( m_pZone->getInternalName() + ".nav" );
//m_naviMesh = LoadMesh( baseMesh.string() ); LoadMesh( baseMesh.string() );
// Load all meshes for testing // Load all meshes for testing
/*
for( const auto & entry : std::filesystem::directory_iterator( meshFolder ) ) for( const auto & entry : std::filesystem::directory_iterator( meshFolder ) )
{ {
if( entry.path().extension().string() == ".nav" ) if( entry.path().extension().string() == ".nav" )
@ -45,6 +47,7 @@ void Sapphire::NaviProvider::init()
LoadMesh( entry.path().string() ); LoadMesh( entry.path().string() );
} }
} }
*/
InitQuery(); InitQuery();
} }
@ -221,10 +224,11 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::Path
dtPolyRef startRef, endRef = 0; dtPolyRef startRef, endRef = 0;
float start[3] = { startPos.x, startPos.y, startPos.z }; float start[3] = { startPos.x, startPos.y, startPos.z };
float end[3] = { startPos.x, startPos.y, startPos.z }; float end[3] = { endPos.x, endPos.y, endPos.z };
dtQueryFilter filter; dtQueryFilter filter;
filter.setAreaCost( 0, 0 ); filter.setIncludeFlags(0xffff);
filter.setExcludeFlags(0);
m_naviMeshQuery->findNearestPoly( start, m_polyFindRange, &filter, &startRef, 0 ); m_naviMeshQuery->findNearestPoly( start, m_polyFindRange, &filter, &startRef, 0 );
m_naviMeshQuery->findNearestPoly( end, m_polyFindRange, &filter, &endRef, 0 ); m_naviMeshQuery->findNearestPoly( end, m_polyFindRange, &filter, &endRef, 0 );
@ -262,6 +266,8 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::Path
dtVcopy( &smoothPath[numSmoothPath * 3], iterPos ); dtVcopy( &smoothPath[numSmoothPath * 3], iterPos );
numSmoothPath++; numSmoothPath++;
auto resultCoords = std::vector< Common::FFXIVARR_POSITION3 >();
// Move towards target a small advancement at a time until target reached or // Move towards target a small advancement at a time until target reached or
// when ran out of memory to store the path. // when ran out of memory to store the path.
while( npolys && numSmoothPath < MAX_SMOOTH ) while( npolys && numSmoothPath < MAX_SMOOTH )
@ -365,6 +371,13 @@ std::vector< Sapphire::Common::FFXIVARR_POSITION3 > Sapphire::NaviProvider::Path
numSmoothPath++; numSmoothPath++;
} }
} }
for( int i = 0; i < numSmoothPath; i += 3 )
{
resultCoords.push_back( Common::FFXIVARR_POSITION3{ smoothPath[i], smoothPath[i + 2], smoothPath[i + 3] } );
}
return resultCoords;
} }
else else
{ {