Math 陡度的变化,怎么办

Math 陡度的变化,怎么办,math,xna,Math,Xna,你将如何改变陡度作为循环的进展。基本上,我已经制作了一个顶点形成山谷的地形。要使用的这些顶点的数据创建如下: // Divides it to a sensible height const int DIVISOR_NUMBER = 40; for (int x = 0; x < TerrainWidth; x++) { float height = Math.Abs(((float)x - ((float)TerrainWidth / 2

你将如何改变陡度作为循环的进展。基本上,我已经制作了一个顶点形成山谷的地形。要使用的这些顶点的数据创建如下:

    // Divides it to a sensible height
    const int DIVISOR_NUMBER = 40;

    for (int x = 0; x < TerrainWidth; x++)
    {
        float height = Math.Abs(((float)x - ((float)TerrainWidth / 2))/ (float)DIVISOR_NUMBER);

        for (int y = 0; y < TerrainHeight; y++)
        {
            float copyOfHeight = height;
            float randomValue = random.Next(0, 3);
            copyOfHeight += randomValue / 10;
            HeightData[x, y] = copyOfHeight;
        }
    }
//将其划分到合理的高度
常数整除数=40;
对于(int x=0;x
这个很好用。但是我现在想让山谷的两边在第一圈的起点和终点更陡峭,山谷越靠近中心就越平坦。我有点精神障碍,想不出一个好办法。任何帮助都将不胜感激。

您可以使用平方(又称二次)曲线。尝试:

float offset = (float)x - (float)TerrainWidth/2;
float height = offset*offset*SCALE_FACTOR;
如果您仍然希望在山谷底部出现“折痕”,则可以将您的身高设置为加权和:

float height = Math.Abs(offset) * ABS_FACTOR + offset*offset * QUADRATIC_FACTOR;

我猜,立方的这种影响会使它更明显?立方会使山谷更平坦,边缘的曲线更突然。您还需要使用
Math.Abs()
来处理负偏移量。