Hi, all. I've decided to write a custom utility function used for facing one entity to another (for instance the camera to another object). I had thought I had all the math worked out (as for using trigonometry to find the angles and whatnot), but apparently I haven't got it all figured out as far as the code is concerned.
Here's the function:
void FaceObject(ENTITY* ent1,ENTITY* ent2)
{
distz= ent2.z - ent1.z; //these are the distance variables.
disty= ent2.y - ent1.y; //as you can see,these find
distx= ent2.x - ent1.x; //the distance between the x,y,and z components.
distxy= sqrt(pow(distx,2) + pow(disty,2)); //finding general distance to object
/*I prefer not to use vec_dist() here because
*I have already found the z distance above,
*and I don't need more than the x and y in
*this case.*/
ent1.pan= atan(disty/distx); //using arc tangent to find pan
ent1.tilt= atan(distz/distxy); //and tilt angles.
}
Can anyone tell me what I'm doing wrong here? Maybe I should be using atanv()?
Well, I suppose it would help if I explained a bit more in detail,
. I run it, and the camera is just sitting there, doing nothing, facing straight. I have the object that I want the camera to face at an obscure position from the camera, so I know it's not just that the effect isn't visible.