从matrix4()获取翻译

时间:2016-01-28 13:15:59

标签: three.js

对于大多数三个开发者来说,它看起来像是一个虚拟问题但是,如何从转换矩阵中提取翻译呢?

实际上我手动指向矩阵阵列位置(12,13,14)。

提前致谢。

2 个答案:

答案 0 :(得分:3)

如果要从矩阵中提取平移组件,请使用以下模式:

var vec = new THREE.Vector3();
vec.setFromMatrixPosition( matrix4 );

仅在需要翻译,四元数和比例组件时才使用Matrix4.decompose()

three.js r.73

答案 1 :(得分:2)

Matrix4 has a decompose method能够做到这一点。

var mat = /* ... */;
var translation = new THREE.Vector3(),
  rotation = new THREE.Quaternion(),
  scale = new THREE.Vector3();
mat.decompose(translation, rotation, scale);

当然,如果你只对翻译感兴趣,那么你最好做你目前正在做的事情。 Behind the scenes, decompose simply extracts elements 12, 13, and 14 from mat.elements