I am facing a challenge where I need to ensure that the camera stays at a fixed distance behind an object as it moves and rotates. Specifically, I am working on drawing an airplane and require the camera to always focus on its rear end, while allowing user interaction like mouse movement for viewing other angles.
Assuming I have defined the position and rotation of the airplane (represented by an instance of THREE.Object3D):
airplane.position = {x: 1, y:2, z: 3};
airplane.rotation = {x: Math.PI/4, y:1.2, z: 0};
If the initial configuration has the camera positioned at (5, 0, 0) when the airplane's rotation and position are both (0, 0, 0), what would be the simplest approach to calculate the vector for placing the camera?
Thank you in advance for any insight!
Apologies for the messy code presentation; I'm currently juggling with it. Unfortunately, I can't create a jsfiddle due to the absence of a server to host three.js resources...