opengl中的标志效果

发布于 2024-12-13 19:29:15 字数 320 浏览 0 评论 0原文

我正在尝试按照此在线教程来创建一些波浪 http://nehe.gamedev.net/tutorial/flag_effect_(waaving_texture)/16002/

我想让波浪变得更大,但我不确定我是否以正确的方式进行处理,教程中当前四边形网格的大小为 45,所以我已增加到 450,但大小并没有似乎没有增加那么多。

有人可以指出我需要修改哪些内容才能使四边形变大的正确方向吗?

I'm trying to follow this online tutorial to create some waves
http://nehe.gamedev.net/tutorial/flag_effect_(waving_texture)/16002/.

I want to make the wave much bigger, but I'm not sure if I'm going about it the right way, the current mesh of quads is sized 45 in the tutorial, so i have increased to 450, however the size doesn't seem to increase that much.

Can someone point me in the right direction as to what needs to be modified to make the quads bigger.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╭ゆ眷念 2024-12-20 19:29:15

如果你只是想让四边形变大,那么你需要修改顶点位置代码。在您发布的 NeHe 教程中,将此部分更改

// Loop Through The X Plane
for(int x=0; x<45; x++)
{
    // Loop Through The Y Plane
    for(int y=0; y<45; y++)
    {
        // Apply The Wave To Our Mesh
        points[x][y][0]=float((x/5.0f)-4.5f);
        points[x][y][1]=float((y/5.0f)-4.5f);
        points[x][y][2]=float(sin((((x/5.0f)*40.0f)/360.0f)*3.141592654*2.0f));
    }
}

// Loop Through The X Plane
float spacing = 0.5f;
float spacingInv = 1.0f/spacing;
float offset = (45 / spacingInv) / 2.0f;    // The 45 comes from the number of points (if you change this, change the for loop and the variable creation)
for(int x=0; x<45; x++)
{
    // Loop Through The Y Plane
    for(int y=0; y<45; y++)
    {
        // Apply The Wave To Our Mesh
        // We change the x/5.0f-4.5f to change the size of the quads
        // See text after for more details
        points[x][y][0]=float((x/spacingInv)-offset);
        points[x][y][1]=float((y/spacingInv)-offset);
        points[x][y][2]=float(sin((((x/spacingInv)*40.0f)/360.0f)*3.141592654*2.0f));
    }
}

:说明:
x/5.0f 给出的值为 0、0.2、0.4、0.6、0.8、1.0、......、9.0。

如果您只采用这些值,您现在将拥有一个偏离中心的四边形网格。现在取 x/5.0f - 4.5f 得到值 -4.5 -4.3, -4.1, ...... 4.1, 4.3, 4.5

如果你想让四边形更大,你需要增加点之间的间距(即,将 x/5.0f 更改为 x/2.0f 之类的内容(这就是我给出的示例中发生的情况))。然后你想要重新居中(即更改-4.5f)。

If you just want to make the quads bigger, then you need to modify the vertex position code. In the NeHe tutorial you posted change this part:

// Loop Through The X Plane
for(int x=0; x<45; x++)
{
    // Loop Through The Y Plane
    for(int y=0; y<45; y++)
    {
        // Apply The Wave To Our Mesh
        points[x][y][0]=float((x/5.0f)-4.5f);
        points[x][y][1]=float((y/5.0f)-4.5f);
        points[x][y][2]=float(sin((((x/5.0f)*40.0f)/360.0f)*3.141592654*2.0f));
    }
}

To this:

// Loop Through The X Plane
float spacing = 0.5f;
float spacingInv = 1.0f/spacing;
float offset = (45 / spacingInv) / 2.0f;    // The 45 comes from the number of points (if you change this, change the for loop and the variable creation)
for(int x=0; x<45; x++)
{
    // Loop Through The Y Plane
    for(int y=0; y<45; y++)
    {
        // Apply The Wave To Our Mesh
        // We change the x/5.0f-4.5f to change the size of the quads
        // See text after for more details
        points[x][y][0]=float((x/spacingInv)-offset);
        points[x][y][1]=float((y/spacingInv)-offset);
        points[x][y][2]=float(sin((((x/spacingInv)*40.0f)/360.0f)*3.141592654*2.0f));
    }
}

Explanation:
x/5.0f gives you values 0, 0.2, 0.4, 0.6, 0.8, 1.0, ......, 9.0.

If you were to take just those values, you would now have an off center grid of quads. Now taking x/5.0f - 4.5f gives you values -4.5 -4.3, -4.1, ...... 4.1, 4.3, 4.5

If you wanted to make the quads bigger, you need to increase the spacing between the points (i.e. change the x/5.0f to something like x/2.0f (which is what happens in the example I gave)). And then you want to recenter (i.e. change the -4.5f).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文