【问题标题】:How to rotate object with camera three.js如何用相机three.js旋转对象
【发布时间】:2023-04-05 15:58:01
【问题描述】:

您好,我正在尝试让一个可怜的人跟随相机,这样我就可以实现步枪取景器的效果。我正在使用 OrbitControl。当我检查 camera.rotation.y 时,它只显示范围是从 -PI/2 到 PI/2,而我可以将相机旋转 360 度。我无法理解它,请帮忙!

到目前为止,我已经到了那里(这只是我代码的一部分):

    pivot = new THREE.Object3D();
    pivot.add(viewfinder);//adding viewfinder as a child of pivot
    scene.add( pivot );

以后

    pivot.rotation.y =  camera.rotation.y; 

这允许旋转我的取景器,但由于某种原因,它完全是由 Pi/2 移动的,所以我从当前相机位置中扣除了它,我得到了这个:

   pivot.rotation.y =  (camera.rotation.y - (Math.PI/2)) ;

这让我可以用相机旋转取景器,但只能在 180 度范围内。如何将其旋转 360 度? 请帮我。 谢谢。

【问题讨论】:

  • 也许this 就是你所指的。

标签: javascript camera three.js rotation


【解决方案1】:

我猜你想让网格总是面向你的相机,对吧?您可以使用相机矩阵来设置网格旋转,mesh.rotation.setRotationFromMatrix(camera.matrix),但如果您的网格有父实体,请小心。或者您可以使用lookAt() 函数mesh.lookAt(camera.position),它们都可以正常工作。

【讨论】:

    猜你喜欢
    • 2013-08-30
    • 2014-05-19
    • 1970-01-01
    • 2019-06-29
    • 2021-08-23
    • 2013-07-15
    • 2016-01-20
    • 1970-01-01
    • 2015-12-01
    相关资源
    最近更新 更多