如何确定 2D 可见性
我正在开发一个人工智能沙箱,我想计算每个生物体可以看到的内容。
规则是简单地从实体的角度隐藏形状边缘后面的内容。该图像澄清了一切:
alt 文本 http://img231.imageshack.us/img231/2972 /shadows.png
我需要它作为人工智能的输入,或者以图形方式显示它,以在特定实体移动时显示它。
有什么很酷的想法吗?
I'm developing an AI sandbox and I would like to calculate what every living entity can see.
The rule is to simply hide what's behind the edges of the shapes from the point of view of the entity. The image clarifies everything:
alt text http://img231.imageshack.us/img231/2972/shadows.png
I need it either as an input to the artificial intelligence either graphically, to show it for a specific entity while it moves..
Any cool ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
李氏算法。它会生成一个多边形,这可能对 AI 的进一步分析有用:
我意识到这个解释不太好,但我有这里有一个在线演示,您可以尝试一下,了解它是如何工作的。将其扩展到与圆圈一起使用可能还不错(著名的遗言)。
Lee's Algorithm. It produces a polygon which might be useful for further analysis by your AI:
I realize this explanation isn't great, but I have an online demo here that you can play with to get a sense for how it works. Extending it to work with circles probably isn't too bad (famous last words).
如果您使用简单的形状来阻挡实体的视图,我已经实现了一种简单的方法来执行此操作:
创建一个可以水平或垂直移动的
VisionWave
对象。您可以使用源坐标、与该点相交的两条线以及距源点的距离来定义 VisionWave。您应该有 4 个波浪:一个向上、一个向下、一个向左、一个向右,定义它们的线的斜率应为 1 和 -1(即 X)。下面我的粗略绘图显示了一个波浪(向右),由
>
字符表示。创建一个循环,每次将每个波传播一个像素。传播波时,您需要执行以下操作:
我在 Roguelike 中实现了这样的系统,速度非常快。确保分析您的代码是否存在瓶颈。
如果你很聪明,你可以尝试圆形波而不是直线,但我不知道由于三角计算,它是否会更快。
If you're using simple shapes to block the entity's view, there is an easy way to do this that I have implemented:
Create a
VisionWave
object which can move either horizontally or vertically. You can define aVisionWave
using a source coordinate, two lines that intersect that point, and a distance from the source point.You should have 4 waves: one going up, one down, one left, and one right, and the lines that define them should have a slope of 1 and -1 (i.e., an X). My crude drawing below shows one wave (going right) as represented by the
>
character.Make a loop that propagates each wave one pixel at a time. When you propagate the wave, you want to do the following:
I implemented a system like this in my Roguelike and it is very fast. Make sure to profile your code for bottlenecks.
If you're very clever you might try circular waves instead of straight lines, but I don't know if it would be faster due to the trigonometric calculations.
确定哪些顶点对您的视点可见,然后将这些顶点投影到远离视点的直线上以形成新顶点。闭合形状,您将创建一个代表不可见区域的多边形。
请参阅 阴影体积 了解 3D 等效项。
Determine which vertices are visible to your eye point, then project those vertices back away from the eye point on a straight line to make new vertices. Close the shape and you will have created a polygon representing the invisible area.
See shadow volumes for the 3D equivalent.