]>
Commit | Line | Data |
---|---|---|
5f6ef99e RBR |
1 | import { System } from '@serpentity/serpentity'; |
2 | import LissajousCurve from '../nodes/lissajous_curve'; | |
3 | ||
4 | const internals = { | |
362f9116 | 5 | kAmplitude: 1, |
5f6ef99e RBR |
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 | ||
362f9116 RBR |
24 | delete this.curves; |
25 | delete this.time; | |
5f6ef99e RBR |
26 | } |
27 | ||
28 | update(dt){ | |
29 | ||
6a87c253 | 30 | this.time = (this.time + dt / 500) % internals.kPeriod; |
5f6ef99e RBR |
31 | |
32 | for (const curve of this.curves) { | |
362f9116 RBR |
33 | curve.position.x = this._getPosition(curve.amplitude.a, curve.frequency.a, this.time, 0); |
34 | curve.position.y = this._getPosition(curve.amplitude.b, curve.frequency.b, this.time, 0); | |
35 | curve.position.z = this._getPosition(curve.amplitude.c, curve.frequency.c, this.time, 0); | |
5f6ef99e | 36 | } |
5f6ef99e RBR |
37 | } |
38 | ||
39 | _getPosition(amplitude, frequency, time, phaseShift) { | |
40 | ||
41 | return amplitude * Math.sin(frequency * time + phaseShift); | |
42 | } | |
43 | }; |