title: How does fWorldPerScreenWidthPixel work for drawing in loop
body: <p>This code draws a sine wave with function.  In the following panning/zooming code, I am trying to understand how fWorldPerScreenWidthPixel is being used to draw the line segments.</p>
  
  <pre><code>WorldToScreen(fWorldLeft - fWorldPerScreenWidthPixel, -function((fWorldLeft - fWorldPerScreenWidthPixel) - 5.0f) + 5.0f, opx, opy);
  </code></pre>
  
  <p>It is setting opx and opy, but why is it subtracted from:   fWorldLeft</p>
  
  <p>It seems strange to want to start left of fWorldLeft in the for loop where it draws the line. fWorldLeft starts at -25.</p>
  
  <p>I have included the necessary code to explain:</p>
  
  <pre><code>// Draw Chart
      float fWorldPerScreenWidthPixel = (fWorldRight - fWorldLeft) / ScreenWidth();
      float fWorldPerScreenHeightPixel = (fWorldBottom - fWorldTop) / ScreenHeight();
      int px, py, opx = 0, opy = 0;
      WorldToScreen(fWorldLeft - fWorldPerScreenWidthPixel, -function((fWorldLeft - fWorldPerScreenWidthPixel) - 5.0f) + 5.0f, opx, opy);
      for (float x = fWorldLeft; x &lt; fWorldRight; x += fWorldPerScreenWidthPixel)
      {
          float y = -function(x - 5.0f) + 5.0f;
          WorldToScreen(x, y, px, py);
          DrawLine(opx, opy, px, py, PIXEL_SOLID, FG_GREEN);
          opx = px;
          opy = py;
      }
  </code></pre>
  
  <p>Call to set fWorldLeft:</p>
  
  <pre><code>// Clip
      float fWorldLeft, fWorldTop, fWorldRight, fWorldBottom;
      ScreenToWorld(0, 0, fWorldLeft, fWorldTop);
  </code></pre>
  
  <p>Sets fWorldleft:</p>
  
  <pre><code>// Convert coordinates from Screen Space --&gt; World Space
  void ScreenToWorld(int nScreenX, int nScreenY, float &amp;fWorldX, float &amp;fWorldY)
  {
      fWorldX = ((float)nScreenX / fScaleX) + fOffsetX;
      fWorldY = ((float)nScreenY / fScaleY) + fOffsetY;
  }
  </code></pre>
  
  <p>and while I'm at it, World to Screen:</p>
  
  <pre><code>// Convert coordinates from World Space --&gt; Screen Space
  void WorldToScreen(float fWorldX, float fWorldY, int &amp;nScreenX, int &amp;nScreenY)
  {
      nScreenX = (int)((fWorldX - fOffsetX) * fScaleX);
      nScreenY = (int)((fWorldY - fOffsetY) * fScaleY);
  }
  </code></pre>
  
  <p>Thank you!</p>
  
  <p>Josh</p>