我无法确定物体相对于相机的角度,我试图用跟随它的相机编码太空船。我有相机跟随船,但相机的旋转有时是一点点,这是我的相机代码: `var focalpoint = new THREE.Vector3( actor.position.x, actor.position.y, actor.position.z + 14 );
//move camera closer to the object if it gets too far away
var calculatedDistance = distance(camera.position, actor.position);
var cameraTolerance = calculatedDistance - this.cameradistance.min;
var closingvelocity = cameraTolerance * 0.02;
if(calculatedDistance > this.cameradistance.max)cameravelocity.z = -closingvelocity;
if(calculatedDistance < this.cameradistance.min)cameravelocity.z = closingvelocity;
//slow down the camera
if(calculatedDistance < this.cameradistance.max && calculatedDistance > this.cameradistance.min){
cameravelocity.z = 0;
}
camera.translateX( cameravelocity.x );
camera.translateY( cameravelocity.y );
camera.translateZ( cameravelocity.z );
camera.lookAt(focalpoint);
camera.rotation.z = 0;`
现在我需要限制宇宙飞船(演员)的旋转,以便它不会开始飞向相机,并修复相机翻转问题。所以我需要弄清楚如何找到演员相对于相机的旋转,我完全不知道从哪里开始计算甚至如何。
哦,请堆叠溢出的众神听到我的电话!
答案 0 :(得分:1)
通过反转目标的旋转找到答案,然后如此相乘:
var rotationOffset = actor.quaternion.clone().inverse();
var rotation = camera.quaternion.clone().multiply( rotationOffset );