调整六边形网格的高度图生成 [英] Tweaking Heightmap Generation For Hexagon Grids

查看:191
本文介绍了调整六边形网格的高度图生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在做一个小项目,只是为了一点乐趣.这是一个使用OpenGL的C ++ WinAPI应用程序.

Currently I'm working on a little project just for a bit of fun. It is a C++, WinAPI application using OpenGL.

我希望它将变成在六边形网格上玩的RTS游戏,当我完成基本游戏引擎后,我计划进一步扩展它.

I hope it will turn into a RTS Game played on a hexagon grid and when I get the basic game engine done, I have plans to expand it further.

目前,我的应用程序由一个VBO组成,该VBO包含顶点和高度图信息.高度图是使用中点位移算法(菱形正方形)生成的.

At the moment my application consists of a VBO that holds vertex and heightmap information. The heightmap is generated using a midpoint displacement algorithm (diamond-square).

为了实现六边形网格,我接受了在此处解释的想法.它向下移动普通网格的奇数行,以允许相对容易地渲染六边形,而不会造成太多的复杂性(我希望如此).

In order to implement a hexagon grid I went with the idea explained here. It shifts down odd rows of a normal grid to allow relatively easy rendering of hexagons without too many further complications (I hope).

几天后,它开始融合在一起,我添加了鼠标拾取功能,方法是将网格中的每个十六进制呈现为唯一的颜色,然后在此FBO中采样给定的鼠标位置以标识ID所选单元格的位置(在下面的屏幕截图的右上角可见).

After a few days it is beginning to come together and I've added mouse picking, which is implemented by rendering each hex in the grid in a unique colour, and then sampling a given mouse position within this FBO to identify the ID of the selected cell (visible in the top right of the screenshot below).

在我的项目的下一个阶段,我想研究生成更多可玩"地形.对我来说,这意味着每个六边形的形状应比上图中所看到的更规则.

In the next stage of my project I would like to look at generating more 'playable' terrains. To me this means that the shape of each hexagon should be more regular than those seen in the image above.

所以终于到了我要说的,在那里:

So finally coming to my point, is there:

  • 在当前方法中平滑或调整顶点的方法 可以将六边形的所有点都放在一个平面上(共面).
  • A way of smoothing or adjusting the vertices in my current method that would bring all point of a hexagon onto one plane (coplanar).

对于寻求有关如何使点共面的信息的任何人,请在此处是一个伟大的爆炸.

For anyone looking for information on how to make points coplanar here is a great explination.

  • 一种更好的程序地形生成方法,它可以 更好地控制这种事情.
  • 一种以不同的方式表示我的顶点信息的方式.
  • A better approach to procedural terrain generation that would allow for better control of this sort of thing.
  • A way to represent my vertex information in a different way that allows for this.

需要明确的是,我并不是要实现具有凸起边缘或平台(如下所示)的扁平六角网格.

To be clear, I am not trying to achieve a flat hex grid with raised edges or platforms (as seen below).

)

我希望所有几何图形都可以连接并进入下一个位段.

I would like all the geometry to join and lead into the next bit.

我希望能达到与现在相似的水平(相对起伏的丘陵和地形),但高原的可控性更高.这使我以后可以灵活地断开区域(无法播放的图块)的连接,如果需要,可以在其中添加更高细节的网格.

I'm hope to achieve something similar to what I have now (relatively nice undulating hills & terrain) but with more controllable plateaus. This gives me the flexibility of cording off areas (unplayable tiles) later on, where I can add higher detail meshes if needed.

欢迎任何反馈,我将其用作学习练习,所以请-欢迎所有评论!

Any feedback is welcome, I'm using this as a learning exercise so please - all comments welcome!

推荐答案

这取决于您真正想要的是什么,以及更受控"的含义.

It depends on what you actually want and what you mean by "more controlled".

您是否想说在半径为20的坐标[11,-127]上会有一座山"?这的复杂程度取决于您要走多远.如果只需要山脉,则径向渐变就足够了(只需将渐变值添加到噪声值中即可).但是,如果您想要一些更复杂的形状,就可以请客.

Do you want to be able to say "there will be a mountain on coordinates [11, -127] with radius 20"? Complexity of this this depends on how far you want to go. If you want just mountains, then radial gradients are enough (just add the gradient values to the noise values). But if you want some more complex shapes, you are in for a treat.

我在我的项目中进行了深入探讨(请考虑已发布的版本只是一个原型,目前正在进行重大重新设计,不过它完全可以用作地图生成器).

I explore this idea to great depth in my project (please consider that the published version is just a prototype, which is currently undergoing major redesign, it is completely usable a map generator though).

另一种方法是使生成过程更具过程性-您只需指定一系列数学函数,然后将其应用于地形即可.即使是简单的值转换也可以使您受益匪浅.

Another way is to make the generation much more procedural - you just specify a sequence of mathematical functions, which you apply on the terrain. Even a simple value transformation can get you very far.

所有这些方法对于十六进制网格都应该可以正常工作.如果由于奇数行移位而发生伪影,则可以对奇数行进行插值(只需使用简单的线性插值公式,从位于其之间的两个顶点计算顶点的高度值即可).

All of these methods should work just fine for hex grid. If artefacts occur because of the odd-row shift, then you could interpolate the odd rows instead (just calculate the height value for the vertex from the two vertices between which it is located with simple linear interpolation formula).

考虑一个将紫色线映射到蓝色曲线的函数-它强调较低的定位高度和很高的定位高度,但使它们之间的过渡更陡峭(此示例只是一个余弦函数,使曲线变小了)平滑会使转换更加突出).

Consider a function, which maps the purple line into the blue curve - it emphasizes lower located heights as well as very high located heights, but makes the transition between them steeper (this example is just a cosine function, making the curve less smooth would make the transformation more prominent).

您还可以只使用曲线的下半部分,从而使峰更尖锐,而位于较低位置的区域更平坦(因此更具可玩性).

You could also only use bottom half of the curve, making peaks sharper and lower located areas flatter (thus more playable).

曲线的清晰度"可以通过功率(使效果更加显着)或平方根(减小效果)轻松调节.

"sharpness" of the curve can be easily modulated with power (making the effect much more dramatic) or square root (decreasing the effect).

此操作实际上非常简单(特别是如果您使用余弦函数)-只需将该函数应用于地图中的每个像素即可.如果该函数在数学上不是那么微不足道,那么查找表就可以正常工作(在表值之间进行三次插值,线性插值会创建伪像).

Implementation of this is actually extremely simple (especially if you use the cosine function) - just apply the function on each pixel in the map. If the function isn't so mathematically trivial, lookup tables work just fine (with cubic interpolation between the table values, linear interpolation creates artefacts).

可以在本文中找到几种更简单的随机噪声地形游戏化"方法:"

Several more simple methods of "gamification" of random noise terrain can be found in this paper: "Realtime Synthesis of Eroded Fractal Terrain for Use in Computer Games".

祝您的项目好运

这篇关于调整六边形网格的高度图生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆