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


C++ List::Allocate方法代码示例

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


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

示例1: Triangulate

/// Triangulates the mesh.
void Mesh::Triangulate()
{
	int newMeshFacesNeeded = numFaces;
    if (numFaces == 0)
        return;
//	std::cout<<"\nMeshFaces: "<<numFaces;
	for (int i = 0; i < numFaces; ++i)
	{
	 //   std::cout<<"D:";
		MeshFace * currentMeshFace = &faces[i];
		if (currentMeshFace->numVertices > 3)
		{
			int meshFacesToAdd = currentMeshFace->numVertices - 3;
		//	std::cout<<"\nMeshFaces to add in faces "<<i<<": "<<MeshFacesToAdd;
			newMeshFacesNeeded += currentMeshFace->numVertices - 3;
			if (meshFacesToAdd > 20){
				std::cout<<"\nMeshFace vertices amount very large("<<(int)currentMeshFace->numVertices<<"), printing debug info:";
				assert(currentMeshFace->numVertices - 3 < 18);
				std::cout<<"\nAborting Triangularization since mesh data seems faulty!";
				return;
			}
		}
	}
//	std::cout<<"\nNew numFaces needed:"<<newMeshFacesNeeded;

	// Already triangulated..
	if (newMeshFacesNeeded == faces.Size())
	{
		triangulated = true;
		return;
	}

	// Allocate new MeshFace array
	int meshFaceSize = sizeof(faces);
	List<MeshFace> newMeshFaces;
	newMeshFaces.Allocate(newMeshFacesNeeded, true);
	int meshFacesAddedSoFar = 0;
	for (int i = 0; i < numFaces; ++i)
	{
		MeshFace * newTri = &newMeshFaces[meshFacesAddedSoFar];
		MeshFace & oldMeshFace = faces[i];
		// Just copy
		if (oldMeshFace.numVertices == 3)
		{
			newTri->numVertices = 3;
		//	newTri->AllocateArrays();
			newTri->normals = oldMeshFace.normals;
			newTri->uvs = oldMeshFace.uvs;
			newTri->vertices = oldMeshFace.vertices;
			meshFacesAddedSoFar++;
		}
		else {
			int numVertices = oldMeshFace.numVertices;
	//		std::cout<<"\nConverting old faces...";
	//		std::cout<<"\n";
	//		oldMeshFace->Print();
	//		std::cout<<"\nInto new numFaces...!";
			for (int j = 0; j < numVertices-2; ++j)
			{
				newTri = &newMeshFaces[meshFacesAddedSoFar];
				/// Create new triangle for every extra vertices!
				newTri->numVertices = 3;
				newTri->AllocateArrays();
				newTri->normals[0] = oldMeshFace.normals[0];
				newTri->uvs[0] = oldMeshFace.uvs[0];
				newTri->vertices[0] = oldMeshFace.vertices[0];
				for (int k = j+1; k < j+3; ++k)
				{
					newTri->normals[k - j] = oldMeshFace.normals[k];
					newTri->uvs[k - j] = oldMeshFace.uvs[k];
					newTri->vertices[k - j] = oldMeshFace.vertices[k];
				}
				meshFacesAddedSoFar++;
	//			std::cout<<"\n";
	//			newTri->Print();
			}
		}
	}
	faces.Clear();
	faces = newMeshFaces;
	numFaces = newMeshFacesNeeded;
	triangulated = true;
}
开发者ID:erenik,项目名称:engine,代码行数:84,代码来源:Mesh.cpp


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