Three.js - 视图宽度 [英] Three.js - Width of view

查看:218
本文介绍了Three.js - 视图宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法找出场景渲染部分的宽度?

Is there a way to find out the width of a rendered portion of the scene?

例如,如果我们有一个宽度为100的网格,但是使用一定级别的缩放进行渲染...我该如何计算网格部分的宽度是在屏幕上呈现的?

For example, if we have a mesh of width 100, but rendered with a certain level of zoom...how can I calculate the width of the portion of the mesh that is being rendered in the screen?

推荐答案

你必须在这里准确。

您可以根据摄像机的视野, camera.fov 计算可见的矩形区域,以及给定距离, dist ,来自相机。

You can calculate the visible rectangular region given the camera's field-of-view, camera.fov, and a given distance, dist, from the camera.

由于物体可能具有深度,因此您必须在网格中选择一个平面,并在该距离处进行计算。

Since the object presumably has depth, you have to pick one plane through the mesh, and do the calculation at that distance.

以下是给定距离高度和宽度的方法>来自相机的。

Here is how to calculate the visible height and width for a given distance dist from the camera.

var vFOV = THREE.Math.degToRad( camera.fov ); // convert vertical fov to radians

var height = 2 * Math.tan( vFOV / 2 ) * dist; // visible height

var width = height * camera.aspect;           // visible width

three.js r.87

three.js r.87

这篇关于Three.js - 视图宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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