本文整理汇总了C++中dtVdist2DSqr函数的典型用法代码示例。如果您正苦于以下问题:C++ dtVdist2DSqr函数的具体用法?C++ dtVdist2DSqr怎么用?C++ dtVdist2DSqr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dtVdist2DSqr函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: dtVdist2DSqr
dtPolyRef PathFinder::getPathPolyByPosition(const dtPolyRef* polyPath, uint32 polyPathSize, const float* point, float* distance) const
{
if (!polyPath || !polyPathSize)
{ return INVALID_POLYREF; }
dtPolyRef nearestPoly = INVALID_POLYREF;
float minDist2d = FLT_MAX;
float minDist3d = 0.0f;
for (uint32 i = 0; i < polyPathSize; ++i)
{
float closestPoint[VERTEX_SIZE];
if (dtStatusFailed(m_navMeshQuery->closestPointOnPoly(polyPath[i], point, closestPoint)))
continue;
float d = dtVdist2DSqr(point, closestPoint);
if (d < minDist2d)
{
minDist2d = d;
nearestPoly = polyPath[i];
minDist3d = dtVdistSqr(point, closestPoint);
}
if (minDist2d < 1.0f) // shortcut out - close enough for us
{ break; }
}
if (distance)
{ *distance = dtSqrt(minDist3d); }
return (minDist2d < 3.0f) ? nearestPoly : INVALID_POLYREF;
}
开发者ID:EdwardTuring,项目名称:MangosZero,代码行数:32,代码来源:PathFinder.cpp
示例2: MANGOS_ASSERT
dtPolyRef PathInfo::getPathPolyByPosition(dtPolyRef *polyPath, uint32 polyPathSize, const float* point, float *distance)
{
if (!polyPath || !polyPathSize)
return INVALID_POLYREF;
dtPolyRef nearestPoly = INVALID_POLYREF;
float minDist2d = FLT_MAX;
float minDist3d = 0.0f;
for (uint32 i = 0; i < polyPathSize; ++i)
{
MANGOS_ASSERT(polyPath[i] != INVALID_POLYREF);
float closestPoint[VERTEX_SIZE];
if (DT_SUCCESS != m_navMeshQuery->closestPointOnPoly(polyPath[i], point, closestPoint))
continue;
float d = dtVdist2DSqr(point, closestPoint);
if (d < minDist2d)
{
minDist2d = d;
nearestPoly = m_pathPolyRefs[i];
minDist3d = dtVdistSqr(point, closestPoint);
}
if(minDist2d < 1.0f) // shortcut out - close enough for us
break;
}
if (distance)
*distance = dtSqrt(minDist3d);
return (minDist2d < 4.0f) ? nearestPoly : INVALID_POLYREF;
}
开发者ID:Elarose,项目名称:MaNGOSZero,代码行数:34,代码来源:PathFinder.cpp
示例3: dtVdist2DSqr
dtPolyRef PathGenerator::GetPathPolyByPosition(dtPolyRef const* polyPath, uint32 polyPathSize, float const* point, float* distance) const
{
if (!polyPath || !polyPathSize)
return INVALID_POLYREF;
dtPolyRef nearestPoly = INVALID_POLYREF;
float minDist2d = FLT_MAX;
float minDist3d = 0.0f;
for (uint32 i = 0; i < polyPathSize; ++i)
{
float closestPoint[VERTEX_SIZE];
if (dtStatusFailed(_navMeshQuery->closestPointOnPoly(polyPath[i], point, closestPoint, NULL)))
continue;
float d = dtVdist2DSqr(point, closestPoint);
if (d < minDist2d)
{
minDist2d = d;
nearestPoly = polyPath[i];
minDist3d = dtVdistSqr(point, closestPoint);
}
if (minDist2d < 1.0f) // shortcut out - close enough for us
break;
}
if (distance)
*distance = dtMathSqrtf(minDist3d);
return (minDist2d < 3.0f) ? nearestPoly : INVALID_POLYREF;
}
开发者ID:Jildor,项目名称:TrinityCore,代码行数:32,代码来源:PathGenerator.cpp
示例4: overOffmeshConnection
static bool overOffmeshConnection(const dtCrowdAgent* ag, const float radius)
{
if (!ag->ncorners)
return false;
const bool offMeshConnection = (ag->cornerFlags[ag->ncorners-1] & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ? true : false;
if (offMeshConnection)
{
const float distSq = dtVdist2DSqr(ag->npos, &ag->cornerVerts[(ag->ncorners-1)*3]);
if (distSq < radius*radius)
return true;
}
return false;
}
开发者ID:Craz3dBanana,项目名称:recastnavigation,代码行数:15,代码来源:DetourCrowd.cpp
示例5: withinRadiusOfOffMeshConnection
static bool withinRadiusOfOffMeshConnection( const Bot_t *bot, rVec pos, rVec off, dtPolyRef conPoly )
{
const dtOffMeshConnection *con = bot->nav->mesh->getOffMeshConnectionByRef( conPoly );
if ( !con )
{
return false;
}
if ( dtVdist2DSqr( pos, off ) < con->rad * con->rad )
{
return true;
}
return false;
}
开发者ID:BlueMustache,项目名称:Unvanquished,代码行数:15,代码来源:bot_nav.cpp
示例6: updateEnvironment
void dtCrowd::updateEnvironment(unsigned* agentsIdx, unsigned nbIdx)
{
// If we want to update every agent
if (agentsIdx == 0)
{
agentsIdx = m_agentsToUpdate;
nbIdx = m_maxAgents;
}
nbIdx = (nbIdx < m_maxAgents) ? nbIdx : m_maxAgents;
// Get nearby navmesh segments and agents to collide with.
for (unsigned i = 0; i < nbIdx; ++i)
{
dtCrowdAgent* ag = 0;
if (!getActiveAgent(&ag, agentsIdx[i]))
continue;
if (ag->state != DT_CROWDAGENT_STATE_WALKING)
continue;
if (ag->state == DT_CROWDAGENT_STATE_INVALID)
m_agentsEnv[ag->id].boundary.reset();
// Update the collision boundary after certain distance has been passed or
// if it has become invalid.
const float updateThr = ag->perceptionDistance * 0.25f;
if (dtVdist2DSqr(ag->position, m_agentsEnv[ag->id].boundary.getCenter()) > dtSqr(updateThr) ||
!m_agentsEnv[ag->id].boundary.isValid(m_crowdQuery->getNavMeshQuery(), m_crowdQuery->getQueryFilter()))
{
dtPolyRef ref;
float nearest[3];
m_crowdQuery->getNavMeshQuery()->findNearestPoly(ag->position, m_crowdQuery->getQueryExtents(), m_crowdQuery->getQueryFilter(), &ref, nearest);
m_agentsEnv[ag->id].boundary.update(ref, ag->position, ag->perceptionDistance,
m_crowdQuery->getNavMeshQuery(), m_crowdQuery->getQueryFilter());
}
// Query neighbour agents
m_agentsEnv[ag->id].nbNeighbors = this->computeNeighbors(ag->id);
for (unsigned j = 0; j < m_agentsEnv[ag->id].nbNeighbors; j++)
m_agentsEnv[ag->id].neighbors[j].idx = getAgentIndex(&m_agents[m_agentsEnv[ag->id].neighbors[j].idx]);
}
}
开发者ID:MrMagne,项目名称:recastdetour,代码行数:45,代码来源:DetourCrowd.cpp
示例7: dtVdist2DSqr
dtPolyRef PathFinder::getPathPolyByPosition(const dtPolyRef *polyPath, uint32 polyPathSize, const float* point, float *distance) const
{
if (!polyPath || !polyPathSize)
return INVALID_POLYREF;
dtPolyRef nearestPoly = INVALID_POLYREF;
float minDist2d = FLT_MAX;
float minDist3d = 0.0f;
for (uint32 i = 0; i < polyPathSize; ++i)
{
// skip DT_POLYTYPE_OFFMESH_CONNECTION they aren't handled in closestPointOnPoly
const dtMeshTile* tile = 0;
const dtPoly* poly = 0;
if (m_navMesh->getTileAndPolyByRef(polyPath[i], &tile, &poly) != DT_SUCCESS)
continue;
if (poly->getType() == DT_POLYTYPE_OFFMESH_CONNECTION)
continue;
float closestPoint[VERTEX_SIZE];
if (DT_SUCCESS != m_navMeshQuery->closestPointOnPoly(polyPath[i], point, closestPoint))
continue;
float d = dtVdist2DSqr(point, closestPoint);
if (d < minDist2d)
{
minDist2d = d;
nearestPoly = m_pathPolyRefs[i];
minDist3d = dtVdistSqr(point, closestPoint);
}
if(minDist2d < 1.0f) // shortcut out - close enough for us
break;
}
if (distance)
*distance = dtSqrt(minDist3d);
return (minDist2d < 3.0f) ? nearestPoly : INVALID_POLYREF;
}
开发者ID:Bootz,项目名称:StrawberryCore,代码行数:41,代码来源:PathFinder.cpp
示例8: be
/**
@par
This is the function used to plan local movement within the corridor. One or more corners can be
detected in order to plan movement. It performs essentially the same function as #dtNavMeshQuery::findStraightPath.
Due to internal optimizations, the maximum number of corners returned will be (@p maxCorners - 1)
For example: If the buffers are sized to hold 10 corners, the function will never return more than 9 corners.
So if 10 corners are needed, the buffers should be sized for 11 corners.
If the target is within range, it will be the last corner and have a polygon reference id of zero.
*/
int dtPathCorridor::findCorners(float* cornerVerts, unsigned char* cornerFlags,
dtPolyRef* cornerPolys, const int maxCorners,
dtNavMeshQuery* navquery, const dtQueryFilter* /*filter*/,
int options )
{
dtAssert(m_path);
dtAssert(m_npath);
static const float MIN_TARGET_DIST = 0.01f;
int ncorners = 0;
navquery->findStraightPath(m_pos, m_target, m_path, m_npath,
cornerVerts, cornerFlags, cornerPolys, &ncorners, maxCorners, options);
// Prune points in the beginning of the path which are too close.
while (ncorners)
{
if ((cornerFlags[0] & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ||
dtVdist2DSqr(&cornerVerts[0], m_pos) > dtSqr(MIN_TARGET_DIST))
break;
ncorners--;
if (ncorners)
{
memmove(cornerFlags, cornerFlags+1, sizeof(unsigned char)*ncorners);
memmove(cornerPolys, cornerPolys+1, sizeof(dtPolyRef)*ncorners);
memmove(cornerVerts, cornerVerts+3, sizeof(float)*3*ncorners);
}
}
// Prune points after an off-mesh connection.
/*for (int i = 0; i < ncorners; ++i)
{
if (cornerFlags[i] & DT_STRAIGHTPATH_OFFMESH_CONNECTION)
{
ncorners = i+1;
break;
}
}*/
return ncorners;
}
开发者ID:jswigart,项目名称:recastnavigation,代码行数:53,代码来源:DetourPathCorridor.cpp
示例9: getActiveAgents
void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
{
m_velocitySampleCount = 0;
const int debugIdx = debug ? debug->idx : -1;
dtCrowdAgent** agents = m_activeAgents;
int nagents = getActiveAgents(agents, m_maxAgents);
// Check that all agents still have valid paths.
checkPathValidity(agents, nagents, dt);
// Update async move request and path finder.
updateMoveRequest(dt);
// Optimize path topology.
updateTopologyOptimization(agents, nagents, dt);
// Register agents to proximity grid.
m_grid->clear();
for (int i = 0; i < nagents; ++i)
{
dtCrowdAgent* ag = agents[i];
const float* p = ag->npos;
const float r = ag->params.radius;
m_grid->addItem((unsigned short)i, p[0]-r, p[2]-r, p[0]+r, p[2]+r);
}
// Get nearby navmesh segments and agents to collide with.
for (int i = 0; i < nagents; ++i)
{
dtCrowdAgent* ag = agents[i];
if (ag->state != DT_CROWDAGENT_STATE_WALKING)
continue;
// Update the collision boundary after certain distance has been passed or
// if it has become invalid.
const float updateThr = ag->params.collisionQueryRange*0.25f;
if (dtVdist2DSqr(ag->npos, ag->boundary.getCenter()) > dtSqr(updateThr) ||
!ag->boundary.isValid(m_navquery, &m_filter))
{
ag->boundary.update(ag->corridor.getFirstPoly(), ag->npos, ag->params.collisionQueryRange,
m_navquery, &m_filter);
}
// Query neighbour agents
ag->nneis = getNeighbours(ag->npos, ag->params.height, ag->params.collisionQueryRange,
ag, ag->neis, DT_CROWDAGENT_MAX_NEIGHBOURS,
agents, nagents, m_grid);
for (int j = 0; j < ag->nneis; j++)
ag->neis[j].idx = getAgentIndex(agents[ag->neis[j].idx]);
}
// Find next corner to steer to.
for (int i = 0; i < nagents; ++i)
{
dtCrowdAgent* ag = agents[i];
if (ag->state != DT_CROWDAGENT_STATE_WALKING)
continue;
if (ag->targetState == DT_CROWDAGENT_TARGET_NONE || ag->targetState == DT_CROWDAGENT_TARGET_VELOCITY)
continue;
// Find corners for steering
ag->ncorners = ag->corridor.findCorners(ag->cornerVerts, ag->cornerFlags, ag->cornerPolys,
DT_CROWDAGENT_MAX_CORNERS, m_navquery, &m_filter);
// Check to see if the corner after the next corner is directly visible,
// and short cut to there.
if ((ag->params.updateFlags & DT_CROWD_OPTIMIZE_VIS) && ag->ncorners > 0)
{
const float* target = &ag->cornerVerts[dtMin(1,ag->ncorners-1)*3];
ag->corridor.optimizePathVisibility(target, ag->params.pathOptimizationRange, m_navquery, &m_filter);
// Copy data for debug purposes.
if (debugIdx == i)
{
dtVcopy(debug->optStart, ag->corridor.getPos());
dtVcopy(debug->optEnd, target);
}
}
else
{
// Copy data for debug purposes.
if (debugIdx == i)
{
dtVset(debug->optStart, 0,0,0);
dtVset(debug->optEnd, 0,0,0);
}
}
}
// Trigger off-mesh connections (depends on corners).
for (int i = 0; i < nagents; ++i)
{
dtCrowdAgent* ag = agents[i];
if (ag->state != DT_CROWDAGENT_STATE_WALKING)
continue;
if (ag->targetState == DT_CROWDAGENT_TARGET_NONE || ag->targetState == DT_CROWDAGENT_TARGET_VELOCITY)
continue;
//.........这里部分代码省略.........
开发者ID:Craz3dBanana,项目名称:recastnavigation,代码行数:101,代码来源:DetourCrowd.cpp
示例10: updateStepProximityData
void dtCrowd::updateStepProximityData(const float dt, dtCrowdAgentDebugInfo*)
{
// Register agents to proximity grid.
m_grid->clear();
for (int i = 0; i < m_numActiveAgents; ++i)
{
dtCrowdAgent* ag = m_activeAgents[i];
const float* p = ag->npos;
const float r = ag->params.radius;
m_grid->addItem((unsigned short)i, p[0] - r, p[2] - r, p[0] + r, p[2] + r);
}
// Get nearby navmesh segments and agents to collide with.
for (int i = 0; i < m_numActiveAgents; ++i)
{
dtCrowdAgent* ag = m_activeAgents[i];
if (ag->state != DT_CROWDAGENT_STATE_WALKING)
continue;
m_navquery->updateLinkFilter(ag->params.linkFilter);
// Update the collision boundary after certain distance has been passed or
// if it has become invalid.
const float updateThr = ag->params.collisionQueryRange*0.25f;
if (dtVdist2DSqr(ag->npos, ag->boundary.getCenter()) > dtSqr(updateThr) ||
!ag->boundary.isValid(m_navquery, &m_filters[ag->params.filter]))
{
// UE4: force removing segments too close to offmesh links
const bool useForcedRemove = m_linkRemovalRadius > 0.0f && ag->ncorners &&
(ag->cornerFlags[ag->ncorners - 1] & DT_STRAIGHTPATH_OFFMESH_CONNECTION);
const float* removePos = useForcedRemove ? &ag->cornerVerts[(ag->ncorners - 1) * 3] : 0;
const float removeRadius = m_linkRemovalRadius;
// UE4: prepare filter containing only current area
// boundary update will take all corner polys and include them in local neighborhood
unsigned char allowedArea = DT_WALKABLE_AREA;
if (m_raycastSingleArea)
{
m_navquery->getAttachedNavMesh()->getPolyArea(ag->corridor.getFirstPoly(), &allowedArea);
m_raycastFilter.setAreaCost(allowedArea, 1.0f);
}
// UE4: move dir for segment scoring
float moveDir[3] = { 0.0f };
if (ag->ncorners)
{
dtVsub(moveDir, &ag->cornerVerts[2], &ag->cornerVerts[0]);
}
else
{
dtVcopy(moveDir, ag->vel);
}
dtVnormalize(moveDir);
ag->boundary.update(ag->corridor.getFirstPoly(), ag->npos, ag->params.collisionQueryRange,
removePos, removeRadius, useForcedRemove,
ag->corridor.getPath(), ag->corridor.getPathCount(),
moveDir,
m_navquery, m_raycastSingleArea ? &m_raycastFilter : &m_filters[ag->params.filter]);
m_raycastFilter.setAreaCost(allowedArea, DT_UNWALKABLE_POLY_COST);
}
// Query neighbour agents
ag->nneis = getNeighbours(ag->npos, ag->params.height, ag->params.collisionQueryRange,
ag, ag->neis, DT_CROWDAGENT_MAX_NEIGHBOURS,
m_activeAgents, m_numActiveAgents, m_grid);
for (int j = 0; j < ag->nneis; j++)
ag->neis[j].idx = getAgentIndex(m_activeAgents[ag->neis[j].idx]);
}
}
开发者ID:1vanK,项目名称:AHRUnrealEngine,代码行数:71,代码来源:DetourCrowd.cpp
示例11: be
/**
@par
This is the function used to plan local movement within the corridor. One or more corners can be
detected in order to plan movement. It performs essentially the same function as #dtNavMeshQuery::findStraightPath.
Due to internal optimizations, the maximum number of corners returned will be (@p maxCorners - 1)
For example: If the buffers are sized to hold 10 corners, the function will never return more than 9 corners.
So if 10 corners are needed, the buffers should be sized for 11 corners.
If the target is within range, it will be the last corner and have a polygon reference id of zero.
*/
int dtPathCorridor::findCorners(float* cornerVerts, unsigned char* cornerFlags,
dtPolyRef* cornerPolys, const int maxCorners,
dtNavMeshQuery* navquery, const dtQueryFilter* filter,
float radius)
{
dtAssert(m_path);
dtAssert(m_npath);
static const float MIN_TARGET_DIST = 0.01f;
dtQueryResult result;
navquery->findStraightPath(m_pos, m_target, m_path, m_npath, result);
int ncorners = dtMin(result.size(), maxCorners);
result.copyRefs(cornerPolys, maxCorners);
result.copyFlags(cornerFlags, maxCorners);
result.copyPos(cornerVerts, maxCorners);
// Prune points in the beginning of the path which are too close.
while (ncorners)
{
if ((cornerFlags[0] & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ||
dtVdist2DSqr(&cornerVerts[0], m_pos) > dtSqr(MIN_TARGET_DIST))
break;
ncorners--;
if (ncorners)
{
memmove(cornerFlags, cornerFlags+1, sizeof(unsigned char)*ncorners);
memmove(cornerPolys, cornerPolys+1, sizeof(dtPolyRef)*ncorners);
memmove(cornerVerts, cornerVerts+3, sizeof(float)*3*ncorners);
}
}
// Prune points after an off-mesh connection.
for (int i = 0; i < ncorners; ++i)
{
if (cornerFlags[i] & DT_STRAIGHTPATH_OFFMESH_CONNECTION)
{
ncorners = i+1;
break;
}
}
// [UE4] Offset path points from corners
const dtNavMesh* nav = navquery->getAttachedNavMesh();
float v1[3], v2[3], dir[3];
for (int i = 0; i < ncorners - 1; i++)
{
int fromIdx = 0;
while (m_path[fromIdx] != cornerPolys[i] && fromIdx < m_npath)
{
fromIdx++;
}
if (m_path[fromIdx] != cornerPolys[i] || fromIdx == 0)
continue;
const dtMeshTile* tile0 = 0;
const dtMeshTile* tile1 = 0;
const dtPoly* poly0 = 0;
const dtPoly* poly1 = 0;
nav->getTileAndPolyByRefUnsafe(m_path[fromIdx - 1], &tile0, &poly0);
nav->getTileAndPolyByRefUnsafe(m_path[fromIdx], &tile1, &poly1);
if (tile0 != tile1)
continue;
float* corner = &cornerVerts[i * 3];
unsigned char dummyT1, dummyT2;
navquery->getPortalPoints(m_path[fromIdx - 1], m_path[fromIdx], v1, v2, dummyT1, dummyT2);
const float edgeLen = dtVdist(v1, v2);
if (edgeLen > 0.001f)
{
const float edgeOffset = dtMin(radius, edgeLen * 0.75f) / edgeLen;
if (dtVequal(corner, v1))
{
dtVsub(dir, v2, v1);
dtVmad(corner, corner, dir, edgeOffset);
}
else
{
dtVsub(dir, v1, v2);
dtVmad(corner, corner, dir, edgeOffset);
//.........这里部分代码省略.........
开发者ID:johndpope,项目名称:UE4,代码行数:101,代码来源:DetourPathCorridor.cpp
注:本文中的dtVdist2DSqr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论