-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab1.cpp
More file actions
137 lines (122 loc) · 3.13 KB
/
lab1.cpp
File metadata and controls
137 lines (122 loc) · 3.13 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <Windows.h>
#include <GL/glut.h>
#include <math.h>
void init() {
glClearColor(1.0, 1.0, 1.0, 1.0);
gluOrtho2D(-10, 10, -12, 10);
}
void drawRoof(float startX, float startY, float radius, float start, float size) {
// Roof
glBegin(GL_LINE_STRIP);
for (float i = start; i < size + start; i++) {
float degreesInRadians = i * 3.1415926535 / 180;
glVertex2f(cos(degreesInRadians) * radius + startX, sin(degreesInRadians) * radius + startY);
}
glEnd();
}
void drawMoon() {
float startX = 7.0, startY = 7.0, radius = 2.0, size = 360;
glColor3f(0.858824 , 0.858824 , 0.439216);
glBegin(GL_POLYGON);
for (float i = 0; i < size; i++) {
float degreesInRadians = i * 3.1415926535 / 180;
glVertex2f(cos(degreesInRadians) * radius + startX, sin(degreesInRadians) * radius + startY);
}
glEnd();
startX = 7.0 + 1.0;
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
for (float i = 0; i < size; i++) {
float degreesInRadians = i * 3.1415926535 / 180;
glVertex2f(cos(degreesInRadians) * radius + startX, sin(degreesInRadians) * radius + startY);
}
glEnd();
}
void drawWalls() {
// Walls
glBegin(GL_LINE_LOOP);
glVertex2f(-8, 1);
glVertex2f(8, 1);
glVertex2f(8, -1);
glVertex2f(6.5, -1);
glVertex2f(6.5, -10);
glVertex2f(-6.5, -10);
glVertex2f(-6.5, -1);
glVertex2f(-8, -1);
glEnd();
}
void drawDoor() {
// Door
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(1.5, -10);
glVertex2f(-1.5, -10);
glVertex2f(-1.5, -5);
glVertex2f(1.5, -5);
glEnd();
}
void drawWindows(float point1[2], float point2[2], float point3[2], float point4[2]) {
glBegin(GL_LINE_LOOP);
glVertex2f(point1[0], point1[1]);
glVertex2f(point2[0], point2[1]);
glVertex2f(point3[0], point3[1]);
glVertex2f(point4[0], point4[1]);
glEnd();
}
void drawKnob() {
float rad;
// Door Knob
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_POLYGON);
for (int i = 0; i <= 360; i++)
{
rad = i * 3.142 / 180;
glVertex2f(1.0 + 0.2 * sin(rad), -7.5 + 0.2 * cos(rad));
}
glEnd();
}
void house() {
float point1[2] = {-4.5, -5}, point2[2] = {-4.5, -7.5}, point3[2] = {-2.0, -7.5}, point4[2] = {-2.0, -5};
float point5[2] = { 2.0, -5 }, point6[2] = { 2.0, -7.5 }, point7[2] = { 4.5, -7.5 }, point8[2] = { 4.5, -5 };
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(2.0);//sets the width of the line
drawMoon();
glColor3f(0.0, 0.0, 1.0);
drawRoof(0, 1, 4, 0, 180);
drawWalls();
drawDoor();
//Window 1
drawWindows(point1, point2, point3, point4);
//Window 2
drawWindows(point5, point6, point7, point8);
glColor3f(0.0, 0.0, 1.0);
// Window panes 1
glBegin(GL_LINES);
glVertex2f(-3.25, -5);
glVertex2f(-3.25, -7.5);
glEnd();
glBegin(GL_LINES);
glVertex2f(-4.5, -6.25);
glVertex2f(-2, -6.25);
glEnd();
// Window panes 2
glBegin(GL_LINES);
glVertex2f(3.25, -5);
glVertex2f(3.25, -7.5);
glEnd();
glBegin(GL_LINES);
glVertex2f(4.5, -6.25);
glVertex2f(2, -6.25);
glEnd();
drawKnob();
glFlush();//enables fast execution of statements
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitWindowPosition(50, 100);
glutInitWindowSize(500, 500); glutCreateWindow("Simple House");
init();
glutDisplayFunc(house);
glutMainLoop();
}