当前位置: 首页>>代码示例>>C++>>正文


C++ CFrustum::Intersects方法代码示例

本文整理汇总了C++中CFrustum::Intersects方法的典型用法代码示例。如果您正苦于以下问题:C++ CFrustum::Intersects方法的具体用法?C++ CFrustum::Intersects怎么用?C++ CFrustum::Intersects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CFrustum的用法示例。


在下文中一共展示了CFrustum::Intersects方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetMeshes

void CBspMapMeshProvider::GetMeshes(Palleon::MeshArray& meshes, const Palleon::CCamera* camera)
{
	const Bsp::LeafArray& leaves(m_bspFile->GetLeaves());
	const Bsp::LeafFaceArray& leafFaces(m_bspFile->GetLeafFaces());
	const Bsp::FaceArray& faces(m_bspFile->GetFaces());
	const Bsp::VISDATA& visData(m_bspFile->GetVisData());

	CMatrix4 invViewMatrix = camera->GetViewMatrix().Inverse();
	CVector3 cameraPosition = CVector3(invViewMatrix(3, 0), invViewMatrix(3, 1), invViewMatrix(3, 2));

	int32 leafIndex = FindLeaf(cameraPosition);
	const Bsp::LEAF& leaf(leaves[leafIndex]);

	CFrustum cameraFrustum = camera->GetFrustum();

	memset(m_faceVisibleSet, 0, m_faceVisibleSetSize);

	if(leaf.cluster != -1)
	{
		const uint8* visVector = &visData.vectors[leaf.cluster * visData.vectorSize];
		for(uint32 i = 0; i < leaves.size(); i++)
		{
			const Bsp::LEAF& testLeaf = leaves[i];
			uint32 testCluster = testLeaf.cluster;
			if(static_cast<int32>(testCluster) < 0) continue;
			uint8 visByte = visVector[testCluster / 8];
			bool visible = (visByte & (1 << (testCluster & 7))) != 0;
			if(visible)
			{
				CVector3 leafBoxMin = Bsp::ConvertToAthenaCoord(static_cast<float>(testLeaf.mins[0]), static_cast<float>(testLeaf.mins[1]), static_cast<float>(testLeaf.mins[2]));
				CVector3 leafBoxMax = Bsp::ConvertToAthenaCoord(static_cast<float>(testLeaf.maxs[0]), static_cast<float>(testLeaf.maxs[1]), static_cast<float>(testLeaf.maxs[2]));

				if(cameraFrustum.Intersects(leafBoxMin, leafBoxMax))
				{
					for(unsigned int i = 0; i < testLeaf.leafFaceCount; i++)
					{
						unsigned int faceIndex = leafFaces[i + testLeaf.leafFaceIndex];
						unsigned int faceByte = faceIndex / 8;
						assert(faceByte < m_faceVisibleSetSize);
						m_faceVisibleSet[faceByte] |= (1 << (faceIndex & 7));
					}
				}
			}
		}
	}

	m_visibleFaceIndices.clear();

	for(unsigned int i = 0; i < faces.size(); i++)
	{
		const Bsp::FACE& currentFace = faces[i];
		if(currentFace.textureIndex != -1)
		{
			BspMapMaterialPtr faceMaterial = m_bspMapResourceProvider->GetMaterial(currentFace.textureIndex);
			if(faceMaterial->GetIsSky()) continue;
		}

		unsigned int faceByte = i / 8;
		if(m_faceVisibleSet[faceByte] & (1 << (i & 7)))
		{
			m_visibleFaceIndices.push_back(i);
		}
	}

	if(m_visibleFaceIndices.size() == 0) return;

	std::sort(m_visibleFaceIndices.begin(), m_visibleFaceIndices.end(), FaceSorter(faces));

	uint32 currentTextureIdx = -2;
	uint32 currentLightMapIdx = -2;
	BatchMeshPtr currentBatch;
	unsigned int currentBatchIndex = 0;
	for(unsigned int i = 0; i < m_visibleFaceIndices.size(); i++)
	{
		uint32 faceIndex = m_visibleFaceIndices[i];
		const Bsp::FACE& currentFace = faces[faceIndex];
		BspFaceMeshPtr faceMesh = m_faceMeshes[faceIndex];
		if(!faceMesh) continue;
		bool needNewBatch = false;
		needNewBatch |= (currentFace.textureIndex != currentTextureIdx);
		needNewBatch |= (currentFace.lightMapIndex != currentLightMapIdx);
		needNewBatch |= (currentBatch && !currentBatch->CanWriteMesh(faceMesh->GetVertexCount(), faceMesh->GetIndexCount()));
		if(needNewBatch)
		{
			//Switch to new batch
			if(currentBatch)
			{
				currentBatch->EndBatch();
			}
			currentBatch = m_batches[currentBatchIndex++];
			meshes.push_back(currentBatch.get());
			currentBatch->BeginBatch();
			currentTextureIdx = currentFace.textureIndex;
			currentLightMapIdx = currentFace.lightMapIndex;

			//Prepare material
			Palleon::MaterialPtr batchMaterial = currentBatch->GetMaterial();
			BspMapMaterialPtr faceMaterial = m_bspMapResourceProvider->GetMaterial(currentTextureIdx);
			
			for(unsigned int i = 0; i < Palleon::CMaterial::MAX_TEXTURE_SLOTS; i++)
//.........这里部分代码省略.........
开发者ID:jpd002,项目名称:Palleon,代码行数:101,代码来源:BspMapMeshProvider.cpp


注:本文中的CFrustum::Intersects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。