gpt4 book ai didi

javascript - 计算相机近平面和远平面边界

转载 作者:行者123 更新时间:2023-11-29 18:16:24 25 4
gpt4 key购买 nike

我正在尝试执行 Calculate near/far plane vertices using THREE.Frustum 中提到的计算.我使用了问题和答案,https://stackoverflow.com/a/12022005/299037 , 组合一个完整的工作示例,http://jsfiddle.net/cZb66/ , 将粒子放置在远平面的边界,在这种情况下,近平面非常接近以至于粒子会遮挡 View 。出于某种原因,远平面点并不像我预期的那样位于相机的范围内(窗口的 Angular 落)。

hNear = 2 * Math.tan(camera.fov / 2) * camera.near; // height
wNear = hNear * camera.aspect; // width

// Far Plane dimensions
hFar = 2 * Math.tan(camera.fov / 2) * camera.far; // height
wFar = hFar * camera.aspect; // width

var farTopLeft = new THREE.Vector3( wFar / 2, hFar / 2, -camera.far );
var farBottomRight = new THREE.Vector3( -wFar / 2, -hFar / 2, -camera.far );
var farTopRight = new THREE.Vector3( -wFar / 2, hFar / 2, -camera.far );
var farBottomLeft = new THREE.Vector3( wFar / 2, -hFar / 2, -camera.far );

// adjust the vectors to the camera location and direction
camera.updateMatrixWorld();
farTopLeft.applyMatrix4( camera.matrixWorld );
farBottomRight.applyMatrix4( camera.matrixWorld );
farTopRight.applyMatrix4(camera.matrixWorld);
farBottomLeft.applyMatrix4(camera.matrixWorld);

var z = 1;
var farParticles = new THREE.Geometry();
farParticles.vertices.push(new THREE.Vector3(farTopLeft.x, farTopLeft.y, z));
farParticles.vertices.push(new THREE.Vector3(farBottomRight.x, farBottomRight.y, z));
farParticles.vertices.push(new THREE.Vector3(farTopRight.x, farTopRight.y, z));
farParticles.vertices.push(new THREE.Vector3(farBottomLeft.x, farBottomLeft.y, z));
farParticles.vertices.push(new THREE.Vector3(0, 0, 0));

最佳答案

你很接近。 camera.fov 以度为单位。在计算可见高度时,您需要将 camera.fov 转换为弧度。

hNear = 2 * Math.tan( camera.fov * Math.PI / 180 / 2 ) * camera.near;

还有一些其他错误。这是一个工作 fiddle :

http://jsfiddle.net/cZb66/3/

three.js r.66

编辑:将 jsfiddle 链接更新到具有 1x1 近粒子的版本。

关于javascript - 计算相机近平面和远平面边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22934703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com