计算相机近距离和远距离平面边界 [英] Calculating the camera near and far plane bounds

查看:96
本文介绍了计算相机近距离和远距离平面边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行计算附近/中提到的计算使用THREE.Frustum 远平面顶点。我使用了问题和答案, https://stackoverflow.com/a/12022005/299037 ,完整的工作示例, http://jsfiddle.net/cZb66/ ,将粒子放置在在这种情况下,近平面很近,以至于粒子会遮挡视线。由于某种原因,远平面点不在相机的范围内(窗口的角落),正如我预期的那样。

I'm trying to perform the calculations mentioned in Calculate near/far plane vertices using THREE.Frustum. I used the question and the answer, https://stackoverflow.com/a/12022005/299037, to put together a complete working example, http://jsfiddle.net/cZb66/, that places particles at the bounds of the far plane, the near plane in this case is so close that the particles would obscure the view. For some reason the far plane points are not at the extents of the camera (the corners of the window) as I would have expected them to be.

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 转换为弧度。

You were close. camera.fov is in degrees. You needed to convert camera.fov to radians in your calculation of the visible height.

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

还有一些其他错误。这是一个工作小提琴:

There were a few other errors. Here is a working fiddle:

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

three.js r.66

three.js r.66

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

Updated jsfiddle link to version with 1x1 near particles.

这篇关于计算相机近距离和远距离平面边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆