Archived

This topic is now archived and is closed to further replies.

TWild

Can someone explain this to me?

Recommended Posts

I understand what this function is supposed to do (sets the camera position and makes it look towards the target), but I am confused on HOW it works. I''m not sure why he (Jim Adam''s PRPGWDX) is using the magnitude of the vector (which I''m assuming extends from the origin to [XDiff, ZDiff], correct?) in the atan2 function. I have a trig/calculus/physics background, although its been a few semesters back. I just have a hard time relating it to code or something Can anyone shed some light on how this function works?
BOOL cCamera::Point(float XEye, float YEye, float ZEye, float XAt, float YAt, float ZAt)
{
  float XRot, YRot, XDiff, YDiff, ZDiff;

  // Calculate angles between points

  XDiff = XAt - XEye;
  YDiff = YAt - YEye;
  ZDiff = ZAt - ZEye;
  XRot = (float)atan2(-YDiff, sqrt(XDiff*XDiff+ZDiff*ZDiff));
  YRot = (float)atan2(XDiff, ZDiff);

  Move(XEye, YEye, ZEye);
  Rotate(XRot, YRot, 0.0f);

  return TRUE;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
XDiff holds the world to camera transformation of the "At" point. In this case, he calls the camera the "Eye." Think about it. If you wanted to make things simple, you''d virtually keep the camera AT THE ORIGIN pointing down the z-axis. Well, forget about the direction for now... how would you do it? How would you trick a point into being at the same spot in the camera''s view relative to the world position of the virtual camera?--Easy. Subtract the camera''s position. Think about it. If the world coord of the "At" is in quadrant one, and the camera is between it and the origin, then if you moved the camera to the origin, you''d have to subtract that same change, componentwise from the "At." And I don''t know what atan means so I can''t help you there.

-leinad (I think I''m banned)

Share this post


Link to post
Share on other sites