I've created a cube in WebGL. I have an animation in mind but am struggling with make it come together.
The full code is roughly 150 lns of code so here's a working sample: Working Plunkr Code
Here's a video wireframe of the animation, I'm trying to achieve: https://youtu.be/sZeBm8EM3mw
1 -The animations sets an anchor point to the bottom left of the cube.
2 -The animation scales the cube from the anchor point.
3 -The animations rotates the cube from the anchor point roughly halfway through scale.
shaders: (Vertex)
attribute vec4 coords;
attribute float pointSize;
uniform mat4 transformMatrix;
attribute vec4 colors;
varying vec4 varyingColors;
uniform mat4 perspectiveMatrix;
void main(void) {
gl_Position = perspectiveMatrix * transformMatrix * coords;
gl_PointSize = pointSize;
varyingColors = colors;
}
(Fragment)
precision mediump float;
uniform vec4 color;
varying vec4 varyingColors;
void main(void) {
gl_FragColor = varyingColors;
}
I'm using gl-matrix to do wall the matrix transformation
Transformations would go in the draw fn and use the gl-matrix mat4.
function draw() {
var transformMatrix = gl.getUniformLocation(shaderProgram, "transformMatrix");
gl.uniformMatrix4fv(transformMatrix, false, matrix);
// mat4.rotateY(matrix, matrix, 0.01); // This is example of rotations
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawElements(gl.TRIANGLES, indexCount, gl.UNSIGNED_BYTE, 0);
requestAnimationFrame(draw);
}