|
@@ -203,6 +203,15 @@ export default class GerstnerWavesComponent extends RE.Component {
|
|
|
this.elapsed += RE.Runtime.deltaTime;
|
|
|
(this.object3d as any).material.uniforms.clock.value = this.elapsed
|
|
|
}
|
|
|
+
|
|
|
+ getHeightAt(position: THREE.Vector3) {
|
|
|
+ let height = 0
|
|
|
+ let coords = new THREE.Vector2(position.x, position.z)
|
|
|
+ this.wave.waves.forEach((wave) => {
|
|
|
+ height += this.wave.calcWaveH(wave, coords, this.elapsed)
|
|
|
+ })
|
|
|
+ return height
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
RE.registerComponent(GerstnerWavesComponent);
|
|
@@ -230,7 +239,7 @@ class GerstnerWave {
|
|
|
}
|
|
|
|
|
|
calcWaveH( w, coord, time ){
|
|
|
- const dir = new THREE.Vector2( w.dir ).normalize();
|
|
|
+ const dir = new THREE.Vector2( w.dir[0], w.dir[1] ).normalize();
|
|
|
const k = 6.283185307179586 / w.wavelen; // Phase Increment
|
|
|
const c = Math.sqrt( 9.8 / k ); // Phase Speed. Higher the wave, the faster it moves, Gravity Constant
|
|
|
const f = k * ( GerstnerWave.dot( dir, coord ) - c * time ); // Frequency - Specific time in Phase : PhaseInc * ( Angle - PhaseSpeed * Time )
|