Advertisement
_BYTE

Functions.cpp

Dec 12th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.89 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "Functions.h"
  3.  
  4. POINT Point(int x, int y)
  5. {
  6.     POINT res;
  7.     res.x = x;
  8.     res.y = y;
  9.     return res;
  10. }
  11.  
  12. POINT3 PointEx(int x, int y, int z)
  13. {
  14.     POINT3 res;
  15.     res.x = x;
  16.     res.y = y;
  17.     res.z = z;
  18.     return res;
  19. }
  20.  
  21. int Round(double x)
  22. {
  23.     if(x < 0) x -= 0.5; else x += 0.5;
  24.     return (int) x;
  25. }
  26.  
  27. double Abs(double X)
  28. {
  29.     if(X < 0) X = (double) - X;
  30.     return X;
  31. }
  32.  
  33. double DegreeToRad(double Angle)
  34. {
  35.     return (( (double) Angle * Pi) / 180);
  36. }
  37.  
  38. POINT3 GlobalPointToScreen(POINT3 World_Point, double Angle_Horizontal, double Angle_Vertical, int R)
  39. {
  40.     int M1[4];
  41.     double M2[4][4];
  42.  
  43.     double A = DegreeToRad(Angle_Horizontal);
  44.     double B = DegreeToRad(Angle_Vertical);
  45.  
  46.     M1[0] = World_Point.x;
  47.     M1[1] = World_Point.y;
  48.     M1[2] = World_Point.z;
  49.     M1[3] = 1;
  50.  
  51.     M2[0][0] = - sin(A);
  52.     M2[1][0] = cos(A);
  53.     M2[2][0] = 0;
  54.     M2[3][0] = 0;
  55.  
  56.     M2[0][1] = - cos(B) * cos(A);
  57.     M2[1][1] = - cos(B) * sin(A);
  58.     M2[2][1] = sin(B);
  59.     M2[3][1] = 0;
  60.  
  61.     M2[0][2] = - sin(B) * cos(A);
  62.     M2[1][2] = - sin(B) * sin(A);
  63.     M2[2][2] = - cos(B);
  64.     M2[3][2] = R;
  65.  
  66.     M2[0][3] = 0;
  67.     M2[1][3] = 0;
  68.     M2[2][3] = 0;
  69.     M2[3][3] = 1;
  70.  
  71.     int M3[4];
  72.     int S = 0;
  73.  
  74.     for(int i = 0; i < 4; i++)
  75.     {
  76.         for(int j = 0; j < 4; j++)
  77.             S = S + Round(M1[j] * (double) M2[i][j]);
  78.         M3[i] = S; S = 0;
  79.     }
  80.  
  81.     POINT3 res = PointEx(Abs(M3[0]),Abs(M3[1]),Abs(M3[2]));
  82.     return res;
  83. }
  84.  
  85. POINT Perspective(POINT3 PT, double d)
  86. {
  87.     int x = Round(d * ((double) PT.x / (double) PT.z));
  88.     int y = Round(d * ((double) PT.y / (double) PT.z));
  89.     POINT res = Point(x,y);
  90.     return res;
  91. }
  92.  
  93. void Piramid(HDC hdc, POINT *PT, int COUNT)
  94. {
  95.     for(int i = 1; i < COUNT; i++)
  96.     {
  97.         MoveToEx(hdc,PT[0].x,PT[0].y,NULL);
  98.         LineTo(hdc,PT[i].x,PT[i].y);
  99.     }
  100.  
  101.     for(int i = 1; i < COUNT; i++)
  102.     {
  103.         MoveToEx(hdc,PT[i].x,PT[i].y,NULL);
  104.         if(i != COUNT-1)
  105.             LineTo(hdc,PT[i+1].x,PT[i+1].y);
  106.         else
  107.             LineTo(hdc,PT[1].x,PT[1].y);
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement