Jump to content
  • Advertisement


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


Can someone explain this to me?

This topic is 5531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!