【发布时间】:2012-06-26 02:49:36
【问题描述】:
我正在使用 SplineCurve3 仅在 X 和 Y 轴上绘制一条线,我有一个立方体通过使用 spline.getPoint(t) 成功地沿这条线制作动画,其中 t 时间为 0-1。我正在尝试通过使用点积的 Y 向上向量将立方体定向到直线。
它几乎是对齐的,但稍微偏了一点。我以为我会使用 Y 向量和当前点的切线的点积作为将四元数旋转到的角度。
这是我的渲染函数:
function render() {
var updateMatrix = new THREE.Matrix4();
updateMatrix.setPosition(spline.getPoint(t));
var angle = new THREE.Vector3(0,1,0).dot(spline.getTangent(t).normalize());
var quat = new THREE.Quaternion;
quat.setFromAxisAngle(new THREE.Vector3(0,0,1), angle);
updateMatrix.setRotationFromQuaternion(quat);
marker.rotation.getRotationFromMatrix(updateMatrix);
marker.matrixWorld = updateMatrix;
t = (t >= 1) ? 0 : t += 0.002;
renderer.render(scene, camera);
}
这是一个演示我的问题的小提琴,谁能告诉我旋转方面哪里出了问题?
您可以编辑我的 - jsfiddle example
【问题讨论】:
-
我知道这是一篇旧帖子,但想扔掉一个较小的版本,其他人可能会觉得有用:
code obj.position.copy(spline.getPoint( t )); obj.lookAt(spline.getTangent( t ).add(obj.position));
标签: matrix three.js quaternions