Direction vector to a rotation (three.js)

末鹿安然 提交于 2019-12-08 05:47:38

问题


I'm attempting rotate an arrow on the surface of a planet to face the direction it is traveling. I can get the direction vector and the up vector from the surface normal. How would I go about turning this into a quaternion for my arrows rotation. I'm using three.js so any suggested methods they provided that I can use would be useful. Cheers.

The information I have so far.

var upVector = new THREE.Vector3();
upVector.subVectors( new THREE.Vector3(0,0,0), lastVec );

var dirVector = new THREE.Vector3();
upVector.subVectors( lastVec, destVec );

var sideVector = new THREE.Vector3();
sideVector.crossVectors( dirVector, upVector );

var newUp = new THREE.Vector3();
newUp.crossVectors( dirVector, sideVector );

回答1:


Try (with myDirectionVector):

var mx = new THREE.Matrix4().lookAt(myDirectionVector,new THREE.Vector3(0,0,0),new THREE.Vector3(0,1,0));
var qt = new THREE.Quaternion().setFromRotationMatrix(mx);


来源:https://stackoverflow.com/questions/32849600/direction-vector-to-a-rotation-three-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!