@sgsrules: you might want to check that atan2/atan2 really gives you the rotation you want. I think what you want is a cartesian to spherical coordinate conversion to get those rotations.
It's a common misconception that to point at for example <1,1,1> you'd rotate z by PI/4 (atan2(y/x)), then rotate y by PI/4 (atan2(z/x)). 45 degrees around, then tilt 45 degrees up -- simple, right? Yep, but wrong. ;)
Here are two ways to draw a line from 0,0,0 to x,y,z:
Quote:
// with no rotations, draw a cartesian coordinate line
line(0,0,0, x,y,z);
// with rotations, draw a spherical coordinate line
pushMatrix();
float r = sqrt(x*x+y*y+z*z); // radial distance
float theta = atan2(y,x); // zenith angle, range -pi..pi
float phi = acos(z/r); // azimuth angle, range -pi/2..pi/2
rotateZ(theta); // "heading" or "around"
rotateY(phi); // "tilt" or "elevation"
line(0,0,0, 0,0,r); // the z-axis now points "at" x,y,z
popMatrix();
hope that helps