diff options
Diffstat (limited to 'Water.gd')
-rw-r--r-- | Water.gd | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -78,4 +78,36 @@ func _set_time(val): func _physics_process(delta): self._time += delta + #self._time = 0.0 +func gertsner_wave(pos, idx): + if idx >= waves.size(): return 0.0 + var wave = waves[idx] + var k = wave._k + var a = wave._a + var t = wave._t + + var d = wave.direction.normalized() + var f = k * (d.dot(Vector2(pos.x,pos.z)) - t) + + var tmp = a * cos(f) + var new_pos = Vector3(d.x * tmp, a * sin(f), d.y * tmp) + + return new_pos + +func sample_wave(pos): + var new_pos = Vector3(pos.x,0,pos.z) + for idx in waves.size(): + new_pos += gertsner_wave(pos, idx) + return new_pos + +func height(pos): + var old_pos = pos + var y = old_pos.y + for _i in range(2): + var new_pos = sample_wave(old_pos) + y = new_pos.y + new_pos = old_pos - (new_pos - old_pos) + old_pos = new_pos + y += self.global_transform.origin.y + return y |