-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
131 lines (114 loc) · 2.79 KB
/
main.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
#include <iostream>
#include <math.h>
#include<GL/glut.h>
#include<GL/gl.h>
#include<vector>
using namespace std;
vector<float> points;
int angleZ = 0,angleX = 0;
GLfloat v0[] = {0.0, -1.0, +2.0 };
GLfloat v1[] = {+1.73205081, -1.0, -1.0 };
GLfloat v2[] = {-1.73205081, -1.0, -1.0 };
void myinit()
{
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glOrtho(-5.0, 5.0, -5.0, 5.0, -1.0f, 1.0f);
//gluOrtho2D(-1.0,11.0,-1.0,11.0);
glMatrixMode(GL_MODELVIEW);
}
void reshape(GLsizei width, GLsizei height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5.0, 5.0, -5.0, 5.0, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void spkeyboard(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_RIGHT:
angleZ += 5;
glutPostRedisplay();
break;
case GLUT_KEY_LEFT:
angleZ -= 5;
glutPostRedisplay();
break;
case GLUT_KEY_UP:
angleX += 5;
glutPostRedisplay();
break;
case GLUT_KEY_DOWN:
angleX -= 5;
glutPostRedisplay();
break;
default:
break;
}
}
void tetaedro ()
{
static const GLfloat P1[3] = { 0.0, -1.0, +2.0 };
static const GLfloat P2[3] = { +1.73205081, -1.0, -1.0 };
static const GLfloat P3[3] = { -1.73205081, -1.0, -1.0 };
static const GLfloat P4[3] = { 0.0, +2.0, 0.0 };
static const GLfloat * const coords[4][3] =
{
{ P1, P2, P3 }, { P1, P3, P4 }, { P1, P4, P2 }, { P2, P4, P3 }
};
glTranslatef(0.0, 0.0, -10.0);
glRotatef(angleX, 1.0, 0.0, 0.0);
//glRotatef(rotationY, 0.0, 1.0, 0.0);
glRotatef(angleZ, 0.0, 0.0, 1.0);
for (int i = 0; i < 4; ++i)
{
glLoadName(i);
glBegin(GL_TRIANGLES);
for (int j = 0; j < 3; ++j)
{
glColor3f(0.0,0.0,0.0);
glVertex3f(coords[i][j][0], coords[i][j][1],
coords[i][j][2]);
}
glEnd();
}
}
void init(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glShadeModel (GL_SMOOTH);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
tetaedro();
glFlush();
}
void reshape1(int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10.0, 10.0, -10.0, 10.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (800, 800);
glutInitWindowPosition (100, 100);
glutCreateWindow("TETRAEDRO");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape1);
glutSpecialFunc(spkeyboard);
glutMainLoop();
return 0;
}