-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsphere.cpp
More file actions
54 lines (46 loc) · 999 Bytes
/
sphere.cpp
File metadata and controls
54 lines (46 loc) · 999 Bytes
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
/* sphere.cpp
* Omkar H. Ramachandran
* omkar.ramachandran@colorado.edu
*
* Functions for rendering skydome
*
*/
#include "general.h"
void Vertex(double th,double ph,double R, double G, double B){
glColor3f(R , G , B);
glVertex3d(sin(th*DEGtoRAD)*cos(ph*DEGtoRAD) , sin(th*DEGtoRAD)*sin(ph*DEGtoRAD) , cos(th*DEGtoRAD));
}
void sphere(double R,double G,double B,double r, bool wireframe, bool use_texture){
int th,ph;
// Save transformation
glPushMatrix();
// Offset and scale
// glTranslated(x,y,z);
glScaled(r,r,r);
// Latitude bands
for (th=0;th<180;th+=d)
{
if(wireframe)
glBegin(GL_LINES);
else
glBegin(GL_QUAD_STRIP);
for (ph=0;ph<=360;ph+=d){
double t,s;
if(use_texture){
s = (ph)/360.0;
t = (th)/180.0;
glTexCoord2f(s,t);
}
Vertex(th,ph,R,G,B);
if(use_texture){
s = (ph)/360.0;
t = (th+d)/180.0;
glTexCoord2f(s,t);
}
Vertex(th+d,ph,R,G,B);
}
glEnd();
}
// Undo transformations
glPopMatrix();
}