-
Notifications
You must be signed in to change notification settings - Fork 0
/
CG_Practical04.cpp
127 lines (121 loc) · 2.81 KB
/
CG_Practical04.cpp
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
118
119
120
121
122
123
124
125
126
127
#include <iostream>
#include <graphics.h>
#include <math.h>
using namespace std;
class transform
{
public:
int m, a[20][20], c[20][20];
int i, j, k;
public:
void object();
void accept();
void operator*(float b[20][20])
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < m; j++)
{
c[i][j] = 0;
for (int k = 0; k < m; k++)
{
c[i][j] = c[i][j] + (a[i][k] * b[k][j]);
}
}
}
}
};
void transform::object()
{
int gd, gm;
gd = DETECT;
initgraph(&gd, &gm, NULL);
line(300, 0, 300, 600);
line(0, 300, 600, 300);
for (i = 0; i < m - 1; i++)
{
line(300 + a[i][0], 300 - a[i][1], 300 + a[i + 1][0], 300 - a[i + 1][1]);
}
line(300 + a[0][0], 300 - a[0][1], 300 + a[i][0], 300 - a[i][1]);
for (i = 0; i < m - 1; i++)
{
line(300 + c[i][0], 300 - c[i][1], 300 + c[i + 1][0], 300 - c[i + 1][1]);
}
line(300 + c[0][0], 300 - c[0][1], 300 + c[i][0], 300 - c[i][1]);
int temp;
cout << "Press 1 to continue";
cin >> temp;
closegraph();
}
void transform::accept()
{
cout << "\n";
cout << "Enter the Number Of Edges:";
cin >> m;
cout << "\nEnter The Coordinates :";
for (int i = 0; i < m; i++)
{
for (int j = 0; j < 3; j++)
{
if (j >= 2)
a[i][j] = 1;
else
cin >> a[i][j];
}
}
}
int main()
{
int ch, tx, ty, sx, sy;
float deg, theta, b[20][20];
transform t;
t.accept();
cout << "\nEnter your choice";
cout << "\n1.Translation"
"\n2.Scaling"
"\n3.Rotation";
cin >> ch;
switch (ch)
{
case 1:
cout << "\nTRANSLATION OPERATION\n";
cout << "Enter value for tx and ty:";
cin >> tx >> ty;
b[0][0] = b[2][2] = b[1][1] = 1;
b[0][1] = b[0][2] = b[1][0] = b[1][2] = 0;
b[2][0] = tx;
b[2][1] = ty;
t *b;
t.object();
break;
case 2:
cout << "\nSCALING OPERATION\n";
cout << "Enter value for sx,sy:";
cin >> sx >> sy;
b[0][0] = sx;
b[1][1] = sy;
b[0][1] = b[0][2] = b[1][0] = b[1][2] = 0;
b[2][0] = b[2][1] = 0;
b[2][2] = 1;
t *b;
t.object();
break;
case 3:
cout << "\nROTATION OPERATION\n";
cout << "Enter value for angle:";
cin >> deg;
theta = deg * (3.14 / 100);
b[0][0] = b[1][1] = cos(theta);
b[0][1] = sin(theta);
b[1][0] = sin(-theta);
b[0][2] = b[1][2] = b[2][0] = b[2][1] = 0;
b[2][2] = 1;
t *b;
t.object();
break;
default:
cout << "\nInvalid choice";
}
getch();
return 0;
}