Alrighty。我有一个班级球。我试图初始化具有给定数量的细分的UVSphere的坐标。该类有一个2D矢量顶点,如下所示:
std::vector<std::vector<Angel::vec3>> verts;
其中vec3本质上是三个浮点数的结构
我有两个功能
void setupSphere();
void setupRaw();
其实现如下:
void Sphere::setupSphere()
{
float pi = std::atan(1.0f) * 4.0f;
float subdivAngle = 2 * pi / numSubdivide;
std::vector<Angel::vec3> yVectors;
yVectors.reserve(numSubdivide);
for (int i = 0; i < numSubdivide; i ++)
{
float curAngle = subdivAngle * i;
yVectors.push_back(Angel::vec3(std::cos(curAngle), 0.0, -std::sin(curAngle)));
}
int zNumSubdivide = numSubdivide + 4;
float zAngle = 2 * pi / zNumSubdivide;
for (int i = 1; i < zNumSubdivide / 2; i ++)
{
float curAngle = pi / 2 - zAngle * i;
float yCoord = std::sin(curAngle);
float xzScale = std::cos(curAngle);
std::vector<Angel::vec3> curVector;
for (int j = 0; j < numSubdivide; j ++)
{
Angel::vec3 newPoint = yVectors[j] * xzScale;
newPoint.y = yCoord;
curVector.push_back(newPoint);
}
verts.push_back(curVector);
}
std::cout << "Size = " << verts.size() << std::endl;
setupRaw();
//setupTexture();
}
void Sphere::setupRaw()
{
std::cout << "TESTING" << std::endl;
std::cout << "Size = " << verts.size();
}
当我在setupSphere()结尾处查看verts的内容时,它看起来很棒,但是在setupRaw()中,当我尝试打印verts的大小时它会崩溃。这是怎么回事?