旋转方向向量(three.js) [英] Direction vector to a rotation (three.js)

查看:112
本文介绍了旋转方向向量(three.js)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试旋转行星表面上的箭头以面向其行进方向.我可以从表面法线获得方向向量和向上向量.我将如何将其转换为箭头旋转的四元数.我正在使用three.js,所以他们提供的任何我可以使用的建议方法都会很有用.干杯.

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.

我目前掌握的信息.

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 );

推荐答案

Try (with myDirectionVector):

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);

这篇关于旋转方向向量(three.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆