This is a problem I have been trying hard to figure out and I can't. You know how in Final Fantasy Tactics and Xenogears the characters are billboarded sprites that change "directions" (flat images of the sprite facing certain directions) depending on the camera?

So, given a position of a sprite and a point that sprite is facing (the point is rotated around the sprite by 0,45,90,135,180,225,270,315 degrees), and given a position of a camera and a point the camera is facing (a point rotated around the camera by 0 to 359 degrees), how can I find the correct "direction" image (0 - 7) for the sprite? What relationship between these points / angles needs to be found?

If anyone can help me or give me a hint, tip, or tutorial, I'd appreciate it. I've tried various things - law of cosines, etc, but I'm still not sure what thing exactly I'm looking for, so my attempts have always been messed up.

Thanks!

(ps I have all the following information about the sprite and the camera:
sprite position
sprite angle
point sprite is facing (position.x + sin (radangle), position.z + cos (radangle))

camera position
camera angle
point camera is facing (ditto)
)