如何在透视相机和正交相机之间切换,以保持所需对象的大小 [英] How to switch between Perspective and Orthographic cameras keeping size of desired object

查看:515
本文介绍了如何在透视相机和正交相机之间切换,以保持所需对象的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在脚本中在透视"相机和正交"相机之间切换. 我希望物体在一定深度上保持投影尺寸. 我放弃了对几何的了解...

I try to switch between Perspective and Orthographic cameras in my script. I want object on some depth to keep it's projection size. I gave up to understand the geometry...

您能否提供一些指向简单教程的链接对我来说太复杂了.

Could you provide some link to a simple tutorial this is too complicated for me.

对于具有position.z==0的对象,我有:

For object with position.z==0 i have:

perspCamera = new THREE.PerspectiveCamera(45, W / H, 1, 1000);
perspCamera.position.z = 100;

var S=Math.tan((45/180)*Math.PI)*100;
orthoCamera = new THREE.OrthographicCamera( -S, S, S, -S, 1, 1000 );

不正确.

我明白了,我会用Codepen链接发布答案

I get it I will post an answer with codepen link

推荐答案

在透视投影时Z距离和大小之间的关系是:

The relation between Z-distance and size, at perspective projection is:

var fov_y   = 45;
var depht_s = Math.tan(fov_y/2.0 * Math.PI/180.0) * 2.0;

因此正交投影必须为( THREE.OrthographicCamera ):

So the orthographic projection has to be (THREE.OrthographicCamera):

var Z      = 100;
var aspect = W / H;
var size_y = depht_s * Z;
var size_x = depht_s * Z * aspect; 

orthoCamera = new THREE.OrthographicCamera(
    -size_x/2,  size_x/2,
     size_y/2, -size_y/2,
     1, 1000 );

这篇关于如何在透视相机和正交相机之间切换,以保持所需对象的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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