示例#1
0
dtStatus dtNavMesh::setPolyFlags(dtPolyRef ref, unsigned short flags)
{
	if (!ref) return DT_FAILURE;
	unsigned int salt, it, ip;
	decodePolyId(ref, salt, it, ip);
	if (it >= (unsigned int)m_maxTiles) return DT_FAILURE | DT_INVALID_PARAM;
	if (m_tiles[it].salt != salt || m_tiles[it].header == 0) return DT_FAILURE | DT_INVALID_PARAM;
	dtMeshTile* tile = &m_tiles[it];
	if (ip >= (unsigned int)tile->header->polyCount) return DT_FAILURE | DT_INVALID_PARAM;
	dtPoly* poly = &tile->polys[ip];
	
	// Change flags.
	poly->flags = flags;
	
	return DT_SUCCESS;
}
dtStatus dtNavMesh::setPolyTeamCost( dtPolyRef ref, dtTeam team, float cost )
{
	if ( !ref ) return DT_FAILURE;
	unsigned int salt, it, ip;
	decodePolyId( ref, salt, it, ip );
	if ( it >= (unsigned int)m_maxTiles ) return DT_FAILURE | DT_INVALID_PARAM;
	if ( m_tiles[ it ].salt != salt || m_tiles[ it ].header == 0 ) return DT_FAILURE | DT_INVALID_PARAM;
	dtMeshTile* tile = &m_tiles[ it ];
	if ( ip >= (unsigned int)tile->header->polyCount ) return DT_FAILURE | DT_INVALID_PARAM;
	dtPoly* poly = &tile->polys[ ip ];

	// Change flags.
	poly->teamCost[ team ] = cost;

	return DT_SUCCESS;
}
示例#3
0
// Returns start and end location of an off-mesh link polygon.
dtStatus dtNavMesh::getOffMeshConnectionPolyEndPoints(dtPolyRef prevRef, dtPolyRef polyRef, float* startPos, float* endPos) const
{
    unsigned int salt, it, ip;

    if (!polyRef)
         return DT_FAILURE;

    // Get current polygon
    decodePolyId(polyRef, salt, it, ip);
    if (it >= (unsigned int)m_maxTiles)
        return DT_FAILURE | DT_INVALID_PARAM;

    if (m_tiles[it].salt != salt || m_tiles[it].header == 0)
        return DT_FAILURE | DT_INVALID_PARAM;

    const dtMeshTile* tile = &m_tiles[it];
    if (ip >= (unsigned int)tile->header->polyCount)
        return DT_FAILURE | DT_INVALID_PARAM;

    // Make sure that the current poly is indeed off-mesh link.
    const dtPoly* poly = &tile->polys[ip];
    if (poly->getType() != DT_POLYTYPE_OFFMESH_CONNECTION)
        return DT_FAILURE;

    // Figure out which way to hand out the vertices.
    int idx0 = 0, idx1 = 1;

    // Find link that points to first vertex.
    for (unsigned int i = poly->firstLink; i != DT_NULL_LINK; i = tile->links[i].next)
    {
        if (tile->links[i].edge == 0)
        {
            if (tile->links[i].ref != prevRef)
            {
                idx0 = 1;
                idx1 = 0;
            }
            break;
        }
    }

    dtVcopy(startPos, &tile->verts[poly->verts[idx0]*3]);
    dtVcopy(endPos,   &tile->verts[poly->verts[idx1]*3]);

    return DT_SUCCESS;
}
示例#4
0
bool dtNavMesh::isValidPolyRef(dtPolyRef ref) const
{
    if (!ref)
        return false;

    unsigned int salt, it, ip;
    decodePolyId(ref, salt, it, ip);
    if (it >= (unsigned int)m_maxTiles)
        return false;

    if (m_tiles[it].salt != salt || m_tiles[it].header == 0)
        return false;

    if (ip >= (unsigned int)m_tiles[it].header->polyCount)
        return false;

    return true;
}
示例#5
0
const dtOffMeshConnection* dtNavMesh::getOffMeshConnectionByRef(dtPolyRef ref) const
{
	unsigned int salt, it, ip;
	
	// Get current polygon
	decodePolyId(ref, salt, it, ip);
	if (it >= (unsigned int)m_maxTiles) return 0;
	if (m_tiles[it].salt != salt || m_tiles[it].header == 0) return 0;
	const dtMeshTile* tile = &m_tiles[it];
	if (ip >= (unsigned int)tile->header->polyCount) return 0;
	const dtPoly* poly = &tile->polys[ip];
	
	// Make sure that the current poly is indeed off-mesh link.
	if (poly->getType() != DT_POLYTYPE_OFFMESH_CONNECTION)
		return 0;

	const unsigned int idx =  ip - tile->header->offMeshBase;
	dtAssert(idx < (unsigned int)tile->header->offMeshConCount);
	return &tile->offMeshCons[idx];
}
示例#6
0
dtStatus dtNavMesh::getTileAndPolyByRef(const dtPolyRef ref, const dtMeshTile** tile, const dtPoly** poly) const
{
    if (!ref)
        return DT_FAILURE;

    unsigned int salt, it, ip;
    decodePolyId(ref, salt, it, ip);
    if (it >= (unsigned int)m_maxTiles)
        return DT_FAILURE | DT_INVALID_PARAM;

    if (m_tiles[it].salt != salt || m_tiles[it].header == 0)
        return DT_FAILURE | DT_INVALID_PARAM;

    if (ip >= (unsigned int)m_tiles[it].header->polyCount)
        return DT_FAILURE | DT_INVALID_PARAM;

    *tile = &m_tiles[it];
    *poly = &m_tiles[it].polys[ip];

    return DT_SUCCESS;
}
示例#7
0
dtStatus dtNavMesh::getPolyArea(dtPolyRef ref, unsigned char* resultArea) const
{
    if (!ref)
        return DT_FAILURE;

    unsigned int salt, it, ip;
    decodePolyId(ref, salt, it, ip);
    if (it >= (unsigned int)m_maxTiles)
        return DT_FAILURE | DT_INVALID_PARAM;

    if (m_tiles[it].salt != salt || m_tiles[it].header == 0)
        return DT_FAILURE | DT_INVALID_PARAM;

    const dtMeshTile* tile = &m_tiles[it];
    if (ip >= (unsigned int)tile->header->polyCount)
        return DT_FAILURE | DT_INVALID_PARAM;

    const dtPoly* poly = &tile->polys[ip];
    *resultArea = poly->getArea();

    return DT_SUCCESS;
}