Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I trying to calculate the max distance the camera can zoom in on a sphere while still displaying all of the sphere on screen.

var dist =  diameter / (2 * Math.tan( camera.fov * (Math.PI/180) / 2 ));

this zooms in to much. The top and bottom of the sphere are clipped. What am i doing wrong?

fiddle

See Question&Answers more detail:os

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

1 Answer

The sphere is being clipped for the same reason that if you stand close to a large sphere you can't see its "north pole".

You need to do the calculation for a plane that passes through the front of the sphere, not its center.

As a result, the quantity you calculated is the minimum distance to the front of the sphere. The minimum distance to its center is the quantity you calculated plus the sphere's radius.

(Note: this will yield a conservative approximation, due to the curvature of the sphere.)

EDIT: OK, here is the exact answer.

var dist =  radius / ( Math.sin( camera.fov * ( Math.PI / 180 ) / 2 ) );

fiddle: http://jsfiddle.net/x98Fk/3/

The three.js camera field-of-view is the vertical FOV, so this this the result for the vertical direction. If the window is narrower than it is wide, then you have to deal with that issue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...