void look_at(ENTITY* Vehicle, VECTOR* Destination, ENTITY* Planet)
{
VECTOR V_Nrml;
ANGLE V_Ang;
VECTOR V_Path;
ANGLE Path_Ang;
var hemisphere;
//this time I start off with a nuetral angle for the calculations
vec_fill(V_Ang, 0);//standing stright up with zero pan
//get our vehicle's normal from the planet core
vec_diff(V_Nrml, Vehicle.x, Planet.x);
// orient angle by planet normal (perfect sphere)
alignToVec(V_Ang, V_Nrml, vector(0, 0, 1), 1);
// get destination position relative to the planet core
vec_diff(V_Path, Destination, Vehicle.x);
//rotate relative destination by absolute orientation
vec_rotateback(V_Path, V_Ang);
// convert to an angle
vec_to_angle(Path_Ang, V_Path);
//DEBUG path
vec_set(testv1,V_Path);
vec_normalize(testv1,1000);
vec_add(testv1,Planet.x);
draw_line3d(testv1,NULL,100);
draw_line3d(testv1,COLOR_GREEN,100);
draw_line3d(Planet.x,COLOR_GREEN,100);
//avoid gimbal lock
if(Path_Ang.tilt>89||Path_Ang.tilt<-89)
{
return;//don't rotate
}
// rotate angle by Path_Ang
ang_rotate(V_Ang, vector(Path_Ang.pan, 0, 0));
vec_set(Vehicle.pan,V_Ang);
}