dtStatus getEdgeMidPoint(dtPolyRef from, dtPoly fromPoly, dtMeshTile fromTile, dtPolyRef to, dtPoly toPoly, dtMeshTile toTile, float[] mid) { float[] left = new float[3];//, right[3]; float[] right = new float[3]; if (dtStatusFailed(getPortalPoints(from, fromPoly, fromTile, to, toPoly, toTile, left, right))) return DT_FAILURE | DT_INVALID_PARAM; mid[0] = (left[0]+right[0])*0.5f; mid[1] = (left[1]+right[1])*0.5f; mid[2] = (left[2]+right[2])*0.5f; return DT_SUCCESS; }
public void getTileAndPolyByRefUnsafe(dtPolyRef polyRef, ref dtMeshTile tile, ref dtPoly poly, ref uint ip) { uint salt = 0, it = 0; decodePolyId(polyRef,ref salt,ref it,ref ip); tile = m_tiles[it]; poly = m_tiles[it].polys[ip]; }
// Returns portal points between two polygons. dtStatus getPortalPoints(dtPolyRef from, dtPoly fromPoly, dtMeshTile fromTile, dtPolyRef to, dtPoly toPoly, dtMeshTile toTile, float[] left, float[] right) { // Find the link that points to the 'to' polygon. dtLink link = null; for (uint i = fromPoly.firstLink; i != DT_NULL_LINK; i = fromTile.links[i].next) { if (fromTile.links[i].polyRef == to) { link = fromTile.links[i]; break; } } if (link == null) return DT_FAILURE | DT_INVALID_PARAM; // Handle off-mesh connections. if (fromPoly.getType() == (byte) dtPolyTypes.DT_POLYTYPE_OFFMESH_CONNECTION) { // Find link that points to first vertex. for (uint i = fromPoly.firstLink; i != DT_NULL_LINK; i = fromTile.links[i].next) { if (fromTile.links[i].polyRef == to) { int v = fromTile.links[i].edge; dtVcopy(left, 0, fromTile.verts,fromPoly.verts[v]*3); dtVcopy(right, 0, fromTile.verts,fromPoly.verts[v]*3); return DT_SUCCESS; } } return DT_FAILURE | DT_INVALID_PARAM; } if (toPoly.getType() == (byte) dtPolyTypes.DT_POLYTYPE_OFFMESH_CONNECTION) { for (uint i = toPoly.firstLink; i != DT_NULL_LINK; i = toTile.links[i].next) { if (toTile.links[i].polyRef == from) { int v = toTile.links[i].edge; dtVcopy(left, 0, toTile.verts, toPoly.verts[v]*3); dtVcopy(right, 0, toTile.verts, toPoly.verts[v]*3); return DT_SUCCESS; } } return DT_FAILURE | DT_INVALID_PARAM; } // Find portal vertices. int v0 = fromPoly.verts[link.edge]; int v1 = fromPoly.verts[(link.edge+1) % (int)fromPoly.vertCount]; dtVcopy(left, 0, fromTile.verts,v0*3); dtVcopy(right, 0, fromTile.verts,v1*3); // If the link is at tile boundary, dtClamp the vertices to // the link width. if (link.side != 0xff) { // Unpack portal limits. if (link.bmin != 0 || link.bmax != 255) { float s = 1.0f/255.0f; float tmin = link.bmin*s; float tmax = link.bmax*s; dtVlerp(left, 0, fromTile.verts, v0*3, fromTile.verts, v1*3, tmin); dtVlerp(right, 0, fromTile.verts, v0*3, fromTile.verts, v1*3, tmax); } } return DT_SUCCESS; }
//C# port : also return ip because the code used to do pointer arithmetics on the // array's addresses, which is a no in C# because managed array may not be contiguous in memory public dtStatus getTileAndPolyByRef(dtPolyRef polyRef, ref dtMeshTile tile, ref dtPoly poly, ref uint ip) { if (polyRef == 0) return DT_FAILURE; uint salt = 0, it = 0; decodePolyId(polyRef, ref salt, ref it, ref ip); if (it >= (uint)m_maxTiles) return DT_FAILURE | DT_INVALID_PARAM; if (m_tiles[it].salt != salt || m_tiles[it].header == null) return DT_FAILURE | DT_INVALID_PARAM; if (ip >= (uint)m_tiles[it].header.polyCount) return DT_FAILURE | DT_INVALID_PARAM; tile = m_tiles[it]; poly = m_tiles[it].polys[ip]; return DT_SUCCESS; }