【问题标题】:Parametric generation of a plane平面的参数化生成
【发布时间】:2015-03-20 14:24:34
【问题描述】:

我正在尝试使用给定的widthheight 以参数方式生成一个平面。这应该非常简单,但却非常令人沮丧:我的代码适用于 16x16 或以下的所有正方形尺寸,然后就开始混乱了。

生成顶点

这里没什么特别的,只是按行和列布置顶点。

Float3* vertices = new Float3[width * height];
int i = 0;
for (int r = 0; r < height; r++) {
    for (int c = 0; c < width; c++) {
        i = (r * width) + c;
        vertices[i] = Float3(c, 0, r);
    }
}

生成索引

黑色数字 = 顶点索引,红色数字 = 顺序

除了边缘之外,每个顶点需要 6 个槽来放置它们的索引。

numIndices = ((width - 1) * (height - 1)) * 6;
GLubyte* indices = new GLubyte[numIndices];
i = 0; // Index of current working vertex on the map
int j = -1; // Index on indices array
for (int r = 0; r < height - 1; r++) {
    for (int c = 0; c < width - 1; c++) {
        i = (r * width) + c;
        indices[++j] = i;
        indices[++j] = i + height + 1;
        indices[++j] = i + height;
        indices[++j] = i;
        indices[++j] = i + 1;
        indices[++j] = i + 1 + height;
    }
}

逻辑哪里出错了?

【问题讨论】:

    标签: c++ opengl


    【解决方案1】:

    您超出了 GLubyte 的限制,它可以容纳 255 的最大值。尝试改用 GLushort。

    【讨论】:

    • 我觉得很可笑,但这正是问题所在。非常感谢。
    猜你喜欢
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-20
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    • 2012-07-15
    相关资源
    最近更新 更多