Esempio n. 1
0
void CQuake3BSP::RenderLevel(const CVector3 &vPos)
{
    // Reset our bitset so all the slots are zero.
    m_FacesDrawn.ClearAll();

    // Grab the leaf index that our camera is in
    int leafIndex = FindLeaf(vPos);

    // Grab the cluster that is assigned to the leaf
    int cluster = m_pLeafs[leafIndex].cluster;

    // Initialize our counter variables (start at the last leaf and work down)
    int i = m_numOfLeafs;
    g_VisibleFaces = 0;

    // Go through all the leafs and check their visibility
    while(i--)
    {
        // Get the current leaf that is to be tested for visibility from our camera's leaf
        tBSPLeaf *pLeaf = &(m_pLeafs[i]);

        // If the current leaf can't be seen from our cluster, go to the next leaf
        if(!IsClusterVisible(cluster, pLeaf->cluster))
            continue;

        // If the current leaf is not in the camera's frustum, go to the next leaf
        if(!g_Frustum.BoxInFrustum((float)pLeaf->min.x, (float)pLeaf->min.y, (float)pLeaf->min.z,
                                   (float)pLeaf->max.x, (float)pLeaf->max.y, (float)pLeaf->max.z))
            continue;

        // If we get here, the leaf we are testing must be visible in our camera's view.
        // Get the number of faces that this leaf is in charge of.
        int faceCount = pLeaf->numOfLeafFaces;

        // Loop through and render all of the faces in this leaf
        while(faceCount--)
        {
            // Grab the current face index from our leaf faces array
            int faceIndex = m_pLeafFaces[pLeaf->leafface + faceCount];

            // Before drawing this face, make sure it's a normal polygon
            if(m_pFaces[faceIndex].type != FACE_POLYGON) continue;

            // Since many faces are duplicated in other leafs, we need to
            // make sure this face already hasn't been drawn.
            if(!m_FacesDrawn.On(faceIndex))
            {
                // Increase the rendered face count to display for fun
                g_VisibleFaces++;

                // Set this face as drawn and render it
                m_FacesDrawn.Set(faceIndex);
                RenderFace(faceIndex);
            }
        }
    }
}
Esempio n. 2
0
void CQuake3BSP::RenderLevel(const CVector3 &vPos)
{
	// Reset our bitset so all the slots are zero.
	m_FacesDrawn.ClearAll();


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	// In this new revision of RenderLevel(), we do things a bit differently.
	// Instead of looping through all the faces, we now want to loop through
	// all of the leafs.  Each leaf stores a list of faces assign to it.
	// We call FindLeaf() to find the current leaf index that our camera is
	// in.  This leaf will then give us the cluster that the camera is in.  The
	// cluster is then used to test visibility between our current cluster
	// and other leaf clusters.  If another leaf's cluster is visible from our 
	// current cluster, the leaf's bounding box is checked against our frustum.  
	// Assuming the bounding box is inside of our frustum, we draw all the faces
	// stored in that leaf.  

	// Grab the leaf index that our camera is in
	int leafIndex = FindLeaf(vPos);

	// Grab the cluster that is assigned to the leaf
	int cluster = m_pLeafs[leafIndex].cluster;

	// Initialize our counter variables (start at the last leaf and work down)
	int i = m_numOfLeafs;
	g_VisibleFaces = 0;

	// Go through all the leafs and check their visibility
	while(i--)
	{
		// Get the current leaf that is to be tested for visibility from our camera's leaf
		tBSPLeaf *pLeaf = &(m_pLeafs[i]);

		// If the current leaf can't be seen from our cluster, go to the next leaf
		if(!IsClusterVisible(cluster, pLeaf->cluster)) 
			continue;

		// If the current leaf is not in the camera's frustum, go to the next leaf
		if(!g_Frustum.BoxInFrustum((float)pLeaf->min.x, (float)pLeaf->min.y, (float)pLeaf->min.z,
		  	 				       (float)pLeaf->max.x, (float)pLeaf->max.y, (float)pLeaf->max.z))
			continue;
		
		// If we get here, the leaf we are testing must be visible in our camera's view.
		// Get the number of faces that this leaf is in charge of.
		int faceCount = pLeaf->numOfLeafFaces;

		// Loop through and render all of the faces in this leaf
		while(faceCount--)
		{
			// Grab the current face index from our leaf faces array
			int faceIndex = m_pLeafFaces[pLeaf->leafface + faceCount];

			// Before drawing this face, make sure it's a normal polygon
			if(m_pFaces[faceIndex].type != FACE_POLYGON) continue;

			// Since many faces are duplicated in other leafs, we need to
			// make sure this face already hasn't been drawn.
			if(!m_FacesDrawn.On(faceIndex)) 
			{
				// Increase the rendered face count to display for fun
				g_VisibleFaces++;

				// Set this face as drawn and render it
				m_FacesDrawn.Set(faceIndex);
				RenderFace(faceIndex);
			}
		}			
	}

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

}