Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

javascript - How to switch between Perspective and Orthographic cameras keeping size of desired object

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.

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 );

It is incorrect.

Update:

I get it I will post an answer with codepen link

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

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 );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...