Rotation towards an object in 3d space
Posted
by retoucher
on Stack Overflow
See other posts from Stack Overflow
or by retoucher
Published on 2010-02-07T01:20:30Z
Indexed on
2010/04/12
22:02 UTC
Read the original article
Hit count: 339
3d
|trigonometry
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?
© Stack Overflow or respective owner