title: Zooming and swiping with OpenGL ES
body: <p>I am making a 2D puzzle for iOS and currently I`m trying to implement zooming and scrolling with UIPinchGestureRecognizer.</p>
  
  <p>Zooming is done this way: I have a target 2D vector which is a "zooming point". The code is:</p>
  
  <pre><code>glTranslatef(target.x, target.y, 0);
  glScalef(scale, scale, 0);
  glTranslatef(-target.x, -target.y, 0);
  </code></pre>
  
  <p>Target is being selected with gesture recognizer this way:</p>
  
  <pre><code>-(void)handlePinchGesture:(UIPinchGestureRecognizer*)recognizer
  {
      if (UIGestureRecognizerStateBegan == [recognizer state])
      {
          view-&gt;setTarget([recognizer locationInView:self]);
      }
      // Rest of the code omitted
  }
  </code></pre>
  
  <p>Everything works just fine.</p>
  
  <p>Initially the game was designed for iPAD, but I want it to work on iPhone and iPOD too. But iPhone and iPOD have different aspect ratio. To keep initial picture proportions I decided to make initial Y scale a bit bigger. Also this made possible to swipe the game field up and down with initial zoom factor. The code is:</p>
  
  <pre><code>glTranslatef(target.x, target.y, 0);
  glScalef(scale, scale * aspectRatio, 0);
  glTranslatef(-target.x, -target.y, 0);
  </code></pre>
  
  <p>This works just fine IF the game field is "centered" at the screen(e.g. when there are equal space in bot swipe directions(up and down)). But if we swipe the field up or down and begin pinch gesture, the game field jumps to the centre again.</p>
  
  <p>I understand that I need to translate the gesture position by some offset, but I cannot figure how exactly for 3 days.</p>