title: LibGDX 3D camera implementation
body: <p>I'm very new to 3D programming and I'm attempting to implement a camera that will follow my model using LibGDX. I'm having issues with the camera implementation and I would greatly appreciate some advice. As I said, I'm new to this (especially the maths) and the code below will almost certainly not be that great:</p>
  
  <p>To rotate my object and camera at the same time I use the following code with inst being the model instance:    </p>
  
  <pre><code>// right
  inst.transform.rotate(new Vector3(0,1,0), -1);
  Common.cam.rotate(Vector3.Y, -1f);
  // left
  inst.transform.rotate(new Vector3(0,1,0), 1);
  Common.cam.rotate(Vector3.Y, 1f);
  </code></pre>
  
  <p>To move my object I use:</p>
  
  <pre><code>// forward
  Common.inst.transform.mul(new Matrix4(new Vector3(0,0,((float)-0.2)),
                  new Quaternion(0,0,0,0), new Vector3(1,1,1)));
  // back
  Common.inst.transform.mul(new Matrix4(new Vector3(0,0,((float)0.2)),
                  new Quaternion(0,0,0,0), new Vector3(1,1,1)));
  </code></pre>
  
  <p>My camera is currently setup as follows:</p>
  
  <pre><code>Vector3 pos = inst.transform.getTranslation(new Vector3(0,0,0));
  pos.z += 5;
  cam.position.set(pos);
  </code></pre>
  
  <p>This code is working fine, but the problem is that the camera is staying in a fixed position when really it should be adjusting itself to be directly behind the new direction the model is facing. I've probably not articulated this clearly so I've represented this visually:</p>
  
  <p><img src="https://i.imgur.com/mIBZFY9.png" alt="1">
  ^ Model (black) and camera (red) with no rotation</p>
  
  <p><img src="https://i.imgur.com/rmxzmU6.png" alt="2">
  ^ What is currently happening upon rotation</p>
  
  <p><img src="https://i.imgur.com/P0etmLG.png" alt="3">
  ^ What needs to happen</p>
  
  <p>I'd imagine this wouldn't be too difficult to implement if my maths was stronger, but I'm at a complete loss as how to implement this behavior. If someone could point me in the right direction that would be great.</p>
  
  <p>Many thanks!</p>