mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Shapes.cpp
Go to the documentation of this file.
1 
6 #include "GlobalGL.h"
7 #include "Shapes.h"
8 
9 Shapes::Shapes(void) {
10 }
11 
12 Shapes::~Shapes(void) {
13 }
14 
15 void Shapes::drawCircle( Vector3 pos, GLint n, GLfloat r, const GLfloat *colorCenter, const GLfloat *colorSurface ) {
16  drawCircle( pos.x, pos.y, pos.z, n, r, colorCenter, colorSurface );
17 }
18 
19 void Shapes::drawCircle( GLfloat xPos, GLfloat yPos, GLfloat zPos, GLint n, GLfloat r, const GLfloat *colorCenter, const GLfloat *colorSurface ) {
20  int i;
21  float alphaPi = ( ( 360.0/n ) / 180.0) * M_PI;
22  if(n <3 )
23  printf("\nFehler! Mindestens 3 Ecken!.\n\n");
24  glBegin( GL_TRIANGLE_FAN );
25  glColor3fv(colorCenter);
26  glVertex3f( xPos + r/3, yPos + r/3, 0 );
27  glColor3fv(colorSurface);
28  for(i=0; i <= n; i++)
29  glVertex3f(xPos + cos(i * alphaPi + M_PI_2)*r, yPos + sin(i * alphaPi + M_PI_2)*r, zPos);
30  glEnd();
31 }
32 
33 void Shapes::drawCircleTex( Vector3 pos, GLint n, GLfloat r ) {
34  drawCircleTex( pos.x, pos.y, pos.z, n, r );
35 }
36 
37 void Shapes::drawCircleTex( GLfloat xPos, GLfloat yPos, GLfloat zPos, GLint n, GLfloat r ) {
38  int i;
39  float alphaPi = ( ( 360.0/n ) / 180.0) * M_PI;
40  if(n <3 )
41  printf("\nFehler! Mindestens 3 Ecken!.\n\n");
42  glBegin( GL_TRIANGLE_FAN );
43  glTexCoord2f( 0.5, 0.5 );
44  glVertex3f( xPos, yPos, 0 );
45  for(i=0; i <= n; i++) {
46  // texcoords generated as distances +- 0.5 from center
47  glTexCoord2f( 0.5 + cos(i * alphaPi + M_PI_2) * 0.5, 0.5 + sin(i * alphaPi + M_PI_2) * 0.5 );
48  glVertex3f( xPos + cos(i * alphaPi + M_PI_2)*r, yPos + sin(i * alphaPi + M_PI_2)*r, zPos );
49  }
50  glEnd();
51 }
52 
53 void Shapes::drawCircleTex( GLfloat xPos, GLfloat yPos, GLfloat zPos, GLint n, GLfloat r, const GLfloat *colorCenter, const GLfloat *colorSurface ) {
54  int i;
55  float alphaPi = ( ( 360.0/n ) / 180.0) * M_PI;
56  if(n <3 )
57  printf("\nFehler! Mindestens 3 Ecken!.\n\n");
58  glBegin( GL_TRIANGLE_FAN );
59  glColor3fv( colorCenter );
60  glTexCoord2f( 0.5, 0.5 );
61  glVertex3f( xPos, yPos, 0 );
62  glColor3fv( colorSurface );
63  for(i=0; i <= n; i++) {
64  // texcoords generated as distances +- 0.5 from center
65  glTexCoord2f(0.5 + cos( i * alphaPi + M_PI_2 ) * 0.5, 0.5 + sin( i * alphaPi + M_PI_2 ) * 0.5 );
66  glVertex3f( xPos + cos(i * alphaPi + M_PI_2)*r, yPos + sin(i * alphaPi + M_PI_2)*r, zPos );
67  }
68  glEnd();
69 }
70 
71 void Shapes::drawCircle( GLfloat xPos, GLfloat yPos, GLfloat zPos, GLint n, GLfloat r, float segmentStart, float segmentEnd, const GLfloat *colorCenter, const GLfloat *colorSurface ) {
72  int i;
73  float alphaPi = ( 360.0/n ) * ANGLE2DEG;
74  if(n <3 )
75  printf("\nFehler! Mindestens 3 Ecken!.\n\n");
76  glBegin( GL_TRIANGLE_FAN );
77  glColor3fv(colorCenter);
78  glVertex3f( xPos + r/3, yPos + r/3, 0 );
79  glColor3fv(colorSurface);
80  for(i=0; i <= n; i++)
81  glVertex3f(xPos + cos(i * alphaPi + M_PI_2)*r, yPos + sin(i * alphaPi + M_PI_2)*r, zPos);
82  glEnd();
83 }
84 
85 void Shapes::drawCircleShape( GLfloat xPos, GLfloat yPos, GLfloat zPos, GLint n, GLfloat r, const GLfloat * color ) {
86  int i;
87  float alphaPi = ( 360.0/n ) * ANGLE2DEG;
88 
89  if(n < 3)
90  printf("\nFehler! Mindestens 3 Ecken!.\n\n");
91  glLineWidth( 2 );
92  glColor3fv( color );
93  glBegin( GL_LINE_LOOP );
94  for(i=0; i <= n; i++)
95  glVertex3f(xPos + cos(i * alphaPi + M_PI_2)*r, yPos + sin(i * alphaPi + M_PI_2)*r, zPos);
96  glEnd();
97 }
98 
99 void Shapes::drawCircleShape( GLfloat xPos, GLfloat yPos, GLfloat zPos, GLint n, GLfloat r, float segmentStart, float segmentEnd, const GLfloat * color ) {
100  int i;
101  float segmentStart2 = segmentStart - floor(segmentStart/360.0f)*360.0;
102  float segmentEnd2 = segmentEnd - floor(segmentEnd/360.0f)*360.0;
103  float alphaPi;
104  if( segmentEnd2 < segmentStart2 )
105  alphaPi = ((360.0 - segmentStart2 + segmentEnd2 )/n) * ANGLE2DEG;
106  else
107  alphaPi = ((segmentEnd2 - segmentStart2)/n) * ANGLE2DEG;
108  //float alphaPi = ( 360.0/n ) * ANGLE2DEG;
109 
110  if(n < 3)
111  printf("\nFehler! Mindestens 3 Ecken!.\n\n");
112  glLineWidth( 2 );
113  glColor3fv( color );
114  glBegin( GL_LINE_STRIP );
115  for(i=0; i <= n; i++)
116  glVertex3f(xPos + cos(i * alphaPi + M_PI_2 + segmentStart2*ANGLE2DEG)*r, yPos + sin(i * alphaPi + M_PI_2 + segmentStart2*ANGLE2DEG)*r, zPos);
117  glEnd();
118 }
119 
120 void Shapes::drawCircleShape( Vector3 pos, GLint n, GLfloat r, float segmentStart, float segmentEnd, const GLfloat * color ) {
121  drawCircleShape( (GLfloat)pos.x, (GLfloat)pos.y, (GLfloat)pos.z, n, r, segmentStart, segmentEnd, color );
122 }
123 
124 
125 void Shapes::drawCircleShapeDashed( GLfloat xPos, GLfloat yPos, GLfloat zPos, GLint n, GLfloat r, const GLfloat * color ) {
126  int i;
127  float alphaPi = ( 360.0/n ) * ANGLE2DEG;
128 
129  if(n < 3)
130  printf("\nFehler! Mindestens 3 Ecken!.\n\n");
131  glLineWidth( 2 );
132  glColor3fv( color );
133  glBegin( GL_LINES );
134  for(i=0; i <= n; i+=2)
135  glVertex3f(xPos + cos(i * alphaPi + M_PI_2)*r, yPos + sin(i * alphaPi + M_PI_2)*r, zPos);
136  glEnd();
137 }
138 
139 void Shapes::drawRect( GLfloat xCenterPos, GLfloat yCenterPos, GLfloat zPos, GLfloat width, GLfloat height ) {
140  glBegin( GL_QUADS );
141  glVertex3f( xCenterPos - width*0.5, yCenterPos + height*0.5, zPos );
142  glVertex3f( xCenterPos - width*0.5, yCenterPos - height*0.5, zPos );
143  glVertex3f( xCenterPos + width*0.5, yCenterPos - height*0.5, zPos );
144  glVertex3f( xCenterPos + width*0.5, yCenterPos + height*0.5, zPos );
145  glEnd();
146 }