J'ai créé un cube dans WebGL. J'ai une animation en tête mais j'ai du mal à la faire se rencontrer.Comment keyframe animer une échelle et faire pivoter à partir d'un point d'ancrage d'un cube webGL?
Le code complet est d'environ 150 LNS de code Voici donc un exemple de travail: Working Plunkr Code
Voici un wireframe vidéo de l'animation, je suis en train de réaliser: https://youtu.be/sZeBm8EM3mw
1 animations -Les définit un point d'ancrage en bas à gauche du cube. 2 -L'animation redimensionne le cube à partir du point d'ancrage.
3 -Les animations font tourner le cube du point d'ancrage à peu près à mi-chemin de l'échelle.
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;
}
J'utilise gl-matrix faire murer la transformation de la matrice
transformations irait au tirage au sort fn et utilisez le mat4 gl-matrix.
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);
}
QQ: couldfromRotationTranslationScaleOrigin() de gl-matrix est la bonne formule de transformation? http://glmatrix.net/docs/mat4.js.html#line1094 –
Oui, il semble que la formule soit bien optimisée. le 'out [12] = v [0] + ox' est le dernier' pivot * translate' tandis que '- (out [0] * ox + out [4] * oy + out [8] * oz)' correspond à 'échelle inverse (pivot) * * rotation *. –
Ok! Maintenant il faut juste apprendre à l'utiliser lol merci! –