0

5 つの頂点と 18 のインデックスを持つピラミッドがあります。各面に法線を追加したいので、各頂点の法線の解決策を見つけました。つまり、インデックスを使用してピラミッドを定義することはできません。18 個の頂点が必要です (空間内の同じ点に対して同じ頂点の 3 倍)。

頂点ベースではなくインデックス ベースで法線を使用するソリューションが必要です。

いくつかのコード (javascript):

var vertices = [
    -half, -half,  half, // 0 front left
     half, -half,  half, // 1 front right
     half, -half, -half, // 2 back right
    -half, -half, -half, // 3 back left
      0.0,  Math.sqrt((size * size) - (2 * (half * half))) - half,   0.0  // 4 top
];

var vertexNormals = [
    // front face
     normaleFront[0],  normaleFront[1],  normaleFront[2],
     normaleFront[0],  normaleFront[1],  normaleFront[2],
     normaleFront[0],  normaleFront[1],  normaleFront[2],

    // back face
     normaleBack[0],  normaleBack[1],  normaleBack[2],
     normaleBack[0],  normaleBack[1],  normaleBack[2],
     normaleBack[0],  normaleBack[1],  normaleBack[2],

    // left face
     normaleLeft[0],  normaleLeft[1],  normaleLeft[2],
     normaleLeft[0],  normaleLeft[1],  normaleLeft[2],
     normaleLeft[0],  normaleLeft[1],  normaleLeft[2],

    // right face
     normaleRight[0],  normaleRight[1],  normaleRight[2],
     normaleRight[0],  normaleRight[1],  normaleRight[2],
     normaleRight[0],  normaleRight[1],  normaleRight[2],

    // bottom face
     0.0, -1.0, 0.0,
     0.0, -1.0, 0.0,
     0.0, -1.0, 0.0,
     0.0, -1.0, 0.0,
     0.0, -1.0, 0.0,
     0.0, -1.0, 0.0,
];

var pyramidVertexIndices = [
    0, 1, 4, // Front face
    2, 3, 4, // Back face
    3, 0, 4, // Left face
    1, 2, 4, // Right face
    0, 1, 2,   2, 3, 0, // Bottom face
];
4

1 に答える 1

1

ピラミッドの各頂点には、属する面に応じて 3 つの異なる法線があります。したがって、 を使用するには、各頂点をそれぞれ異なる法線で 3 回渡す必要がありますglDrawElements

または、電話することもできます

// Face 1
glNormal
glVertex
glVertex
glVertex

// Face 2 glNormal glVertex glVertex glVertex

// ...

于 2011-01-02T22:37:12.460 に答える