x


using objects bounds to zoom in object

hi everybody! i am trying to figure out how to calculate the zoom of the object based on its bounds so it fills out the screen completly.i have a lot of objects in the scene and all of them are different sizes, when i click on some of them, the zoom in, the smaller ones dont get zoomed in enough. i have a constant zoom factor which i would like to calculate based on objects bounds. how should i do this? does screen width and height plays any role here?

more ▼

asked Jun 21 '10 at 10:07 AM

pretender gravatar image

pretender
512 122 134 146

(comments are locked)
10|3000 characters needed characters left

2 answers: sort oldest

Screen width/height shouldn't play a role. What should play a role is the camera's FOV (and possibly near/far clip planes). The FOV in Unity is vertical.

I don't know the math offhand, but you could figure out for a given height how far away from the camera you need to be for it. According to this thread, it's simply using the tangent of the FOV.

Alternatively, you might be able to whip up a solution by calculating the camera frustum planes and moving forward until they are no longer in bounds

more ▼

answered Jun 21 '10 at 03:26 PM

Tetrad gravatar image

Tetrad
7.3k 27 37 89

although i didnt use your solution i thank you..i managed to resolve the issue in an uncomplicated way and that was to look for object bounds, like this collider.bounds.size, that is the Vector3, then to look the highest value and to set the distance to that value. in that way i have smaller and bigger object to fill out the screen when zoomed in... thanks everybody!

Jun 22 '10 at 10:18 AM pretender
(comments are locked)
10|3000 characters needed characters left

You can give them all tags, like size1, size2, size3, raycast and check the tags, if it's size1 so it'll zoom * 2, size2 * 3.

more ▼

answered Jun 21 '10 at 10:46 AM

AnaRhisT gravatar image

AnaRhisT
865 30 33 43

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x503
x183
x101

asked: Jun 21 '10 at 10:07 AM

Seen: 2151 times

Last Updated: Jun 21 '10 at 10:07 AM