Example #1
0
//Calculate which faces to draw given a position & frustum
void BSP::CalculateVisibleFaces(const VECTOR3D & cameraPosition, FRUSTUM frustum)
{
	//Clear the list of faces drawn
	facesToDraw.ClearAll();
	
	//calculate the camera leaf
	int cameraLeaf=CalculateCameraLeaf(cameraPosition);
	int cameraCluster=leaves[cameraLeaf].cluster;

	//loop through the leaves
	for(int i=0; i<numLeaves; ++i)
	{
		//if the leaf is not in the PVS, continue
		if(!isClusterVisible(cameraCluster, leaves[i].cluster))
			continue;

		//if this leaf does not lie in the frustum, continue
		if(!frustum.IsBoundingBoxInside(leaves[i].boundingBoxVertices))
			continue;

		//loop through faces in this leaf and mark them to be drawn
		for(int j=0; j<leaves[i].numFaces; ++j)
		{
			facesToDraw.Set(leafFaces[leaves[i].firstLeafFace+j]);
		}
	}


}
Example #2
0
//Calculate which faces to draw given a position & frustum
void BSP::CalculateVisibleFaces(const XYZ &cameraPosition_xyz, FRUSTUM &frustum, BITSET &segmentMask)
{
	if (disable_vis) return;
	
	//Clear the list of faces drawn
	if (single_cluster)
	{
		if (!show_all) segmentMask.clearAll();
	}
	else
	{
		if (!show_all) leafActive.clearAll();
	}
	
	VECTOR3D cameraPosition;
	cameraPosition.x = cameraPosition_xyz.x;
	cameraPosition.y = cameraPosition_xyz.y;
	cameraPosition.z = cameraPosition_xyz.z;
	
	//calculate the camera leaf
	int cameraLeaf=CalculateCameraLeaf(cameraPosition);
	int cameraCluster=leaves[cameraLeaf].cluster;

	//loop through the leaves
	for(int i=0; i<numLeaves; ++i)
	{
		//if the leaf is not in the PVS, continue
		if(!isClusterVisible(cameraCluster, leaves[i].cluster))
			continue;

		//if this leaf does not lie in the frustum, continue
		if(!frustum.isBoundingBoxInside(leaves[i].boundingBoxVertices))
			continue;

		//loop through faces in this leaf and mark them to be drawn
		if (single_cluster)
		{
			for(int j=0; j<leaves[i].numFaces; ++j)
			{
				//facesToDraw.Set(leafFaces[leaves[i].firstLeafFace+j]);
				int faceNumber = leafFaces[leaves[i].firstLeafFace+j];
				
				if (faceDirectory[faceNumber].faceType==bspPolygonFace)
				{
					int polygonFaceNumber = faceDirectory[faceNumber].typeFaceNumber;
					
//					printf("polygonFaces[polygonFaceNumber].segmentIndex: %d\n",polygonFaces[polygonFaceNumber].segmentIndex);
					if (polygonFaces[polygonFaceNumber].segmentIndex)
					{
						segmentMask.set(polygonFaces[polygonFaceNumber].segmentIndex);
					}
				}
				if (faceDirectory[faceNumber].faceType==bspPatch)
				{
					int polygonFaceNumber = faceDirectory[faceNumber].typeFaceNumber;
					
//					printf("patches[polygonFaceNumber].segmentIndex: %d\n",patches[polygonFaceNumber].segmentIndex);
					if (patches[polygonFaceNumber].segmentIndex)
					{
						segmentMask.set(patches[polygonFaceNumber].segmentIndex);
					}
				}
				if (faceDirectory[faceNumber].faceType==bspMeshFace)
				{
					int polygonFaceNumber = faceDirectory[faceNumber].typeFaceNumber;
					
//					printf("meshFaces[polygonFaceNumber].segmentIndex: %d\n",meshFaces[polygonFaceNumber].segmentIndex);
					if (meshFaces[polygonFaceNumber].segmentIndex)
					{
						segmentMask.set(meshFaces[polygonFaceNumber].segmentIndex);
					}
				}
			}
		}
		else
		{
			leafActive.set(i);
		}
	}
}