-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprg4.txt
95 lines (82 loc) · 2.18 KB
/
prg4.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
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
//#include<windows.h>
#include<GL/glu.h>
#include<GL/glut.h>
#include<stdio.h>
GLfloat Cx=0,Cy=0,Cz=3;
void MyInit()
{
glClearColor(0,0,0,1);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1,1,-1,1,2,10);
glMatrixMode(GL_MODELVIEW);
}
void Square(GLfloat A[],GLfloat B[],GLfloat C[],GLfloat D[])
{
glBegin(GL_POLYGON);
glVertex3fv(A);
glVertex3fv(B);
glVertex3fv(C);
glVertex3fv(D);
glEnd();
}
void Cube(GLfloat V0[],GLfloat V1[],GLfloat V2[],GLfloat V3[],GLfloat V4[],GLfloat V5[],GLfloat V6[],GLfloat V7[])
{
glColor3f(1,0,0);
Square(V0,V1,V2,V3);
glColor3f(0,1,0);
Square(V4,V5,V6,V7);
glColor3f(0,0,1);
Square(V0,V4,V7,V3);
glColor3f(1,1,0);
Square(V1,V5,V6,V2);
glColor3f(1,0,1);
Square(V3,V2,V6,V7);
glColor3f(0,1,1);
Square(V0,V1,V5,V4);
}
void Draw()
{
GLfloat V[8][3] = {
{-0.5, 0.5, 0.5},
{ 0.5, 0.5, 0.5},
{ 0.5,-0.5, 0.5},
{-0.5,-0.5, 0.5},
{-0.5, 0.5,-0.5},
{ 0.5, 0.5,-0.5},
{ 0.5,-0.5,-0.5},
{-0.5,-0.5,-0.5}
};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(Cx,Cy,Cz,0,0,0,0,1,0);
Cube(V[0],V[1],V[2],V[3],V[4],V[5],V[6],V[7]);
glutSwapBuffers();
}
void Key(unsigned char ch,int x,int y)
{
switch(ch)
{
case 'x' : Cx = Cx - 0.5; break;
case 'X' : Cx = Cx + 0.5; break;
case 'y' : Cy = Cy - 0.5; break;
case 'Y' : Cy = Cy + 0.5; break;
case 'z' : Cz = Cz - 0.5; break;
case 'Z' : Cz = Cz + 0.5; break;
}
glutPostRedisplay();
}
int main(int argC,char *argV[])
{
glutInit(&argC,argV);
glutInitWindowSize(600,600);
glutInitWindowPosition(100,150);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Color Cube with Camera");
MyInit();
glutDisplayFunc(Draw);
glutKeyboardFunc(Key);
glutMainLoop();
return 0;
}