public bool IsLeafVisible( BspNode from, BspNode to )
{
if ( to.VisCluster == -1 )
return false;
if ( from.VisCluster == -1 )
// Camera outside world?
return true;
if ( !from.IsLeaf || !to.IsLeaf )
throw new AxiomException( "Both nodes must be leaf nodes for visibility testing." );
// Use PVS to determine visibility
/*
// In wordier terms, the fairly cryptic (but fast) version is doing this:
// Could make it a macro for even more speed?
// Row offset = from cluster number * row size
int offset = from->mVisCluster*mVisData.rowLength;
// Column offset (in bytes) = to cluster number divided by 8 (since 8 bits per bytes)
offset += to->mVisCluster >> 3;
// Get the right bit within the byte, i.e. bitwise 'and' with bit at remainder position
int result = *(mVisData.tableData + offset) & (1 << (to->mVisCluster & 7));
return (result != 0);
*/
byte visSet = visData.tableData[ ( from.VisCluster * visData.rowLength ) + ( to.VisCluster >> 3 ) ];
int result = visSet & ( 1 << ( ( to.VisCluster ) & 7 ) );
return ( result != 0 );
}