【问题标题】:Position camera relative to plane相对于平面定位相机
【发布时间】:2015-03-23 06:35:44
【问题描述】:

我有一个位于某个 x、y、z 位置的平面,它在 3d 空间中旋转。 我知道如何将相机定位在它的位置,只需设置相同的坐标和旋转,但我想把相机放在一定的距离。有人可以告诉我执行此操作的公式,或者是否存在一个 three.js 方法来实现图像中的结果?

look at the image of the camera positioned in front of a rotated plane at a certain distance

谢谢!

【问题讨论】:

    标签: 3d camera three.js position


    【解决方案1】:

    您可以使用垂直于平面的向量计算相机的位置:

    camera_position = plane_position + distance_to_the_plane * plane_normal
    

    或

    camera_position = plane_position - distance_to_the_plane * plane_normal
    

    将相机放在飞机的另一边。

    之后,您可以旋转相机以指向矢量:

    -plane_normal
    

    使用相机对象的lookAt成员

    这是您在评论中询问的程序:

    var distance = 100; // for example
    
    camera.position.copy( plane.normal ).multiplyScalar( distance ).add( plane.position );
    var direction = new THREE.Vector3();
    direction.copy( plane.normal ).negate();
    camera.lookAt( direction );
    

    【讨论】:

    • 非常感谢您的回答,我在three.js方面不是那么先进,所以如果您能给出实际的例子会很棒。例如,如果我有这样的飞机:plane.x = 100;平面.y = 400;平面.z = 500;平面.旋转.x = 0.4;平面.旋转.y = 0.1;平面.旋转.z = 0.4; camera.position.set(0,0,0); camera.rotation.set(0,0,0);实际上,我应该写下什么来规范化并转换为您向我解释的代码?没看懂很抱歉,谢谢
    • 非常感谢您的解释,它有效! :) 你认为它也可以应用于 css3d 渲染的 div 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 1970-01-01
    相关资源
    最近更新 更多