Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1.  
  2. #include <iostream>
  3.  
  4.  
  5.  
  6.  
  7. struct Point
  8. {
  9.     int x, y;
  10. };
  11.  
  12. struct ScreenInfo
  13. {
  14.     int screenWidth;
  15.     int screenHeight;
  16.  
  17.     int xMin, xMax, yMin, yMax;
  18. };
  19.  
  20. Point mat2screen(const Point& mcoord, const ScreenInfo& info);
  21.  
  22.  
  23. int main()
  24.  {
  25.  
  26.         ScreenInfo info = { 800, 600, -5, 5, -4, 4 };
  27.         Point pm ={ 0, 0 };
  28.         Point pe;
  29.  
  30.         pe = mat2screen(pm, info);
  31.  
  32.        std::cout << pe.x << pe.y << std::endl;
  33.     }
  34.  
  35.  
  36. Point mat2screen(const Point& mcoord, const ScreenInfo& info)
  37. {
  38.     Point rv;  //pukt ukladu ekranowego
  39.     rv.x = info.screenWidth / (info.xMax - info.xMin) * mcoord.x + info.screenWidth * info.xMin / (info.xMin - info.xMax);
  40.     rv.y = info.screenHeight / (info.yMin - info.yMax) * mcoord.y + info.screenHeight * info.yMax / (info.yMax - info.yMin);
  41.  
  42.     return rv;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement