Unfortunately the fact it’s hard-coded means it won’t always get the Y-distance right, and I am hoping there is a cooler way to compute a new field of view for the camera.
You can modify it to suit your needs. I don’t know whether you care about adjust the near and far planes or not. And this code works by adjusting the trackball controls to center the model when you’re using the mouse to control the camera (like the “c” key in pview); you could just move the model instead.