2

我正在为学校做一个项目,其中一部分是制作高度图。

我设法按要求创建了高度图,但希望获得一点额外的功劳并平滑整个表面。这是我现在拥有的图像:

http://img.photobucket.com/albums/v222/shavus/hMap.png

我用来生成它的代码是输入 .jpg,然后使用 GL_TRIANGLE_STRIP 创建我已经拥有的地图。

我使用的代码:

glBegin(GL_TRIANGLE_STRIP);
       for(int i = 1; i <= sourceImage->ny; i++)
       {
               for(int j = 1; j <= sourceImage->nx; j++)
               {
                       // Define Color for the Vertex
                       int red = PIC_PIXEL(sourceImage , j, i, 0);                // Find RGB value for each pixel
                       int green = PIC_PIXEL(sourceImage , j, i, 1);
                       int blue = PIC_PIXEL(sourceImage , j, i, 2);
                       float color = (float)(red + green + blue)/(3.0*255.0);

                       // Define Position for the Vertex
                       float xPos = (-1.0 + 2.0*((float)j/(float)sourceImage->nx)) * boxSize;
                       float yPos = (-1.0 + 2.0*((float)i/(float)sourceImage->ny)) * boxSize;
                       float height = (-boxSize + 2*((red + green + blue) / (3.0 * 255.0)));
                       glColor3f(color, color, color);
                       height = height * 0.5 * boxSize;
                       glVertex3f(xPos, yPos, height);
               }
       }
       glEnd(); 

我怎样才能使这个表面看起来更像这样?

http://zac-interactive.dk/blogimages/heightmap.jpg

感谢您的任何帮助,您可以提供!

4

1 回答 1

2

消除高度图中高度突然变化并使其更平滑的简单方法是在其上运行卷积过滤器。

这是一个链接:

http://www.gamedev.net/reference/articles/article2164.asp

在做盒子过滤器。这不是您可以使用的最好的过滤器,但它会产生很大的不同。

于 2010-09-20T18:54:50.037 回答