简体   繁体   English

如何按经过时间缩放二维波模拟?

[英]How to scale a 2D wave simulation by elapsed time?

I have a wave simulation with values calculated like this: (pseudocode)我有一个波浪模拟,其计算值如下:(伪代码)

for(x):
  for(y):
    new_value = (current[x-1,y] + current[x+1,y] + current[x,y-1] + current[x,y+1]) / 2 - previous[x, y]
    new_value -= new_value * damp
    previous[x, y] = new_value

swap(current, previous)

Double the average of surrounding points minus previous value for that point.将周围点的平均值减去该点的先前值加倍。

Right now the change happens every frame so how fast it goes is dependent on the framerate.现在变化发生在每一帧,所以它的速度取决于帧速率。 The problem is, I can't figure out how to scale this process by elapsed time.问题是,我不知道如何通过经过的时间来扩展这个过程。 I tried getting the difference between old and new value and scaling it, but that doesn't work at all;我尝试获取新旧值之间的差异并对其进行缩放,但这根本不起作用; probably something to do with board swapping but I'm not sure.可能与换板有关,但我不确定。

Can I make it work or do I need a completely different approach?我可以让它工作还是我需要一种完全不同的方法?

Ok I figured it out.好的,我想通了。 My problem was based on the fact that I thought I have to run this algorithm every frame – I don't.我的问题是基于这样一个事实,即我认为我必须每帧都运行这个算法——我没有。 If you just run it every few frames then obviously the resulting animation is not smooth;如果你只是每隔几帧运行一次,那么显然生成的动画并不流畅; but I didn't consider that you can just do linear interpolation to get smooth transition from old state to new state which produces a result I'm happy with.但我不认为你可以只做线性插值来获得从旧状态到新状态的平滑过渡,这会产生我满意的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM