This question already has an answer here:
I would like to rotate an object (white rectangle) towards another object (black rectangle). EDIT: the white rectangle (at the top) has a camera. I finally rotated the camera by 180 around the "y" axis, because it was looking to the right of the image. Now, the goal is to rotate the camera around the "x" axis, by the green angle.
I found some images that explains atan2 :
What I try to do is :
Edit : the green angle seems wrong, here is a new one :
If I refer to the trigonometry circle, I should have a value around -120 :
Would someone know what is happening? Here is the code I am using :
//boxNode is the black rectangle, boxYellow is the white rectangle at the top //163 degrees let opposite = boxNode.position.z - boxYellow.position.z let adjacent = boxNode.position.y - boxYellow.position.y //-73 degrees //let opposite = boxNode.position.y - boxYellow.position.y //let adjacent = boxNode.position.z - boxYellow.position.z camRadians = atan2(opposite, adjacent) println("deg: \(convertRad2Deg(camRadians))")