So, here is a vector, matrix, rotation, quaternion question for the three.js masters!
I have a parent object at position(0,0,275)
with direction(0,0,-1)
, +y up and rotation(0,0,0)
.
Attached to the parent is a child object with relation:
rel_position(.5, 0, 0)
rel_rotation(0, 0, 0)
I also have a target in the scene:
position(0, 100, 0)
Consider a ship(parent) with pitch, yaw and roll. It has a turret(child) with pitch and yaw. The turret needs to track the target at a given rotational speed (rad/s).
I have spent 5 days trying to get a proper tracking algorithm. The best I can do is remove the matrixAutoUpdate feature on the parent and child updating the matrix manually. Then use the child.matrixWorld to create rotation matrices or quaternions for the current child rotation. Then I can create a secondary Object3D which looks at the target from the child position. I can take the difference between the child and the secondary Object3D and slerp the quaternion on a rad/s basis. However, when I add roll to the parent or the target is rotated outside of octant (+, +, +)
the child rotation (or quaternion) calculations crash causing wild rotations.
Any direction on a tracking algorithm for a child Object3D would be immensely appreciated. Your efforts will be cited in my upcoming project.
Thank you for your time!