-
Notifications
You must be signed in to change notification settings - Fork 4
/
torus.cpp
105 lines (90 loc) · 2.53 KB
/
torus.cpp
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
96
97
98
99
100
101
102
103
104
105
#ifdef __APPLE_CC__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <cmath>
//#include <GLFW/glfw3.h>
GLdouble xRotated=0.0, yRotated=90.0, zRotated=0.0;
GLdouble xx=0.0, yy=0.0, zz=-3.0 ;
GLdouble innerRaidus=0.15;
GLdouble outterRaidus=1.0;
GLint sides =50;
GLint rings =50;
void sphere(GLfloat radius, int slices, int stacks)
{
glPushMatrix();
glColor3f(1.0, 0.0, 0.0);
// glRotatef(-90.0, 1.0, 0.0, 0.0);
glTranslatef(xx, yy, zz);
glutWireSphere(radius, slices, stacks);
glPopMatrix();
}
void displayTorus(void)
{
glMatrixMode(GL_MODELVIEW); // clear the drawing buffer.
glClear(GL_COLOR_BUFFER_BIT); // clear the identity matrix.
glLoadIdentity();
glPushMatrix();
glTranslatef(1.5,0.0,-3.0);
glColor3f(1.0, 1.0, 0.0);
glRotatef(xRotated,1.0,0.0,0.0);
glRotatef(yRotated,0.0,1.0,0.0);
glRotatef(zRotated,0.0,0.0,1.0);
glScalef(1.0,1.0,1.0);
glutSolidTorus(innerRaidus,outterRaidus,sides,rings);
glPopMatrix();
glPushMatrix();
glTranslatef(-1.5,0.0,-3.0);
glColor3f(1.0, 1.0, 0.0);
glRotatef(xRotated,1.0,0.0,0.0);
glRotatef(yRotated,0.0,1.0,0.0);
glRotatef(zRotated,0.0,0.0,1.0);
glScalef(1.0,1.0,1.0);
glutSolidTorus(innerRaidus,outterRaidus,sides,rings);
glPopMatrix();
// Flush buffers to screen
//glPushMatrix();
// glColor3f(0.0, 0.0, 1.0);
sphere(0.05, 50, 50);
//glPopMatrix();
glFlush();
// sawp buffers called because we are using double buffering
// glutSwapBuffers();
}
void reshapeTorus(int x, int y)
{
if (y == 0 || x == 0) return; //Nothing is visible then, so return
//Set a new projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Angle of view:40 degrees
//Near clipping plane distance: 0.5
//Far clipping plane distance: 20.0
gluPerspective(80.0,(GLdouble)x/(GLdouble)y,0.01,50.0);
glViewport(0,0,x,y); //Use the whole window for rendering
}
void idleTorus(void)
{
// yRotated += 0.0;
xx += 0.003;
yy += 0.003;
displayTorus();
}
int main (int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(1200,1200);
glutCreateWindow("Plasma");
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glClearColor(0.0,0.0,0.0,0.0);
//Assign the function used in events
glutDisplayFunc(displayTorus);
glutReshapeFunc(reshapeTorus);
glutIdleFunc(idleTorus);
//Let start glut loop
glutMainLoop();
return 0;
}
//g++ -framework OpenGL -framework GLUT torus.cpp