如何创建随机模拟?

发布于 2024-07-13 05:11:15 字数 503 浏览 5 评论 0原文

我一直在玩这款Flash游戏,之后我得到了在最初的(“哈哈,火”)反应中,我开始想知道如何在编程中复制这种接触变异行为。 我想它有点像蜜罐xkcd

我正在考虑从一个场景开始,其中粒子相互偏离以及包含的墙壁偏离。 该序列将从一定数量的“突变”粒子开始,当这些突变体与常规粒子碰撞时,它们本身就会变成突变体。 以后我可以做一些更有趣的事情。

我的问题是如何开始这样做。 我计划使用 .NET 的绘图元素在 C# 中完成此操作(尽管我对 C# 相当陌生 - 如果 .NET 有不同的部分,我应该使用让我知道),但如果有任何关于它的一般论文,我有兴趣阅读它们(当然,如果它们可以在线获取)。

谢谢, 罗斯

I've been playing this flash game and after I'd gotten over the initial ('lol, fire') reaction I started to wonder how I could replicate this contact-mutate behaviour in programming. I guess it's a little like the honeypot xkcd.

I was thinking of starting with a scenario where particles deflect off each other and the containing walls. The sequence would start with a set number of 'mutant' particles, and when these mutants collide with regular particles they'd become mutants themselves. I could work in some more fun things later.

My problem is how to get started with this. I'm planning to do it in C# using the Drawing elements of .NET (although I'm fairly new to C# - if there's a different part of .NET I should use let me know) but if there's any general papers on it I'd be interested to read them (if they're available online of course).

Thanks,
Ross

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

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

发布评论

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

评论(2

神爱温柔 2024-07-20 05:11:15

我认为你的想法是正确的,盒子里的一些粒子会在这里做得很好。 我无法想象您会找到关于如此具体和简单案例的论文,但也许是所需的一些技术,但与渲染器相比,后端的实现应该相对简单。

要移动粒子,一个简单的方法是 欧拉迭代,您可以在其中存储位置和速度。 位置=位置+速度*dt; 其中 dt 是自上一帧以来的时间变化。 最好保持 dt 固定,并在渲染器的点之间进行插值(如果可以的话)...这将减少稳定性问题并使碰撞检测更容易。

要反射粒子离开墙壁,请检查其位置的 x 分量或 y 分量是否超出边界,然后翻转速度的其他分量的符号,例如,

if(Math.Abs(position.x_component + velocity.x_component * dt) > x_bound) 
    velocity.y_component = -velocity.y_component;

if(Math.Abs(position.y_component + velocity.y_component * dt) > y_bound)
    velocity.x_component = -velocity.x_component;

如果您有恒定的 dt,则效果很好,但是如果情况有所不同,您将需要做一些更复杂的事情。 找到与盒子的碰撞点并反射部分碰撞面中盒子外部的向量。

对于粒子彼此碰撞,距离检查可能是最好的,一旦距离太小就会触发反射。 即如果它们靠得太近就会发生碰撞。 像粒子是球体一样反射速度分量,因此反射的法线是它们位置的差异。

您可能会发现有关 gamedev 的这篇文章也很有用...

希望这会有所帮助。

I think you are on the right track with what you are thinking, some particles in a box would do fine here. I can't imagine you would find papers on such a specific and simple case but perhaps for some of the techniques required, but an implementation of the backend should be relatively simple compared to a renderer.

To move the particles around a simple method is Euler iteration, where you store the positions and velocities. position = position + velocity*dt; where dt is the change in time since the last frame. It is best to keep dt fixed, and interpolate between points for the renderer if you can... this will reduce stability issues and make collision detection easier.

To reflect a particle off of a wall, check if its x components or y components of position will exceed the bounds and then flip the sign of the other component of the velocity, e.g.

if(Math.Abs(position.x_component + velocity.x_component * dt) > x_bound) 
    velocity.y_component = -velocity.y_component;

if(Math.Abs(position.y_component + velocity.y_component * dt) > y_bound)
    velocity.x_component = -velocity.x_component;

If you have constant dt, this works quite well, but if it varies you will need to do something more complicated. find the collision point with the box and reflect the part of the vector outside the box in the face that was collided with.

For colliding the particles with each other a distance check is probably best, triggering reflection once the distance is too small. i.e. If they get too close they collide. Reflect the velocity components as though the particles were spheres, so the normal for reflection is the difference of their positions.

You may find this article on gamedev useful too...

Hope this helps.

暗喜 2024-07-20 05:11:15

为什么不看看经典的小行星游戏作为起点呢? 这是一个不使用 DirectX 且采用 c# 的链接

http:// /www.codeproject.com/KB/GDI-plus/asteroids.aspx

Why not have a look at the classic Asteroids game as a starting point? Here is alink to one that doesn't use DirectX and is in c#

http://www.codeproject.com/KB/GDI-plus/asteroids.aspx

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