<p dir="auto">Sorry in advance if this is the wrong place or way to ask this.  I would like to add a hook to the trackball mouse controls so that a user can specify a handler they would like called first if needed.  Doing it is not difficult but I'd like to contribute it back to the community if it has value.  How do I go about doing that?  Is there an example of other code that I can look at that would be consistent stylistically?</p>
<p dir="auto">My goal is to have the camera looking perpendicularly at one face of a cube, no matter how the cube rotates. I'm using FirstPersonControls to control the cube. I'm using the pointer lock API so the cube rotates with my mouse movements as a character would in a 3rd person shooter.</p>
<p dir="auto">I'm having problems keeping the camera a fixed distance behind the cube and always looking at the cube at the same angle.</p>
<p dir="auto">To set the position of the camera, I'm doing something like this:<br>
camera.position.x = mesh.position.x + Math.sin(mesh.rotation.y) * 400;<br>
camera.position.y = 450;<br>
camera.position.z = mesh.position.z + Math.cos(mesh.rotation.y) * 400;</p>
<p dir="auto">camera.lookAt(mesh.position);</p>
<p dir="auto">There's two problems with this: One is I'm able to keep aligned behind the cube for a rotation of only 180 degrees, then the cube will do a full spin before the camera re-aligns again. I suspect this is because, when controlled by FirstPersonControls, mesh.rotation.y takes on values from -Pi/2 to Pi/2 and then starts returning to -Pi/2 even though I keep turning in the same direction. So the camera is not able to do a full spin as it would if mesh.rotation.y kept increasing indefinitely as I kept moving the mouse right.</p>
<p dir="auto">The other problem is I'm not sure how to calculate camera.position.y with respect to the mesh rotation. I also want the camera to move on the y-axis while looking at the cube, rather than being hard-coded at 450. But that is a problem I think I should solve after fixing the first issue.</p>
<p dir="auto">Would anyone be able to offer some advice?</p>