animationmatrixgl-matrix

How to understand/use gl-matrix function fromRotationTranslationScale()


I have a cube in GL in this plunkr that looks like this: enter image description here

I would like to scale, rotate and translate the cube from a pivot. to hopefully make it animate like https://www.youtube.com/watch?v=sZeBm8EM3mw&feature=youtu.be

For this transformation I'll be using: gl-matrix. luckily this transformation has a method for this under mat4.fromRotationTranslationScale()

Problem is I'm have a hell of a time just using the method? No errors, just the default implementation removed the cube from the screen.

mat4.fromRotationTranslationScale(
  matrix,
  quat.create(), 
  vec3.create(),
  vec3.create()
);

(static) fromRotationTranslationScale(out, q, v, s) → {mat4}

Creates a matrix from a quaternion rotation, vector translation and vector scale.

Parameters:

Name    Type    Description
out mat4    mat4 receiving operation result
q   quat4   Rotation quaternion
v   vec3    Translation vector
s   vec3    Scaling vector

Question:

Am I using fromRotationTranslationScale incorrectly? If so, where am I going wrong. if not, how can get some kind of feedback to play around with.

I'm weak with the math but I feel like I can reverse engineer and learn with your help ;).


Solution

  • I guess your problem is the scale vector. Indeed, I suppose the default vector values are 0.0,0.0,0.0 and if you put this scale parameter into the transformation, your object disapear since it have a size of 0.0... and, 0 is too small to be visible :)

    The good idententy values to pass to this kind of function are the following:

    //             X    Y    Z    W
    Quaternion  =  0.0, 0.0, 0.0, 1.0
    Translation =  0.0, 0.0, 0.0
    Scale       =  1.0, 1.0, 1.0
    

    This corresponds to the identity matrix:

     1.0  0.0  0.0  0.0
     0.0  1.0  0.0  0.0
     0.0  0.0  1.0  0.0
     0.0  0.0  0.0  1.0
    

    You can notice the diagonal of 1.0, if you put scale values to 0.0 this diagonal becomes filled by 0.0, then all vectors (vertices positions for example) transformed by this matrix are multiplied on all axis by 0.0, which gives 0.0 everywhere.