The maps in Whirlygig are larger than what fits on a single screen. So, the camera needs to move (see Camera Averaging post) with the battling helicopters and zoom in or out depending on how far apart the combatants are. Moving the camera and even basic zooming was fairly easy. But the zoom was jarring. When a heli got within a certain distance from the screen it would zoom very quickly and interfere with the gameplay. So, I wanted to make the camera accelerate smoothly in and out. This turned out to be harder than I thought.

The actual math behind zooming in and out is very simple. However, I always get confused with absolute and relative coordinates. I built smooth zooming 10 different ways and nothing worked like I anticipated. I tried examining different variables, setting breakpoints…etc. but couldn’t figure out what was going wrong. Finally I drew visible AxisAlignedRectangles to the screen and realized that I needed to find the edges of the screen using Relative instead of Absolute camera methods.

I would post code but it’s still pretty rough. I need to refactor some variable names, move some variables into Glue and do some more testing. I realized after I uploaded the video that I should have done a before and after showing zoom without smoothing and with smoothing. That would make it easier to see how big of a difference it makes. Nobody actually reads this anyway so it probably doesn’t matter :P