-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphics.cpp
85 lines (72 loc) · 2.58 KB
/
Graphics.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
#include "src/Graphics.h"
Graphics::Graphics() : _initialized(false)
{
}
void Graphics::initialize(std::string type)
{
//Add functionality to create different shapes with if statement
if(!_initialized)
{
if(type == "circle" || type == "Circle" || type == "CIRCLE")
createCircle(_verts,_norms);
else
createCircle(_verts,_norms);
//_verts.push_back(0.0f); _verts.push_back(0.0f); _verts.push_back(0.0f);
//_verts.push_back(1.0f); _verts.push_back(0.0f); _verts.push_back(0.0f);
//_verts.push_back(0.5f); _verts.push_back(1.0f); _verts.push_back(0.0f);
}
_initialized = true;
}
void Graphics::drawSphere()
{
float xx, yy, zz;
float xxp, yyp, zzp;
for(float angle2 = -3.1416f/2.0f; angle2 <= 3.1416f/2.0f; angle2 += RESOL)
{
glBegin(GL_TRIANGLE_STRIP);
glLoadIdentity();
for(float angle1 = 0.0f; angle1 <= 3.1416f*2.0f; angle1 += RESOL)
{
xx = cos(angle1)*cos(angle2);
yy = sin(angle2);
zz = sin(angle1)*cos(angle2);
xxp = cos(angle1)*cos(angle2 + RESOL);
yyp = sin(angle2 +RESOL);
zzp = sin(angle1)*cos(angle2 + RESOL);
glNormal3d(0, 0, 1);
glVertex3f(xx, yy, zz);
glVertex3f(xxp, yyp, zzp);
}
glEnd();
}
}
void Graphics::createCircle(std::vector<float>& verts,std::vector<float>& norms)
{
float xx, yy, zz;
float xxp,yyp,zzp;
Vector3f n;
Vector3f trans;
for(float angle2 = -3.1416f; angle2 <= 3.1416f; angle2 += RESOL)
{
for(float angle1 = 0.0f; angle1 <= 3.1416f*2.0f; angle1 += RESOL)
{
xx = cos(angle1)*cos(angle2);
yy = sin(angle2);
zz = sin(angle1)*cos(angle2);
xxp = cos(angle1)*cos(angle2 + RESOL);
yyp = sin(angle2 +RESOL);
zzp = sin(angle1)*cos(angle2 + RESOL);
// xx = sin(angle2)*cos(angle1);
// yy = sin(angle2)*sin(angle1);
// zz = cos(angle2);
verts.push_back(xx); verts.push_back(yy); verts.push_back(zz);
n = Vector3f(xx,yy,zz);
n.normalize();
norms.push_back(n.x); norms.push_back(n.y); norms.push_back(n.z);
verts.push_back(xxp); verts.push_back(yyp); verts.push_back(zzp);
n = Vector3f(xxp,yyp,zzp);
n.normalize();
norms.push_back(n.x); norms.push_back(n.y); norms.push_back(n.z);
}
}
}