-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhouse.cpp
161 lines (141 loc) · 2.61 KB
/
house.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include<iostream>
#include<cmath>
#include<algorithm>
#include<GL/glut.h>
using namespace std;
int xr,yr,t,m,c;
float house[11][2] = {
{100,100},
{140,100},
{140,200},
{180,200},
{180,100},
{220,100},
{220,250},
{250,250},
{160,300},
{70,250},
{100,250}
};
void drawHouse(){
glBegin(GL_LINE_LOOP);
for(int i=0;i<11;i++)
glVertex2fv(house[i]);
glEnd();
}
void display1(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
drawHouse();
glPushMatrix();
glTranslatef(xr,yr,0);
glRotatef(t,0,0,1);
glTranslatef(-xr,-yr,0);
glColor3f(0,0,1);
drawHouse();
glPopMatrix();
glFlush();
}
void display2(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
drawHouse();
glColor3f(0,1,0);
glBegin(GL_LINES);
glVertex2f(0,c);
glVertex2f(500,c);
glEnd();
glPushMatrix();
glTranslatef(0,c,0);
glScalef(1,-1,1);
glTranslatef(0,-c,0);
glColor3f(0,0,1);
drawHouse();
glPopMatrix();
glFlush();
}
void display3(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
drawHouse();
glColor3f(0,1,0);
glBegin(GL_LINES);
glVertex2f(c,0);
glVertex2f(c,500);
glEnd();
glPushMatrix();
glTranslatef(c,0,0);
glScalef(-1,1,1);
glTranslatef(-c,0,0);
glColor3f(0,0,1);
drawHouse();
glPopMatrix();
glFlush();
}
void display4(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
drawHouse();
int y1 = c;
int y2 = m*500+c;
glColor3f(0,1,0);
glBegin(GL_LINES);
glVertex2f(0,y1);
glVertex2f(500,y2);
glEnd();
float r = atan(m) * 180 / 3.142; ///////////////////
glPushMatrix();
glTranslatef(0,c,0);
glRotatef(r,0,0,1);
glScalef(1,-1,1);
glRotatef(-r,0,0,1);
glTranslatef(0,-c,0);
glColor3f(0,0,1);
drawHouse();
glPopMatrix();
glFlush();
}
void myInit(){
glClearColor(1,1,1,1);
gluOrtho2D(0,500,0,500);
}
int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100,100);
cout<<"Enter 1 for rotate and 2 for reflect\n";
int ch;
cin>>ch;
switch(ch){
case 1: cout<<"Enter xr,yr,t\n";
cin>>xr>>yr>>t;
glutCreateWindow("Rotate");
glutDisplayFunc(display1);
break;
case 2: cout<<"1:X axis, 2:Y axis, 3:Y=mX+c\n";
int ch1;
cin>>ch1;
if(ch1 == 1){
cout<<"Enter c\n";
cin>>c;
glutCreateWindow("Reflect X axis");
glutDisplayFunc(display2);
}
else if(ch1 == 2){
cout<<"Enter c\n";
cin>>c;
glutCreateWindow("Reflect Y axis");
glutDisplayFunc(display3);
}
else{
cout<<"Enter m,c\n";
cin>>m>>c;
glutCreateWindow("Reflect about y=mx+c");
glutDisplayFunc(display4);
}
break;
}
myInit();
glutMainLoop();
}