-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
117 lines (94 loc) · 2.49 KB
/
Copy pathtest.cpp
File metadata and controls
117 lines (94 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <Windows.h>
#include <stdint.h>
#include <cmath>
#include <chrono>
#include <thread>
using std::cout, std::cin;
HWND hwnd = GetConsoleWindow();
HDC hdc = GetDC(hwnd);
RECT window = {};
const double PI = 3.1415926535897932384;
class CPoint
{
public:
float x, y;
CPoint() = default;
CPoint(float x, float y) : x(x), y(y) {}
};
struct PointForRotate
{
float x, y, koef = 1;
PointForRotate() = default;
PointForRotate(float x, float y) : x(x), y(y) {}
};
struct RotationMatrix
{
float matrix[3][3];
RotationMatrix() = default;
RotationMatrix(float angle)
{
matrix[0][0] = cos(angle);
matrix[0][1] = sin(angle);
matrix[0][2] = 0;
matrix[1][0] = -sin(angle);
matrix[1][1] = cos(angle);
matrix[1][2] = 0;
matrix[2][0] = 0;
matrix[2][1] = 0;
matrix[2][2] = 1;
}
};
int main()
{
HANDLE out_handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD maxWindow = GetLargestConsoleWindowSize(out_handle);
SMALL_RECT srctWindow = {0, 0, maxWindow.X - 50, maxWindow.Y - 15};
SMALL_RECT minWindow = {0, 0, 0, 0};
SetConsoleWindowInfo(out_handle, true, &minWindow);
SetConsoleScreenBufferSize(out_handle, maxWindow);
SetConsoleWindowInfo(out_handle, true, &srctWindow);
SelectObject(hdc, GetStockObject(WHITE_PEN));
std::getchar();
CPoint rec[4]{{100, 100}, {100, 200}, {200, 200}, {200, 100}};
for (int i = 0; i < 4; i++)
{
MoveToEx(hdc, rec[i].x, rec[i].y, NULL);
LineTo(hdc, rec[(i + 1) % 4].x, rec[(i + 1) % 4].y);
}
// ( x y )
// *
// ( cos(a) -sin(a) )
// ( sin(a) cos(a) )
RotationMatrix m(PI / 100);
int result[2], coordsPoint[2];
// * FOR 4 POINTS
for (int k = 0; k < 4; k++)
{
for (int i = 0; i < 2; i++)
result[i] = 0;
// * COPY OF COORDS
coordsPoint[0] = rec[k].x;
coordsPoint[1] = rec[k].y;
// * MULTIPLY
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
result[i] += coordsPoint[j] * m.matrix[j][i];
}
}
// * SET NEW COORDS
rec[k].x = result[0];
rec[k].y = result[1];
}
for (int i = 0; i < 4; i++)
{
MoveToEx(hdc, rec[i].x, rec[i].y, NULL);
LineTo(hdc, rec[(i + 1) % 4].x, rec[(i + 1) % 4].y);
}
ReleaseDC(hwnd, hdc);
std::getchar();
std::getchar();
return 0;
}