title: Rotate object to "look at" another object in 3 dimensions?
body: <p>I want to create a formula that rotates my object (o1) to always point into the direction of another object (o2), regardless of  o1's position.</p>
  
  <p>Kind of like the camera in the following image:
  <a href="http://puu.sh/bLUWw/aaa653accf.png" rel="nofollow">http://puu.sh/bLUWw/aaa653accf.png</a></p>
  
  <p>I got the following code so far, but the yaw-axis seems to be inverted:</p>
  
  <pre><code>Vector3 lookat = { lookAtPosition.x, lookAtPosition.y, lookAtPosition.z };
  Vector3 pos = { position.x, position.y, position.z };
  Vector3 objectUpVector = { 0.0f, 1.0f, 0.0f };
  
  Vector3 zaxis = Vector3::normalize(lookat - pos);
  Vector3 xaxis = Vector3::normalize(Vector3::cross(objectUpVector, zaxis));
  Vector3 yaxis = Vector3::cross(zaxis, xaxis);
  
  Matrix16 pm = {
      xaxis.x, yaxis.x, zaxis.x, 0,
      xaxis.y, yaxis.y, zaxis.y, 0,
      xaxis.z, yaxis.z, zaxis.z, 0,
      0, 0, 0, 1
  };
  </code></pre>
  
  <p>See the following image:
  <a href="http://puu.sh/bLUSG/5228bb2176.jpg" rel="nofollow">http://puu.sh/bLUSG/5228bb2176.jpg</a></p>
  
  <p>I'm sure it's just a few variables that have to be swapped, but I couldn't find them...</p>
  
  <p>PS: The position of the object matrix is multiplied at a later stage, for testing purposes...</p>