落沙模拟

发布于 2024-10-11 04:36:29 字数 257 浏览 9 评论 0原文

我正在尝试重新创建一个“落沙”模拟,类似于那些做同样事情的各种网络玩具 - 但我失败得很厉害。我不太确定从哪里开始。我正在尝试使用元胞自动机来模拟沙粒的行为,但我无法弄清楚如何使更新“世界”的方向变得无关紧要......

例如,粒子之一我想要的类型是植物。当植物与水接触时,植物会将水粒子转化为另一个植物粒子。但这里的问题是,如果我从上到下、从左到右更新游戏世界,那么放置在水粒子海洋中间的植物粒子将立即导致所有水粒子向右和向下那个新的植物粒子变成了植物。这不是我所期望的行为。 =(

I'm trying to re-create a 'falling sand' simulation, similar to those various web toys that are out there doing the same thing - and I'm failing pretty hard. I'm not really sure where to begin. I'm trying to use cellular automata to model the behavior of the sand particles, but I'm having trouble figuring out how to make the direction in which I update the 'world' not matter...

For example, one of the particle types I'd like to have is Plant. When Plant comes in contact with Water, Plant turns that Water particle into another Plant particle. The problem here though is that if I'm updating the game world from top to bottom and left to right, then a Plant particle placed in the middle of a sea of Water particles will immediately cause all of the Water particles to the right and below that new Plant particle to turn into Plants. This is not the behavior I am expecting. =(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生不灭 2024-10-18 04:36:29

一个简单的解决方案是不要就地进行每次迭代。相反,每次更新世界时,都会创建它的副本......然后查看原始版本,但更新副本。这样,更新的顺序就不再重要了,因为在寻找粒子时,您完全忽略了更新。

One straightforward solution is to not do each iteration in-place. Instead, every time you update the world, create a copy of it... then look at the original, but update the copy. That way the order of updating does not matter any more, because you are completely disregarding your updates while you're looking for particles.

未蓝澄海的烟 2024-10-18 04:36:29

不要以顺序方式对其进行编程(循环所有粒子),而是使用真正的模拟编程技术,其中每个粒子都被视为遵守物理定律的单个对象/代理,并且可以异步运行(运行)并响应“事件”(与其他粒子的相互作用)。

如果让每个沙粒成为一个单独的对象太细粒度,那么将世界分成小块(假设有 1000 个颗粒),然后模拟这些块的行为。

Don't program it in a sequential way (looping over all particles) but use real simulation programming techniques in which every particle is treated as an individual object/agent that obeys the laws of physics and that can act (run) asynchronously and respond to "events" (interactions with other particles).

If making every sand particle a separate object is too fine-grained, then divide the world into small blocks of let's say 1000 particles and simlute the behavior of these blocks instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文