FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CG_Lab_Programs/CG_Lab_Program7/prog7.cpp at master · sidpug/CG_Lab_Programs · GitHub
sidpug
CG_Lab_Programs
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
CG_Lab_Programs
/
CG_Lab_Program7
/
prog7.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
75 lines (72 loc) · 1.87 KB
Breadcrumbs
CG_Lab_Programs
/
CG_Lab_Program7
/
prog7.cpp
Copy path
File metadata and controls
75 lines (72 loc) · 1.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
stdlib.h
>
#
include
<
stdio.h
>
#
include
<
GL/glut.h
>
typedef
float
point [
3
];
int
n;
point v[] = { {
0.0
,
0.0
,
0.0
}, {
0.0
,
1.0
, -
1.0
},{-
1.0
, -
1.0
, -
1.0
}, {
1.0
, -
1.0
, -
1.0
} };
void
triangle
(point a, point b, point c)
{
glBegin
(
GL_POLYGON
);
glVertex3fv
(a);
glVertex3fv
(b);
glVertex3fv
(c);
glEnd
();
}
void
divide_triangle
(point a, point b, point c,
int
m)
{
point v1, v2, v3;
int
j;
if
(m >
0
)
{
for
(j =
0
; j <
3
; j++) v1[j] = (a[j] + b[j]) /
2
;
for
(j =
0
; j <
3
; j++) v2[j] = (a[j] + c[j]) /
2
;
for
(j =
0
; j <
3
; j++) v3[j] = (b[j] + c[j]) /
2
;
divide_triangle
(a, v1, v2, m -
1
);
divide_triangle
(c, v2, v3, m -
1
);
divide_triangle
(b, v3, v1, m -
1
);
}
else
(
triangle
(a, b, c));
/*
draw triangle at end of recursion
*/
}
void
tetrahedron
(
int
m)
{
glColor3f
(
1.0
,
0.0
,
0.0
);
divide_triangle
(v[
0
], v[
1
], v[
2
], m);
glColor3f
(
0.0
,
1.0
,
0.0
);
divide_triangle
(v[
3
], v[
2
], v[
1
], m);
glColor3f
(
0.0
,
0.0
,
1.0
);
divide_triangle
(v[
0
], v[
3
], v[
1
], m);
glColor3f
(
0.0
,
0.0
,
0.0
);
divide_triangle
(v[
0
], v[
2
], v[
3
], m);
}
void
display
(
void
)
{
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
glLoadIdentity
();
tetrahedron
(n);
glFlush
();
}
void
myReshape
(
int
w,
int
h)
{
glViewport
(
0
,
0
, w, h);
glMatrixMode
(
GL_PROJECTION
);
glLoadIdentity
();
if
(w <= h)
glOrtho
(-
2.0
,
2.0
, -
2.0
* (GLfloat)h / (GLfloat)w,
2.0
* (GLfloat)h / (GLfloat)w, -
10.0
,
10.0
);
else
glOrtho
(-
2.0
* (GLfloat)w / (GLfloat)h,
2.0
* (GLfloat)w / (GLfloat)h, -
2.0
,
2.0
, -
10.0
,
10.0
);
glMatrixMode
(
GL_MODELVIEW
);
}
void
main
(
int
argc,
char
** argv)
{
printf
(
"
Enter the Number of Divisions ?
"
);
scanf_s
(
"
%d
"
, &n);
glutInit
(&argc, argv);
glutInitDisplayMode
(
GLUT_SINGLE
|
GLUT_RGB
|
GLUT_DEPTH
);
glutInitWindowSize
(
500
,
500
);
glutCreateWindow
(
"
3D Gasket USN:1AH18CS092
"
);
glutReshapeFunc
(myReshape);
glutDisplayFunc
(display);
glEnable
(
GL_DEPTH_TEST
);
glClearColor
(
1.0
,
1.0
,
1.0
,
1.0
);
glutMainLoop
();
}
Back
|
FazBrowse Home
|
New Git URL