title: Rotating 'camera' in OpenGL around object not object around camera
body: <p>In my app I have a set of object lying around the scene. They are all grouped inside box. When user zoom out to see whole box and starts rotate it then the pivot point is in the middle of box,. When you zoom in to see specific object inside then rotating camera so that the object that you are looking at (or space in front of you) then they are still rotating around this previous pivot point.</p>
  
  <p>What I would like to achieve is to have pivot point always in front of camera. In other words, when you zoom out and see box it rotates as it is doing now. When you zoom in to specific object/space then camera rotate around it.</p>
  
  <p>I've created simple images to show what I mean - triangle is camera, red box is some object/space and orange circle is a path on which element is going on while rotating. The first one is what I have now, the second what I'd like to have.</p>
  
  <p><a href="https://i.stack.imgur.com/HsWi5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HsWi5.png" alt="now"></a></p>
  
  <p><a href="https://i.stack.imgur.com/bRxH4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bRxH4.png" alt="future"></a></p>
  
  <p>I know that in OpenGL there isn't something like camera, so in fact it is whole world moving and not one point. So far I've created something like that:</p>
  
  <pre><code>glPushMatrix();
  glTranslatef(translate[0], translate[1], translate[2]);
  glRotatef(rot, 0.0, 1.0, 0.0);
  DrawObject();
  glPopMatrix();
  </code></pre>
  
  <p><code>translate</code> is an array of values simulating camera movement.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>After Ike answer I modified a little my code so now it looks like this:</p>
  
  <pre><code>glPushMatrix();
  glTranslatef(pivot[0], pivot[1], pivot[2]);
  glRotatef(rot, 0.0, 1.0, 0.0);
  glTranslatef(translate[0], translate[1], translate[2]);
  glPopMatrix();
  </code></pre>
  
  <p>So if I'm getting Iko's solution correctly now my biggest concern is calculating correctly pivot point according to place that I'm looking at. Is it correct thinking?</p>