我有情景情景
var camera = new THREE.PerspectiveCamera(...);
scene.add(camera);
var parent = new THREE.Object3D();
parent.position.set(1,2,3);
scene.add(parent);
var child = new THREE.Object3D();
child.position.set(4,5,6);
parent.add(child);
var v = new THREE.Vector3().copy(child.position);
child.localToWorld(v);
child.rotation.z = Math.atan2( ( v.x - camera.position.x ), ( v.y - camera.position.y ) );
它可以正常工作,并且孩子在Z轴上面向相机。
当我这样做时:
parent.rotation.set(1,2,3); // or whatever
子对象受旋转影响,如何避免该旋转,并使子对象保持相同的旋转,就像旋转父对象之前一样(通过父变换将局部旋转更新为视觉上不变),但要保持全局位置因父对象而改变旋转?
答案 0 :(得分:0)
设置子对象的旋转后,请尝试以下操作:
var matrix = new Matrix4();
var quaternion = new THREE.Quaternion();
parent.updateMatrixWorld(); // ensure matrixWorld is up to date
matrix.extractRotation( parent.matrixWorld );
quaternion.setFromRotationMatrix( matrix );
child.quaternion.premultiply( quaternion.inverse() );