-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosutorus.cpp
64 lines (48 loc) · 1.43 KB
/
osutorus.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <GL/gl.h>
#ifndef F_PI
#define F_PI ((float)(M_PI))
#define F_2_PI ((float)(2.f*F_PI))
#define F_PI_2 ((float)(F_PI/2.f))
#endif
void
OsuTorus( float innerRadius, float outerRadius, int nsides, int nrings )
{
float ringDelta = 2.0f * F_PI / (float)nrings;
float sideDelta = 2.0f * F_PI / (float)nsides;
float theta = 0.0;
float cosTheta = 1.0;
float sinTheta = 0.0;
for( int i = 0; i < nrings; i++ )
{
float theta1 = theta + ringDelta;
float cosTheta1 = cosf(theta1);
float sinTheta1 = sinf(theta1);
float phi = 0.0;
float s0 = 1.f - (float)(i+0) / (float)nrings;
float s1 = 1.f - (float)(i+1) / (float)nrings;
glBegin( GL_TRIANGLE_STRIP );
for( int j = 0; j <= nsides; j++ )
{
float cosPhi = cosf(phi);
float sinPhi = sinf(phi);
float dist = outerRadius + innerRadius * cosPhi;
float t = 1.f - (float)j / (float)nsides;
glTexCoord2f( s0, t);
glNormal3f(cosTheta * cosPhi, sinPhi, -sinTheta * cosPhi);
glVertex3f(cosTheta * dist, innerRadius * sinPhi, -sinTheta * dist);
glTexCoord2f( s1, t );
glNormal3f( cosTheta1 * cosPhi, sinPhi, -sinTheta1 * cosPhi );
glVertex3f( cosTheta1 * dist, innerRadius * sinPhi, -sinTheta1 * dist );
phi += sideDelta;
}
glEnd( );
theta = theta1;
cosTheta = cosTheta1;
sinTheta = sinTheta1;
}
}