Axiom.SceneManagers.Bsp.BspLevel.IsLeafVisible C# (CSharp) Method

IsLeafVisible() public method

Determines if one leaf node is visible from another.
public IsLeafVisible ( Axiom.SceneManagers.Bsp.BspNode from, Axiom.SceneManagers.Bsp.BspNode to ) : bool
from Axiom.SceneManagers.Bsp.BspNode
to Axiom.SceneManagers.Bsp.BspNode
return bool
		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 );
		}

Usage Example

 /// <summary>
 ///		Determines if the passed in node (must also be a leaf) is visible from this leaf.
 ///	</summary>
 ///	<remarks>
 ///		Must only be called on a leaf node, and the parameter must also be a leaf node. If
 ///		this method returns true, then the leaf passed in is visible from this leaf.
 ///		Note that internally this uses the Potentially Visible Set (PVS) which is precalculated
 ///		and stored with the BSP level.
 ///	</remarks>
 public bool IsLeafVisible(BspNode leaf)
 {
     return(owner.IsLeafVisible(this, leaf));
 }