【问题标题】:Find the coordinates of the topleft of the canvas on the xy plane given a camera给定相机,在 xy 平面上找到画布左上角的坐标
【发布时间】:2013-07-07 15:31:43
【问题描述】:

我认为这是获得 xyplane 的好方法(如果这是错误的或有更好的方法,请告诉我):

    xyplane = new THREE.Plane().setFromCoplanarPoints(
        new THREE.Vector3(0, 0, 0),
        new THREE.Vector3(10, 15, 0),
        new THREE.Vector3(100, -90, 0),
    );

我有一台相机,它恰好位于(0, 0, 1000),正在查看原点。我可以找到一个正好位于观察口左上角的坐标:

    projector = new THREE.Projector();
    topleft = new THREE.Vector3(-1, 1, 0);
    through = projector.unprojectVector(topleft, camera);

through 然后是THREE.Vector3 {x: -31.425217496422327, y: 22.169468302342334, z: 900.0000201165681},它完美地位于画布的左上角。但是,我想找到 z = 0 的等效点。我尝试用射线来做到这一点;但是,我失败了。

    ray = new THREE.Ray(camera.position, through);
    point = ray.intersectPlane(xyplane);

point 然后是{x: 34.91690754890442, y: -24.632742007573448, z: 0},甚至不接近。我误解了一些基本的东西。我将研究Coordinates of intersection between Ray and Plane 和其他人,同时我试图弄清楚这一点。也许有人可以用通俗的语言解释。

【问题讨论】:

  • 你快到了。 THREE.Ray() 的第二个参数必须是从相机指向目标点的单位长度方向向量。
  • 感谢@WestLangley,您的评论说得很清楚。

标签: three.js


【解决方案1】:

好的,感谢@WestLangley 的评论。 through 变量不是 Ray 构造函数的正确第二个参数。我们需要一个单位向量来表示方向。通过相机位置和through 点,我们可以得到一个方向向量:

    direction = through.sub(camera.position).normalize();

然后其余的按预期工作:

    ray = new THREE.Ray(camera.position, direction);
    p = ray.intersectPlane(xyplane);

【讨论】:

    猜你喜欢
    • 2022-06-15
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    • 2011-02-02
    相关资源
    最近更新 更多