forked from rahulvhegde/Computer-graphics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcube_user.c
More file actions
94 lines (94 loc) · 1.98 KB
/
Copy pathcube_user.c
File metadata and controls
94 lines (94 loc) · 1.98 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
#include<stdio.h>
#include<GL/glut.h>
GLfloat vert[8][3]={{-250,250,-250},{250,250,-250},{250,-250,-250},{-250,-250,-250},{-250,250,250},{250,250,250},{250,-250,250},{-250,-250,250}};
GLfloat view1[]={0,0,500};
int v,theta,x;
void init();
void display();
void drawcube(GLfloat *a,GLfloat *b,GLfloat *c,GLfloat *d,GLfloat *e,GLfloat *f,GLfloat *g,GLfloat *h);
void drawsquare(GLfloat *a,GLfloat *b,GLfloat *c,GLfloat *d);
void keys(unsigned char ki,int x,int y);
void main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowPosition(60,60);
glutInitWindowSize(720,620);
glutCreateWindow("Perspective viewing of color cube");
init();
glEnable(GL_DEPTH_TEST);
glutKeyboardFunc(keys);
glutDisplayFunc(display);
glutMainLoop();
}
void init()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-500,500,-500,500,500,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(view1[0],view1[1],view1[2],0,0,0,0,1,0);
drawcube(vert[0],vert[1],vert[2],vert[3],vert[4],vert[5],vert[6],vert[7]);
glLoadIdentity();
glFlush();
glutSwapBuffers();
}
void drawcube(GLfloat *a,GLfloat *b,GLfloat *c,GLfloat *d,GLfloat *e,GLfloat *f,GLfloat *g,GLfloat *h)
{
glColor3f(1,0,0);
drawsquare(e,f,g,h);
glColor3f(0,1,0);
drawsquare(e,f,b,a);
glColor3f(0,0,1);
drawsquare(h,g,c,d);
glColor3f(1,1,0);
drawsquare(a,e,h,d);
glColor3f(1,0,1);
drawsquare(b,f,g,c);
glColor3f(0,1,1);
drawsquare(a,b,c,d);
}
void drawsquare(GLfloat *a,GLfloat *b,GLfloat *c,GLfloat *d)
{
glBegin(GL_POLYGON);
glVertex3fv(a);
glVertex3fv(b);
glVertex3fv(c);
glVertex3fv(d);
glEnd();
}
void keys(unsigned char ki,int x,int y)
{
if(ki=='x')
{
view1[0]-=1;
}
if(ki=='X')
{
view1[0]+=1;
}
if(ki=='y')
{
view1[1]-=1;
}
if(ki=='Y')
{
view1[1]+=1;
}
if(ki=='z')
{
view1[2]-=1;
}
if(ki=='Z')
{
view1[2]+=1;
}
glutPostRedisplay();
}