コード例 #1
0
//-----------------------------------------------------------------------------
// Purpose: Initialize the cull box with the bounds of the faces.
//-----------------------------------------------------------------------------
void CMapClass::SetCullBoxFromFaceList( CMapFaceList *pFaces )
{
	//
	// Calculate our 3D bounds.
	//
	m_CullBox.ResetBounds();
	for (int i = 0; i < pFaces->Count(); i++)
	{
		CMapFace *pFace = pFaces->Element(i);
		int nPoints = pFace->GetPointCount();
		for (int i = 0; i < nPoints; i++)
		{
			Vector point;
			pFace->GetPoint(point, i);

			//
			// Push the culling box out in all directions.
			// TODO: rotate the culling box based on the cone orientation
			//			
			for (int nDim = 0; nDim < 3; nDim++)
			{
				m_CullBox.bmins[0] = min(m_CullBox.bmins[0], m_Origin[0] - point[nDim]);
				m_CullBox.bmins[1] = min(m_CullBox.bmins[1], m_Origin[1] - point[nDim]);
				m_CullBox.bmins[2] = min(m_CullBox.bmins[2], m_Origin[2] - point[nDim]);

				m_CullBox.bmaxs[0] = max(m_CullBox.bmaxs[0], m_Origin[0] + point[nDim]);
				m_CullBox.bmaxs[1] = max(m_CullBox.bmaxs[1], m_Origin[1] + point[nDim]);
				m_CullBox.bmaxs[2] = max(m_CullBox.bmaxs[2], m_Origin[2] + point[nDim]);
			}
		}
	}
}
コード例 #2
0
//-----------------------------------------------------------------------------
// Purpose: Repairs an invalid solid.
// Input  : pError - Contains information about the error.
//-----------------------------------------------------------------------------
static void FixSolidStructure(MapError *pError)
{
	CMapSolid *pSolid = (CMapSolid *)pError->pObjects[0];

	//
	// First make sure all the faces are good.
	//
	int nFaces = pSolid->GetFaceCount();
	for (int i = nFaces - 1; i >= 0; i--)
	{
		CMapFace *pFace = pSolid->GetFace(i);
		if (!pFace->CheckFace(NULL))
		{
			pFace->Fix();
		}
		//
		// If the face has no points, just remove it from the solid.
		//
		if (pFace->GetPointCount() == 0)
		{
			pSolid->DeleteFace(i);
		}
	}

	//
	// Rebuild the solid from the planes.
	//
	pSolid->CreateFromPlanes();
	pSolid->PostUpdate(Notify_Changed);
}