Native object(s) to convert quaternion to rotation matrix ??
Hi there,
is there a couple of objects to convert quaternion to rotation matrix ??
I guess there isn't.
I looked for them ... no success.
so I decided to use jit.gen...
posting the whole calculation in another thread more global.
you can convert a quaternion to a rotation matrix using the jit.anim.node.
retrieve the @transform attribute (after applying the rotation and updating the node), and discard the last row and last column. this is the rotation matrix.
note, this will also contain any scaling transformations, so don't modify the @scale attribute.
omg.
at least, I would have dived further in jit.gen !!
okay about the rot matrix easily retrievable.
I now have to multiply it by all objects coordinates in my global named matrix.
... digging that right now.
especially there are many ways... I'd go with jit.gen because i really begin to like it and indeed, it is very very fast compared to my first poor design in JAVA :-/
(struggling with a so basic stuff... using this matrix 3x3 mono plane with my 4 planes 1xn matrix with objects coordinates.. planes confuse me)
Robert, can you do something similar to do the opposite: translate a rotation or transform matrix to quaternion?
best,
Zachary
hi zachary. i was about to answer yes. setting the @transform attribute of jit.anim.node decomposes the proper position, quat, and scale values into the respective attributes.
however, when testing this, it looks like there's a bug with the quat attribute not getting properly updated.
this will be fixed for the next update.
here's how it's supposed to work, for future reference:
interesting to have the conversion in both direction.
Robert, would you help me with my (last straight) road to matrix multiplication ?
I tried using [jit.mult], I also tried to pack unpack to play with planes but without success.
hi julien. transforming a vector by a rotation matrix is not a simple pointwise multiplication of the the cells.
i'm not sure if that's what you're trying to do.
in any case, if you have a bunch of vectors (object positions) and a rotation matrix, it should not be too difficult to write the code (javascript or otherwise) to transform the vectors.
or use jit.la.mult, which will multiply a vector (jit.matrix 1 float32 3) by a rotation matrix (jit.matirx 1 float32 3 3)
plenty of online information on this:
http://www.gamespp.com/tutorials/matrixTransformationTutorial04.html
http://wally.cs.iupui.edu/n351/3D/matrix.html
This is "only" for calculating my azimuth & elevation.
For this purpose, I need to apply the rotation matrix given by the cam to each objects coordinates... right?
ok for your links and especially the pure matrix objects.
before that I'll check and recheck the first statement of this post =-)
(just to add: this has to happen each frame very fast.. I'd be afraid to use JS for that but I'll try for sure if you would confirm if my vectors transformation makes sense to calculate ae)
Hi guys,
I'm trying to put this code in js: http://www.gamespp.com/tutorials/matrixTransformationTutorial04.html
Looks like I got it but for some reason I don't get the matrix output of my js to work (outlet 0). I doubled it with a message output and that seems to work fine (outlet 1).
Surely it's something basic but what am I doing wrong here?
Tanx, D.
// JS as text :
// transform.js
inlets=2;
outlets=2;
this.autowatch = 1;
var result_mat = new JitterMatrix(3, "float32", 1, 1);
var vec= new Array(3);
var result = new Array(3);
var mat1
var mat2;
function jit_matrix(mtx_in) {
if(inlet==0){
mat1 = new JitterObject("jit.matrix", mtx_in);
//var cell = mat.getcell(0, 0);
//post(mat1.name);
vec = mat1.getcell(0,0);
result[0] = vec[0] * mat2.getcell(0,0) + vec[1] * mat2.getcell(1,0) + vec[2] * mat2.getcell(2,0) + mat2.getcell(3,0);
result[1] = vec[0] * mat2.getcell(0,1) + vec[1] * mat2.getcell(1,1) + vec[2] * mat2.getcell(2,1) + mat2.getcell(3,1);
result[2] = vec[0] * mat2.getcell(0,2) + vec[1] * mat2.getcell(1,2) + vec[2] * mat2.getcell(2,2) + mat2.getcell(3,2);
result_mat.setall(result[0], result[1] , result[2]);
outlet(0, "jit_matrix", result_mat.name); // output as matrix
outlet(1, result[0] +" "+ result[1] +" "+ result[2]); // output as message
} else {
mat2 = new JitterObject("jit.matrix", mtx_in);
}
}
you need to use "parseFloat" on the args to the setall message, so that javascript will cast from Object to Float.
tanx!
Rob, I'm getting funky results with this. With float inputs it's fine but when I input a decimal (eg. 1.0) it comes out multiplied by then (eg. 10.0) even though the transform matrix is unity. Not sure if it's parseFloat or something else.
// transform.js
inlets=2;
outlets=2;
this.autowatch = 1;
var result_mat = new JitterMatrix(3, "float32", 1, 1);
var vec= new Array(3);
var result = new Array(3);
var mat1
var mat2;
var x;
var y;
var z;
function jit_matrix(mtx_in) {
if(inlet==0){
mat1 = new JitterObject("jit.matrix", mtx_in);
vec = mat1.getcell(0,0);
x = vec[0] * mat2.getcell(0,0) + vec[1] * mat2.getcell(0,1) + vec[2] * mat2.getcell(0,2) + mat2.getcell(0,3);
y = vec[0] * mat2.getcell(1,0) + vec[1] * mat2.getcell(1,1) + vec[2] * mat2.getcell(1,2) + mat2.getcell(1,3);
z = vec[0] * mat2.getcell(2,0) + vec[1] * mat2.getcell(2,1) + vec[2] * mat2.getcell(2,2) + mat2.getcell(2,3);
outlet(1, x+" " +y+" "+z+"n"); // output as message before parseFloat()
result_mat.setcell2d(0,0,parseFloat(x), parseFloat(y), parseFloat(z));
outlet(0, "jit_matrix", result_mat.name); // output as matrix
// outlet(1, result_mat.getcell(0,0)); // output as message
} else {
mat2 = new JitterObject("jit.matrix", mtx_in);
}
}
Also, the 4th row of the transform matrix - translation - doesn't seem to have any effect. Is it perhaps the use of the 'vec' array that's messing things up?
I made an ugly jit.gen alternative for now but I think it's buggy as well. Rotating around X seems fine but around Y and Z is funky. Don't see why. Anyone?
The math's according to the links by Wes:
http://www.gamespp.com/tutorials/matrixTransformationTutorial04.html
http://www.gamespp.com/tutorials/matrixTransformationTutorial05.html
i don't think you were building your rotation matrix properly.
below is a patch using gen, based on this link:
http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToMatrix/index.htm
The 4x4 matrix is not just for rotation but also translation and scaling. What I'm trying to achieve is aligning 2 kinect skeletons taken from different camera angles. I have Meshlab calculate the transform between the 2 by ICP (iterative closest point) registration. It returns a transform matrix like this:
-0.35 -0.03 -0.94 0.0
0.16 0.98 -0.09 0.0
0.92 -0.18 -0.34 0.0
-2.82 0.76 4.2 1.0
Since the math in Wes' link works with 4x4 matrices I was hoping to get it to work that way.