title: Finding the angles for the X, Y and Z axis in 3D - OpenGL/C++
body: <p>I am currently trying to use OpenGL (With SDL) to draw a cube to the location where I left click in the screen and then get it to point at the position in the screen where I right click.</p>
  
  <p>I can successfully draw a cube at my desired location using gluUnproject - Meaning I already know the coordinates of which my cube is situated.</p>
  
  <p>However I do not know how to calculate all of the angles required to make my cube point at the new location.</p>
  
  <p>Of course I am still using gluUnproject to find the coordinates of my right click, but I only know how to rotate around the Z axis from using 2D graphics.</p>
  
  <p>For example before, if I wanted to rotate a quad around the Z axis (Of course, this would be a top down view where the Z axis is still "going through" the screen) in 2D I would do something like:</p>
  
  <pre><code>angle = atan2(mouseCoordsY - quadPosY, mouseCoordsX - quadPosX);
  glRotatef(angle*180/PI, 0, 0, 1);
  </code></pre>
  
  <p>My question is, how would I go about doing this in 3D?</p>
  
  <ul>
  <li>Do I need to calculate the angles for each axis as I did above?</li>
  <li>If so how do I calculate the angle for rotation around the X and Y axis?</li>
  <li>If not, what method should I use to achieve my desired results?</li>
  </ul>
  
  <p>Any help is greatly appreciated.</p>