exponential zoom in / out

Hi,

I’m working on a project for demoing a city model.

I’m using a flyover camera thats controlled by the mouse. Scrollwheel is zooming.

However the problem I run in to when calculating the exponential zoom in value is that it works when I’m reaching min height, but it multiplies whenever I reach the max height.

I’ve got a few variables:

  • PlayerHeight (float)
  • ZoomValue (float)
  • MaxHeight (float)
  • MinHeight (float)

So what I need is for ZoomValue to be 1 when PlayerHeight is MaxHeight / 2, and ZoomValue to be 0 when at MaxHeight or MinHeight, and everything in between. I guess it’s a simple formula but I can’t figure it out.

MinHeight 0f and MaxHeight is 650f.

Just for reference here’s a table I quickly drew illustrating what I need:

[37562-zoomvalue+table.jpg|37562]

Can anyone help me out? Thanks!

From the sample values you have provided it’s more like a linear formula.

int maxHeight = 650;
int minHeight = 0;
int maxZoom = 1f;
int playerHeight;

void Update()
{
   playerHeight = 200; // set playerHeight accordingly.
}

private int CalucalteZoom()
{
  if ((playerHeight > minHeight) && (playerHeight < (maxHeight / 2))) 
  {
    return ((playerHeight * maxZoom)/ (maxHeight / 2));
  } else if ((playerHeight > (maxHeight / 2)) && playerHeight < maxHeight)
  {
    return (((maxHeight - playerHeight) * maxZoom) / (maxHeight / 2));
  } else 
     return 0;
}