陡峭的变化,怎么办(Change of Steepness, how to do)

编程入门 行业动态 更新时间:2024-10-11 15:24:23
陡峭的变化,怎么办(Change of Steepness, how to do)

你会如何改变陡度和循环进展。 基本上我已经制作了一个带有顶点的地形,形成一个山谷。 这些顶点的数据创建在这里:

// 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; } }

这很好用。 但是我现在想要让山谷的两侧在第一个环路的开始和结束处更陡峭,并且山谷变得越来越接近它所获得的中心。 我有一点心理障碍,想不出一个好方法。 任何帮助,将不胜感激。

How would you go about changing the steepness as for loops progress. Essentially I've made a terrain with vertices which form a valley. The creation of the data for these vertices to use is here:

// 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; } }

This works fine. But I now want to make the sides of the valley steeper at the start and end of the first loop and the valley flatten the closer to the center it gets. I'm having a bit of a mental block and can't think of a good way of doing it. Any help would be appreciated.

最满意答案

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

float offset = (float)x - (float)TerrainWidth/2; float height = offset*offset*SCALE_FACTOR;

如果你仍然想在山谷的底部有一个“折痕”,你可以使你的身高加权:

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

You can use a squared (aka quadratic) curve for that. Try:

float offset = (float)x - (float)TerrainWidth/2; float height = offset*offset*SCALE_FACTOR;

If you still want a "crease" at the bottom of the valley, you can make your height a weighted sum:

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

更多推荐

本文发布于:2023-08-08 00:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466654.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:陡峭   Change   Steepness

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!