Hi,
I'm trying to rotate an object towards another object in 3d space. I'm rotating along the Y (vertical) axis, but am having some issues. I have a few translations in my code, and am unsure if this is effecting the calculations for my rotation (for that matter, i'm also unsure if my rotation calculation is correct). For example, I am calculating the Y axis rotation with the following:
Code: float angle = atan2(z2-z1,x2-x1);
float rotation = angle * (180/PI);
The context in which rotation occurs looks like this:
Code: translate(width/2, height/2)
float angle = atan2(z2-z1,x2-x1);
float rotation = angle * (180/PI);
pushMatrix();
translate(x1,y1,z1);
rotateY(rotation);
//draw a few lines here
popMatrix();
This doesn't seem to be rotating my first object (x1,y1,z1) toward the second (x2,y2,z2) along the Y axis. I'm wondering if i need to factor in the translations i'm doing into my angle calculation, or if my angle calculation is simply wrong to begin with.
Thanks.