import { System } from '@serpentity/serpentity'; import LissajousCurve from '../nodes/lissajous_curve'; const internals = { kAmplitude: 1, kPeriod: Math.PI * 12000000 }; /** * Calculates the lissajous curve over time * NOTE: This shouldn't store data, I should have a different entity for * the actual drawable vertices. Either put the storage in the curve, or * create a separate entity. */ export default class WebGLRenderer extends System { constructor() { super(); } added(engine){ this.curves = engine.getNodes(LissajousCurve); this.time = 0; } removed(){ delete this.curves; delete this.time; } update(dt){ this.time = (this.time + dt / 500) % internals.kPeriod; for (const curve of this.curves) { curve.position.x = this._getPosition(curve.amplitude.a, curve.frequency.a, this.time, curve.phase.a); curve.position.y = this._getPosition(curve.amplitude.b, curve.frequency.b, this.time, curve.phase.b); curve.position.z = this._getPosition(curve.amplitude.c, curve.frequency.c, this.time, curve.phase.c); } } _getPosition(amplitude, frequency, time, phaseShift) { return amplitude * Math.sin(frequency * time + phaseShift); } };