本文整理汇总了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;
}