0

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

gman
  • 100,619
  • 31
  • 269
  • 393
Armeen Moon
  • 18,061
  • 35
  • 120
  • 233

1 Answers1

0

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.

  • 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()? – Armeen Moon Oct 13 '17 at 04:34
  • 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 –  Oct 13 '17 at 07:32
  • http://glmatrix.net/docs/quat.js.html#line585 ayeeeee I think your clue clue is helping!!! – Armeen Moon Oct 13 '17 at 14:45
  • 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. –  Oct 13 '17 at 15:09
  • This would only handle rotation of my transformation right? http://glmatrix.net/docs/vec3.js.html#line452 this could handle the others yeah? – Armeen Moon Oct 13 '17 at 15:13
  • 1
    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... –  Oct 13 '17 at 15:16
  • and yes, this will only peforms rotation interpolation, you have to interpolate translation and scale in parallel. And in case you ask for: `interpolation = BeginValue+T*(EndValue-BeginValue)` where `T` is from 0 to 1. You can use this for each x, y and z of translation and scale. –  Oct 13 '17 at 15:22