Is there a way to create a matrix from a rotation quaternion and a translation vector without converting both to matrices first?
What I'm doing right now (using my own little math library) is:
var rotation = new quat(...);
var translation = new vec3(...);
var rotationMatrix = new mat4(rotation);
var translationMatrix = new mat4(translation);
var matrix = mat4.product(translationMatrix, rotationMatrix);
Instead, I'd like to do the following:
var rotation = new quat(...);
var translation = new vec3(...);
var matrix = new mat4(rotation, translation);
It seems inefficient and wasteful to allocate two temporary matrices, especially in Javascript, where they have to be allocated on the heap.
Thank you!
The top left 3×3 submatrix is the rotation, the top right 3×1 vector is the translation, the bottom row is (0,0,0,1). (This is assuming that you're multiplying matrix times column vector, not row vector times matrix. Otherwise the situation would be transposed.) So yes, it should be easy to adapt the constructor which creates the matrix from a rotation to also cater for the case where there is an extra translation vector. Or you might create the matrix from the rotation and then change some of its entries to incorporate the translation.
Note that this assumes your notation to mean “rotate then translate”. If it's the other way round, then you'd have to apply the rotation to the translation vector before including that into the matrix.