Orthographic camera zooming

Hi!

I needed to add an orthographic view to my project with zoom support. I am using an ArcRotateCamera. It is known that the orthographic mode doesn’t honor the arc camera’s radius property and one needs to alter the orthoXXX properties of the camera to zoom in or out the view.

I’ve found some solutions on the forum. All of these solutions uses mouse scroll-wheel events to mimic the zooming functionality of the arc camera.

I didn’t find these solutions good. You may alter the radius property in different ways, not with just the mousewheel.

So I came up with this solution. It is simply watching for changes of the radius property (even if the radius property doesn’t affect the view of the arc camera it reacts and changes according to camera inputs as if the camera was in perspective mode). As an addition you get lerping of the orthoXXXX values for free because the radius value is already lerped each frame so the zoom is smooth and honors all the parameters of the camera for example like the wheelDeltaPercentage which I used in my exampe to make the zooming slower.

If you want a 2D camera looking from above just disable beta rotation.

    camera2d.upperBetaLimit = 0
    camera2d.lowerBetaLimit = 0

Enjoy!

:vulcan_salute:

R.

8 Likes

Love it thanks for the tips :slight_smile:

1 Like

Smart thinking. :clap: I’m gonna bookmark this just in case. :smiley:

1 Like

@sebavan @mawa Thanks guys!

This is great @roland . I have a use for this right now. Much appreciated.

1 Like

You are welcome buddy! Im glad it helped someone :vulcan_salute:

2 Likes

Really nice, thanks. Very elegant solution - saved me a lot of time coding!

2 Likes