I'm trying to rotate an object towards a 3d point using OpenGL and glm. To find xRotation I am doing this:
xRotation=atan2(lookAtDiff.x,lookAtDiff.z)
Where xRotation is around the Y axis and lookAtDiff is a vec3 that is the difference between the object's position and what I am trying to make it face. This works flawlessly. So I decided to do yRotation (Rotation around X axis) in the same manner by doing this:
yRotation=atan2(lookAtDiff.y,lookAtDiff.x)
This gives me the wrong rotation. My question is why am I getting the wrong rotation from this and how can I fix it?
You have to use the diagonal: