It may look like a dummy question for most of the three.js developers but, how can a translation be extracted from the transformation matrix?
Actually I am extracting it manually pointing to the matrix array positions (12, 13, 14).
Thanks in advance.
If you want to extract the translation component from the matrix, then use this pattern:
var vec = new THREE.Vector3();
vec.setFromMatrixPosition( matrix4 );
Use Matrix4.decompose()
only if you need the translation, quaternion and scale components.
three.js r.73
Matrix4
has a decompose
method that is capable of exactly that.
var mat = /* ... */;
var translation = new THREE.Vector3(),
rotation = new THREE.Quaternion(),
scale = new THREE.Vector3();
mat.decompose(translation, rotation, scale);
Of course, if you are only interested in the translation then you are best off doing what you are currently doing. Behind the scenes, decompose
simply extracts elements 12, 13, and 14 from mat.elements
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With