- Home /
Changing the Camera viewport rect results in resizing the objects rendered by the specific camera ?
I am using more than one camera in a game, each camera has different viewport.
All cameras viewports are set in such a way that they all can render certain objects. at the same point.
Now, while changing the viewport rect of a camera, sometimes the objects rendered by the camera are re-sized(Meaning : Shown smaller or larger on the screen, not actually re-sized).
When the viewport width is changed, the size remains the same. but changing the viewport height affects the size.
All camera's are orthographic. What should I do so that the size of the objects shown remains the same irrespective of the camera viewport ?
Thanks.
Case 1 : This does not change the size.
gameCamera1.rect = new Rect(0,0,0.5f,1);
gameCamera2.rect = new Rect(0.5f,0,0.5f,1);
Case 2 : This does change the size.
gameCamera1.rect = new Rect(0,0,1,0.5f);
gameCamera2.rect = new Rect(0,0.5f,1,0.5f);
You can see these images. To get the idea more clear.! In Image "1" the size is perfect, in Image "2" the objects have shrink.
![alt text][1]
In order to have scalable screen sizes, most rendering engines scale vertically. If you want to prevent this in a way in which scale is preserved when the screen size is changed, then you need to alter the field of view to match what you want.
Answer by gfoot · Jan 23, 2014 at 12:01 PM
If you just want the size to match, add something like this to a script on your camera:
public void LateUpdate()
{
camera.orthographicSize = FullScreenOrthographicSize * camera.rect.height;
}
where FullScreenOrthographicSize is a tweakable parameter that's equivalent to the orthographicSize you would use if the camera's viewport covered the whole screen. Then for smaller viewports the camera's orthographicSize gets scaled down appropriately.
If you put this in a script of its own with [ExecuteInEditMode] then it'll be easy to see the effect in the editor, and tweak the FullScreenOrthographicSize value how you want it.
what about perspective projection cameras ins$$anonymous$$d of orthographic? could you help me out with that?
Your answer
Follow this Question
Related Questions
How does the aspect ratio work? 0 Answers
Wipe transition between two cameras 1 Answer
Centering Camera Viewport Rect? 1 Answer