const float radAngle = DEG2RAD (xAng); vector3d O = pos; // O is the sprite''s position vector3d D (O + vector3d(O.x * sin(radAngle), O.y, O.z * cos(radAngle))); vector3d F = vector3d (D.x, O.y, O.z); double theta; const float hyp = Distance2d (D.x, D.z, O.x, O.z); const float adj = Distance2d (O.x, O.z, F.x, F.z); if (hyp != 0) { if ((adj / hyp) != 1) { theta = acos (adj / hyp); if ((D.z > O.z) && (D.x >= O.x)) ; if ((D.z >= O.z) && (D.x < O.x)) theta = theta + (PI * 0.5); if ((D.z < O.z) && (D.x < O.x)) theta = theta + PI; if ((D.z <= O.z) && (D.x >= O.x)) theta = theta + 3 * PI * 0.5; // theta = theta + (PI * 0.5); } else theta = radAngle; } else theta = radAngle; unsigned int direction = FABS((int)CameraAngle - (int)RAD2DEG(theta)) / 45;
Given pos, the position of the sprite, xAng, the angle in degrees the sprite is facing, and CameraAngle, an angle in degrees the camera is rotated, "direction" should hold a number between 0 and 7 that is the correct viewable direction of the character...
Unfortunately it does not. A lot of strange directions are chosen. When will I get this to work? Only the mystics know. But I think that I can do it.
Let me just get what the goal is straight. To find the correct direction, we need to find the angle between line OF (the line between the sprite''s position, and a point in front of it?) and line OD (the line between the sprite''s position, and a point its facing?), then find the difference between this and the camera angle. My head isn''t forming this too well. Why would this work? Why is the camera position not needed - it would seem that the farther away the camera is, the less "sensitive" the sprite is to switching angles when the camera rotates - but this may not be true.
The way I''ve coded it doesn''t seem to work at all - is it a flaw in what I''ve coded, or am I not getting the process and idea right?
Thank you so much for helping... sorry I''m not getting this, don''t give up on me. I''m going to figure this out by gum. =)