Alright heres my code:
Code:
const float radAngle = DEG2RAD (xAng);
const float radCam = DEG2RAD (CameraAngle);
vector3d D (pos + vector3d(pos.x * sin(radAngle), pos.y,
pos.z * cos(radAngle)));
vector3d R = (CamPos + vector3d(CamPos.x * sin(radCam), CamPos.y,
CamPos.z * cos(radCam)));
float fDot = Dot(R,D);
float fAngle = acosf(fDot);
fprintf (ff, "%f %f \n", fDot, fAngle);
dir_ = ((int)RAD2DEG(fAngle) / 45) & 7;
xAng is the sprite angle in degrees, radAngle is the sprite angle converted to radians, CameraAngle is the camera angle in degrees, radCam is it in radians.
D is the point the sprite is facing, R is the point the Camera is facing. (Am I calculating these wrong?). As shown, I calculated the dot product of the camera face-point and the sprite-face point and the arccosine of that dot product.
However, the fprintf statement shows that, after being calculated, fAngle is always equal (in floating point) to -1.#IND00... a really tiny number.
Is this from calculating the points the camera and sprite face incorrectly? From getting degrees/radians mixed up? Thank you very much for your help!
Ps "Dot" is defined as:
Code:
__inline float Dot (const vector3d &v1, const vector3d &v2)
{
return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
}
as far as I know, Dot() and all of the other vector3d routines I wrote function as they should.
Thanks!