This page https://goocreate.com/learn/everything-you-always-wanted-to-know-about-rotation/ describes a function 'LookAt' as being able to rotate a 3D object to face another object. The internal operation of the LookAt function is described (but not listed in code) as:
The way the function works is that it takes the entity and target position and subtracts them to get a back vector. Then it calculates the cross product between the up vector and the back vector to get the right vector. Then it calculates the cross product between the right vector and the back vector to get an up vector that is orthogonal to both the direction and the right vector and finally stores all three vectors normalized inside our rotation Matrix3x3 in their respective rows.
I am trying to replicate this without a library of 3D functions to help me. I have 3d vector subtraction, matrix multiplication, dot and cross product functions. (I'm coding in Lua.)
What I cannot figure out is how to make one object face the same direction (and, hopefully, orientation) as another.
I have read that this is just a matter of creating a rotation matrix based on angles, but everything I find which talks about angles in 3D finishes by return a single angle - I would think that there would be 3 angles - one for each plane.
How do I construct this rotation matrix? I do not know which direction my object is facing, which is why the problem of calculating the current x,y,z angle of the object is a problem. I think what I need is a function to determine the current 3-dimensional angle of an object and a way to convert that into a rotation matrix for another object.