-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameterizedHouse.txt
70 lines (58 loc) · 2.12 KB
/
parameterizedHouse.txt
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
#include<Windows.h>
#include<gl/GL.h>
#include<gl/glu.h>
#include<gl/glut.h>
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0); // set the background to white
glColor3f(0.0f, 0.0f, 0.0f); // set the drawing color to black
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void parameterizedHouse(POINT peak, GLint width, GLint height) {
glBegin(GL_LINE_LOOP);
glVertex2i(peak.x, peak.y); // draw the shell of the house
glVertex2i(peak.x + width / 2, peak.y - 3 * height / 8);//topRight
glVertex2i(peak.x + width / 2, peak.y - height);//downRight
glVertex2i(peak.x - width / 2, peak.y - height);//downLeft
glVertex2i(peak.x - width / 2, peak.y - 3 * height / 8);//topLeft
glVertex2i(peak.x - width / 3, peak.y - 10 * height / 40);//left...
glVertex2i(peak.x - width / 3, peak.y + height / 6);//downLeft...
glVertex2i(peak.x - width / 6, peak.y + height / 6);//downRight...
glVertex2i(peak.x - width / 6, peak.y - 10 * height / 80);//right...
glEnd();
glBegin(GL_LINE_LOOP); //draw the door
glVertex2i(peak.x - width / 10, peak.y - height );//downRight
glVertex2i(peak.x - width / 10, peak.y - 10 * height / 20);
glVertex2i(peak.x - width / 3, peak.y - 10 * height / 20);
glVertex2i(peak.x - width / 3, peak.y - height);//downLeft
glEnd();
glBegin(GL_LINE_LOOP); //draw the windows
glVertex2i(peak.x + width / 10, peak.y - height / 3);//downRight
glVertex2i(peak.x + width / 10, peak.y - 10 * height / 20);
glVertex2i(peak.x + width / 3, peak.y - 10 * height / 20);
glVertex2i(peak.x + width / 3, peak.y - height / 3);//downLeft
glEnd();
}
void mouse(int bin, int state, int x, int y) {
if (bin == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
POINT p;
p.x = x;
p.y = 480.0 - y;
glClear(GL_COLOR_BUFFER_BIT);
parameterizedHouse(p, 250, 250);
glFlush();
}
}
void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(300, 100);
glutCreateWindow("House");
glutMouseFunc(mouse);
myInit();
glutMainLoop();
}