title: Scaling 3D camera pan/zoom based on distance to target
body: <p>I'm working on a DCC-like tool with a 3D viewport that you can move around with your mouse, similar to Maya, Blender, etc.</p>
  
  <p>I need help with some of the math.</p>
  
  <p>There are two points I am trying to nail down. The first is dolly speed based on distance to target. On small scales (say, dist=10^-3), it dollies too fast, and on large scales (say, dist=10^6), it dollies too slow. I would like a flat "camera speed" input that will scale the effect overall, but at all scales the camera should feel the same. It shouldn't matter if I'm 0.1 or 1000 units away, it should feel like I'm approaching the target at the same speed for a given mouse delta.</p>
  
  <p>The other is camera panning, also based on camera distance. Effectively I want the camera target to track the mouse cursor perfectly along a plane that is aligned with the camera and <code>distance_to_target</code> units away. I am unsure if perspective distortion will affect this?</p>
  
  <p>Inputs are:</p>
  
  <pre><code>// Distance in world units to camera's centre of interest
  real distance_to_target
  
  // Number of pixels mouse has moved horizontally since last frame
  int mouse_delta_x
  
  // Number of pixels mouse has moved vertically since last frame
  int mouse_delta_y
  
  // The vector of the mouse delta, normalized into -1 to 1 space based on
  // viewport dimensions where a value of (-1,-1) or (1,1) means the cursor
  // moved from one corner of the viewport to the other, or further, since
  // the last frame.
  vec2 mouse_delta_vector
  
  // Scale the dolly speed
  real dolly_speed
  </code></pre>
  
  <p>Usually I do stuff like this empirically, trying different values until I find something I like, but for this I think it's time to try theory.</p>