angle.pan= (atan(disty/distx) * (180 / pi)) - 90; //finding pan angle (and subtracting 90 degs)
angle.tilt= (atan(distz/distxy) * (180 / pi)); //and tilt angle
these risk dividing by zero. don't allow that possibility.
the other issue (i'm guessing) is that atan will only get you +- 90 degrees (i know, it uses radians, but you know what i mean). you actually want +- 180 degrees.
ages and ages ago i asked for an atan2 function that takes two parameters (instead of doing atan(disty/distx) you'd do atan2(disty,distx)) and it does the divide safely for you, as well as determining the angle between +- 180 instead of +- 90 degrees (actually in radians). i think they implemented it. i never got around to using it, but here's the one i wrote when i was experimenting with quaternions (uses degrees):
double atan2(var x,var y)
{
if(y==0)
{
return (90*sign(x));
}
var z = atanv(x/y) - (180 * (y<0));
return (z);
}
i'm surprised i wasn't using floats. i suggest if you use this function you adapt it to use floats for better precision (very important for many angle applications). hopefully that'll cause no dramas. look up atan2 in the manual if you want to use lite-C's one.
julz