Advertisement
C0BRA

CVector::ToScreen

Nov 18th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. CVector CVector::ToScreen(const CVector& CamPos, const CAngle& CamAngle, double FOV, unsigned int ScreenWidth, unsigned int ScreenHeight) const
  2. {
  3. CVector up = CamAngle.Up();
  4. CVector right = CamAngle.Right();
  5. CVector forward = CamAngle.Forward();
  6.  
  7. CVector dir = CamPos - *this;
  8. double fdp = forward.Dot(dir);
  9.  
  10. if(fdp == 0)
  11. return CVector(0, 0);
  12.  
  13. double d = 4.0 * ScreenHeight / (6.0 * tan(rads(0.5 * FOV)));
  14. CVector proj = dir * (d / fdp);
  15.  
  16. double x = 0.5 * ScreenWidth + right.Dot(proj);
  17. double y = 0.5 * ScreenHeight - up.Dot(proj);
  18.  
  19. return CVector(x, y, 0.0);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement