[英]Converting 2D Tile based shapes to simplified Polygons
As seen in the image above, I have a 2D array of tiles, each with 4 points in my game world. 如上图所示,我有一个2D阵列的瓷砖,每个瓷砖在我的游戏世界中有4个点。 I'm looking for a method to convert these shapes constructed from individual tiles into simplified (no unnecessary vertices, only those needed to form the outline) polygon shapes. 我正在寻找一种方法,将从单个瓷砖构造的这些形状转换为简化的(没有不必要的顶点,只有形成轮廓所需的那些)多边形。
I have been looking around, here and elsewhere and have had very little luck. 我一直在四处寻找,在这里和其他地方,运气很少。 But maybe I don't know the correct terminology to search for. 但也许我不知道要搜索的正确术语。 Any help is appreciated. 任何帮助表示赞赏。
Extra Info: I'm looking to use this to optimize dynamic lighting. 额外信息:我希望用它来优化动态照明。 If someone has a different approach for accomplishing fast dynamic shadows in a tile based world, that will also answer the question. 如果某人有一种不同的方法来在基于图块的世界中完成快速动态阴影,那么这也将回答这个问题。
I suggest next algorithm: 我建议下一个算法:
For more intuitive representation of algorithm, I posted an image below. 为了更直观地表示算法,我在下面发布了一张图片。
The naive approach would be to simply step through every single tile and mark any transition edges into a polygon but you could reuse a common edge detection routine for better performance. 天真的方法是简单地逐步遍历每个单独的图块并将任何过渡边缘标记为多边形,但您可以重复使用公共边缘检测例程以获得更好的性能。
After that you'd probably be interested in tessellating those polygons so as to convert them into collections of triangles (making the later shadow/lighting/intersection math a lot simpler), the only problem in this case is if you end up with a concave polygon, but a decent tessellator should allow you to break it up into convex polygons. 之后你可能有兴趣对这些多边形进行细分,以便将它们转换为三角形集合(使后面的阴影/光照/交叉点数学变得更加简单),在这种情况下唯一的问题是如果你最终得到一个凹面多边形,但一个体面的镶嵌器应该允许您将其分解为凸多边形。 I don't think XNA has anything built in for tessellation so you might need to find a utility library to do it for you. 我不认为XNA有任何内置的镶嵌细分,因此您可能需要找到一个实用程序库来为您完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.