Rotation towards an object in 3d space
- by retoucher
hello,
i have two coordinates on a 2d plane in 3d space, and am trying to rotate one coordinate (a vector) to face the other coordinate. my vertical axis is the y-axis, so if both of the coordinates are located flat on the 2d plane, they would both have a y-axis of 0, and their x and z coordinates determine their position length/width-wise on the plane. right now, i'm calculating the angle like so (language agnostic):
angle = atan2(z2-z1,x2-x1);
and am rotating/translating in space like so:
pushMatrix();
rotateY(angle);
popMatrix();
this doesn't seem to be working though. are my calculations/process correct?