1

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 ;).

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

I can make a whole new question but would you have any idea(libraries) that would help to interpolate over a starting matrix to final matrix value from mat4.fromRotationTranslationScale(x,y,z,w) inside my draw() requestAnimationFrame()?
i could give you answere on how to achieve correcte animation interpolation using quaternion/matrix, but independenttly from any "library". I know how to do and what to do, but not "which" library does it (except mine, which is not even in beta status). I can begin by giving you a clue for quaternions: searchs "SLERP" and "Fast SLERP" in google
glmatrix.net/docs/quat.js.html#line585 ayeeeee I think your clue clue is helping!!!
Yep, that's what you need. However be carefull, this sqlerp function take 2 "control points" in addition comparing the more traditionnal (and usually sufficient) slerp. Begin with what is at the line 217, way sufficient I think.
As i edited before, i suggest you to begin with simple linear interpolation slerp, you'll have all the time to explore bézier curves after...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.