Setting the camera's aspect ratio

:wave:

New Babylon user here, hopefully a simple question but I cannot seem to find anything describing how to set the aspect ratio of any of the perspective oriented cameras.

I’m coming from other graphics apis / math libraries and the aspect ratio is usually one of the parameters in the camera constructor or has a setter of some sort so I was curious as to what the right way to do things is in Babylon.

For example, I have a render target I’d like to render some stuff onto that is 512x512. Of course, taking the aspect ratio of the canvas won’t always work and will usually result in a squashed image.

I kind of figured out a workaround by calling setSize on my Engine instance, setting the size to 512x512, then back to the “normal” size, but I wasn’t sure if that was how things were generally handled.

Any help is appreciated! Thanks!

Welcome aboard!

You can’t set the aspect ratio on a camera directly, it is automatically calculated according to the width/height of the current screen.

For a RTT, you can set the option doNotChangeAspectRatio: false when creating a RenderTargetTexture, to use the aspect ratio of your RTT and not the one of the current screen:

1 Like

Ah, interesting! Thanks for explaining things. Certainly a very different way of working with things than I’m used to but I’m sure I’ll get used to it at some point.