diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-05-06 22:28:48 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-05-06 22:28:48 +0200 |
| commit | 5f6ef99eae91f53239f08143cead1249893fef81 (patch) | |
| tree | fac495ea31140060ccd0b916897bbd7adf72fc2f /lib/systems/lissajous_position_updater.js | |
Initial commit
Diffstat (limited to 'lib/systems/lissajous_position_updater.js')
| -rw-r--r-- | lib/systems/lissajous_position_updater.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/systems/lissajous_position_updater.js b/lib/systems/lissajous_position_updater.js new file mode 100644 index 0000000..0f5792d --- /dev/null +++ b/lib/systems/lissajous_position_updater.js @@ -0,0 +1,44 @@ +import { System } from '@serpentity/serpentity'; +import LissajousCurve from '../nodes/lissajous_curve'; + +const internals = { + kAmplitude: 0.8, + kPeriod: Math.PI * 12000000 +}; + +export default class WebGLRenderer extends System { + + constructor() { + + super(); + } + + added(engine){ + + this.curves = engine.getNodes(LissajousCurve); + this.time = 0; + } + + removed(){ + + this.curves = undefined; + this.time = undefined; + } + + update(dt){ + + this.time = (this.time + dt / 100) % internals.kPeriod; + + for (const curve of this.curves) { + curve.position.x = this._getPosition(internals.kAmplitude, curve.frequency.a, this.time, 0); + curve.position.y = this._getPosition(internals.kAmplitude, curve.frequency.b, this.time, 0); + curve.position.z = this._getPosition(internals.kAmplitude, curve.frequency.c, this.time, 0); + } + console.log('UP'); + } + + _getPosition(amplitude, frequency, time, phaseShift) { + + return amplitude * Math.sin(frequency * time + phaseShift); + } +}; |