-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab4.cpp
More file actions
73 lines (72 loc) · 1.53 KB
/
lab4.cpp
File metadata and controls
73 lines (72 loc) · 1.53 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
#include<GL/glut.h>
#include<stdio.h>
#include<stdlib.h>
float ver[8][3]={{0,0,0},{1,0,0},{1,1,0},{0,1,0},{0,0,1},{1,0,1},{1,1,1},{0,1,1}};
float v1[3]={0,0,5};
void polygon(int a,int b,int c,int d);
void polygon1();
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(v1[0],v1[1],v1[2],0,0,0,0,1,0);
polygon1();
glFlush();
}
void polygon1()
{
polygon(0,1,2,3);
polygon(4,5,6,7);
polygon(5,1,2,6);
polygon(4,0,3,7);
polygon(4,5,1,0);
polygon(7,6,2,3);
}
void polygon(int a,int b,int c,int d)
{
glBegin(GL_POLYGON);
glColor3fv(ver[a]);
glVertex3fv(ver[a]);
glColor3fv(ver[b]);
glVertex3fv(ver[b]);
glColor3fv(ver[c]);
glVertex3fv(ver[c]);
glColor3fv(ver[d]);
glVertex3fv(ver[d]);
glEnd();
}
void key(char f,int x,int y)
{
if(f=='x')v1[0]-=.10;
if(f=='X')v1[0]+=.10;
if(f=='y')v1[1]-=.10;
if(f=='Y')v1[1]+=.10;
if(f=='z')v1[2]-=.10;
if(f=='Z')v1[2]+=.10;
display();
}
void Reshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
glFrustum(-2.0,2.0,-2.0*h/w,0*h/w,2.0,20);
else
glFrustum(-2.0*w/h,2.0*w/h,-2.0,2.0,2.0,20);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc,char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(10,10);
glutCreateWindow("Spinning Color Cube : C Tathva");
glutDisplayFunc(display);
glutKeyboardFunc((void (*)(unsigned char, int, int))key);
glEnable(GL_DEPTH_TEST);
glutReshapeFunc(Reshape);
glutMainLoop();
return 0;
}