FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CG_Lab_Programs/CG_Lab_Program2/Prog2.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_Program2
/
Prog2.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
83 lines (83 loc) · 1.66 KB
Breadcrumbs
CG_Lab_Programs
/
CG_Lab_Program2
/
Prog2.cpp
Copy path
File metadata and controls
83 lines (83 loc) · 1.66 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
76
77
78
79
80
81
82
83
#
include
<
GL/glut.h
>
#
include
<
stdio.h
>
int
x, y;
int
rFlag =
0
;
void
draw_pixel
(
float
x1,
float
y1)
{
glColor3f
(
0.0
,
0.0
,
1.0
);
glPointSize
(
5.0
);
glBegin
(
GL_POINTS
);
glVertex2f
(x1, y1);
glEnd
();
}
void
triangle
()
{
glColor3f
(
1.0
,
0.0
,
0.0
);
glBegin
(
GL_POLYGON
);
glVertex2f
(
100
,
100
);
glVertex2f
(
250
,
400
);
glVertex2f
(
400
,
100
);
glEnd
();
}
float
th =
0.0
;
float
trX =
0.0
, trY =
0.0
;
void
display
()
{
glClear
(
GL_COLOR_BUFFER_BIT
);
glLoadIdentity
();
if
(rFlag ==
1
)
//
Rotate Around origin
{
trX =
0.0
;
trY =
0.0
;
th +=
0.1
;
draw_pixel
(
0.0
,
0.0
);
}
if
(rFlag ==
2
)
//
Rotate Around Fixed Point
{
trX = x;
trY = y;
th +=
0.1
;
draw_pixel
(x, y);
}
glTranslatef
(trX, trY,
0.0
);
glRotatef
(th,
0.0
,
0.0
,
1.0
);
glTranslatef
(-trX, -trY,
0.0
);
triangle
();
glutPostRedisplay
();
glutSwapBuffers
();
}
void
myInit
()
{
glClearColor
(
0.0
,
0.0
,
0.0
,
1.0
);
glMatrixMode
(
GL_PROJECTION
);
glLoadIdentity
();
gluOrtho2D
(-
500.0
,
500.0
, -
500.0
,
500.0
);
glMatrixMode
(
GL_MODELVIEW
);
}
void
rotateMenu
(
int
option)
{
if
(option ==
1
)
rFlag =
1
;
if
(option ==
2
)
rFlag =
2
;
if
(option ==
3
)
rFlag =
3
;
}
void
main
(
int
argc,
char
** argv)
{
printf
(
"
Enter Fixed Points (x,y) for Roration:
\n
"
);
scanf_s
(
"
%d %d
"
, &x, &y);
glutInit
(&argc, argv);
glutInitDisplayMode
(
GLUT_DOUBLE
|
GLUT_RGB
);
glutInitWindowSize
(
500
,
500
);
glutInitWindowPosition
(
0
,
0
);
glutCreateWindow
(
"
Create and Rotate Triangle USN:1AH18CS092
"
);
myInit
();
glutDisplayFunc
(display);
glutCreateMenu
(rotateMenu);
glutAddMenuEntry
(
"
Rotate around ORIGIN
"
,
1
);
glutAddMenuEntry
(
"
Rotate around FIXED POINT
"
,
2
);
glutAddMenuEntry
(
"
Stop Rotation
"
,
3
);
glutAttachMenu
(
GLUT_RIGHT_BUTTON
);
glutMainLoop
();
}
Back
|
FazBrowse Home
|
New Git URL