0

わかりました。私はクラス球を持っています。特定の数のサブディビジョンで UVSphere の座標を初期化しようとしています。このクラスには、次のような 2D ベクトル頂点があります。

std::vector<std::vector<Angel::vec3>> verts;

vec3 は基本的に 3 つの float の構造体です

私には2つの機能があります

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() の最後で頂点の内容を見ると、見栄えは良いのですが、setupRaw() で頂点のサイズを出力しようとするとクラッシュします。ここで何が起こっているのですか?

4

0 に答える 0