- Home /
Finding the right ortho size to fill the screen with an object
I have an object (with several children) whose size in Unity Units I could find pretty easily (mark two corners with dummy objects and just get the Vector3.Distance
of that). Presuming this is a completely 2D application, how would I take this abstract object and fill the screen with it by changing the orthographic camera's Camera.orthographicSize
once?
The intent is to capture a region of the screen (read: the whole object in as best a resolution as possible) for PDF output. I've done it before using a "change and test" looping approach, but changing it once would speed the process up.
I am aware of the Pixel-perfect calculator, however the object I need to capture is very rectangular and I'm not certain how to modify this calculator to go from "pixel-perfect" to "as large as can fit".
Answer by FortisVenaliter · May 18, 2015 at 10:37 PM
I'm not sure, but I believe the orthographic size is equivalent to the vertical size of the view in world units.
However, it should be really easy for you to play with this and figure out for sure yourself. Unit tests are great for this sort of thing.
What I would do is create a new scene with an orthographic camera and a quad. Make sure they are properly facing each other, then play with the quad scale, camera position, screen aspect ratio, and camera ortho size until you're able to find the proper correlations. Then port the info you learned from that into the code in your project, and voila.
I was afraid I was going to have to do some guess and test at some point, but shifting it to compile-time seems to be a bit better. Already have a bit of a start on it... so yeah.
Testing has come to the conclusion that finding the proper Orthographic Size for a non-square object to fill the screen is an exponential function based on the aspect ratio of the camera's rectangle... unless it's filling the screen vertically (ie a wicked-long-and-not-very-tall window), in which case it's a constant number. The exact numbers appear to depend on the aspect ratio of the object in question.