]> git.r.bdr.sh - rbdr/lissajous/blob - lib/systems/lissajous_position_updater.js
0f5792dffd26dcae307cb48d0b9e6d4ecd8c3689
[rbdr/lissajous] / lib / systems / lissajous_position_updater.js
1 import { System } from '@serpentity/serpentity';
2 import LissajousCurve from '../nodes/lissajous_curve';
3
4 const internals = {
5 kAmplitude: 0.8,
6 kPeriod: Math.PI * 12000000
7 };
8
9 export default class WebGLRenderer extends System {
10
11 constructor() {
12
13 super();
14 }
15
16 added(engine){
17
18 this.curves = engine.getNodes(LissajousCurve);
19 this.time = 0;
20 }
21
22 removed(){
23
24 this.curves = undefined;
25 this.time = undefined;
26 }
27
28 update(dt){
29
30 this.time = (this.time + dt / 100) % internals.kPeriod;
31
32 for (const curve of this.curves) {
33 curve.position.x = this._getPosition(internals.kAmplitude, curve.frequency.a, this.time, 0);
34 curve.position.y = this._getPosition(internals.kAmplitude, curve.frequency.b, this.time, 0);
35 curve.position.z = this._getPosition(internals.kAmplitude, curve.frequency.c, this.time, 0);
36 }
37 console.log('UP');
38 }
39
40 _getPosition(amplitude, frequency, time, phaseShift) {
41
42 return amplitude * Math.sin(frequency * time + phaseShift);
43 }
44 };