I've been trying to solve a (rather simple?) problem lately. I'm surprised I haven't been able to find anything really useful on the net so far.
The thing is I have 3d direction vector. Use it to set the direction of an object in 3d space. To do that I need of course a transformation matrix.
I have a function that properly calculates the LookAt matrix. However it is correct for the view transformation. I had no success in using it to calculate the rotation of the object.
I have also tried using trigonometry using (assuming Y is up):
if(dir.getY() != 0.0f) xAngle = (float)Math.toDegrees(Math.atan((dir.getZ()*dir.getZ()+dir.getX()*dir.getX())/dir.getY())); if(dir.getZ() != 0.0f) yAngle = (float)Math.toDegrees(Math.atan(dir.getX()/dir.getZ())); TransformationMatrix.calculateRotationMatrix(xAngle, yAngle, 0.0f);However this does produce proper results only in certain situations.
Can anybody suggest a solution?
Thanks a lot