2020-08-06 23:44:37 +02:00
|
|
|
class Wave2D extends Visual {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.name = "2D Wave";
|
|
|
|
}
|
|
|
|
|
|
|
|
updateData() {
|
|
|
|
let data = audioHandler.getFloatArray();
|
2020-08-08 21:58:15 +02:00
|
|
|
let add = c.width / data.length,
|
|
|
|
x = 0,
|
|
|
|
y = c.height / 2,
|
|
|
|
goTrough = y / 2;
|
2020-08-06 23:44:37 +02:00
|
|
|
let outerLoop = 0;
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
//first
|
|
|
|
this.data[outerLoop] = x;
|
2020-08-08 21:58:15 +02:00
|
|
|
this.data[outerLoop + 1] = y + (data[i] * goTrough);
|
2020-08-06 23:44:37 +02:00
|
|
|
this.data[outerLoop + 2] = data[i];
|
|
|
|
outerLoop += 3;
|
|
|
|
x += add;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
draw(program) {
|
|
|
|
this.prepare(program);
|
|
|
|
let position = this.position,
|
|
|
|
positionBuffer = gl.createBuffer();
|
|
|
|
this.rotate(program);
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.data), gl.DYNAMIC_DRAW);
|
|
|
|
let vao = gl.createVertexArray();
|
|
|
|
gl.bindVertexArray(vao);
|
|
|
|
gl.enableVertexAttribArray(position);
|
|
|
|
gl.vertexAttribPointer(position, 3, gl.FLOAT, true, 0, 0);
|
|
|
|
gl.drawArrays(vConf.get("waveForm", gl.LINE_STRIP), 0, this.data.length / 3);
|
|
|
|
this.afterDraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
rotate(program) {
|
2020-08-08 21:58:15 +02:00
|
|
|
let glHelper = new GLHelper(program);
|
|
|
|
glHelper.project();
|
|
|
|
glHelper.addFudgeFactor(vConf.get("fudgeFactor", 1));
|
|
|
|
glHelper.translate([
|
|
|
|
camera.translate.x,
|
|
|
|
camera.translate.y,
|
|
|
|
camera.translate.z
|
|
|
|
]);
|
|
|
|
glHelper.rotateX(camera.mouse.x);
|
|
|
|
glHelper.rotateY(camera.mouse.y);
|
|
|
|
glHelper.rotateZ(vConf.get("rotation-z", 0));
|
|
|
|
glHelper.applyMatrix();
|
2020-08-06 23:44:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
this.updateFFT(vConf.get('fftSize', 16384));
|
|
|
|
}
|
|
|
|
|
|
|
|
updateFFT(fftSize) {
|
|
|
|
audioHandler.fftSize(fftSize);
|
|
|
|
this.data = new Float32Array(fftSize * 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
prepare(program) {
|
|
|
|
this.position = gl.getAttribLocation(program, "a_position");
|
2020-08-08 21:58:15 +02:00
|
|
|
//GLHelper.uniform1f(program, "u_fudgeFactor", vConf.get("fudgeFactor", 1));
|
|
|
|
GLHelper.uniform3fv(program, "u_lightPos", vConf.get("light", [0, 5, -56]));
|
2020-08-06 23:44:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
afterDraw() {
|
|
|
|
TDUtils.updateRotate('rotation-x', 0);
|
|
|
|
TDUtils.updateRotate('rotation-y', 0);
|
|
|
|
TDUtils.updateRotate('rotation-z', 0);
|
|
|
|
vConf.save();
|
|
|
|
}
|
|
|
|
}
|