00001 00006 #include <stdio.h> 00007 #include <GL/glut.h> 00008 #include <GL/gl.h> 00009 #include <GL/glu.h> 00010 #include <stdlib.h> 00011 #include <unistd.h> 00012 00013 #define X 0 00014 #define Y 1 00015 #define Z 2 00016 00017 extern float campos[]; 00018 extern float speednr; 00019 extern int frametime; 00020 extern int colObject; 00021 extern int WINDOWY; 00022 extern int WINDOWX; 00023 extern int myObjectID; 00024 00025 GLfloat m_hud[] = { 0.379, 0.409, 0.666, 1.0 }; 00026 GLfloat m_hand[] = { 0.6, 0.1, 0.3, 1.0 }; 00027 00029 void DrawHand ( void ) 00030 { 00031 float finger = -0.05; 00032 float length = -0.1; 00033 00034 glMaterialfv(GL_FRONT,GL_DIFFUSE,m_hand); 00035 00036 glBegin(GL_LINES); 00037 glVertex3f(0.0,0.0,0.05); 00038 glVertex3f(0.0,0.0,0.1); 00039 glEnd(); 00040 00041 glBegin(GL_LINES); 00042 glVertex3f(-0.05,0.0,0.05); 00043 glVertex3f(0.05,0.0,0.05); 00044 glVertex3f(-0.05,0.0,0.05); 00045 glVertex3f(-0.05,0.0,-0.05); 00046 glVertex3f(0.05,0.0,0.05); 00047 glVertex3f(0.05,0.0,-0.05); 00048 glVertex3f(-0.05,0.0,-0.05); 00049 glVertex3f(0.05,0.0,-0.05); 00050 glEnd(); 00051 00052 glBegin(GL_LINES); 00053 glVertex3f(-0.05,0.0,-0.05); 00054 glVertex3f(-0.05,0.0,-0.15); 00055 00056 glVertex3f(0.05,0.0,-0.05); 00057 glVertex3f(0.05,0.0,-0.1); 00058 glVertex3f(0.05,0.0,-0.1); 00059 glVertex3f(0.05,finger,length); 00060 00061 glVertex3f(0.02,0.0,-0.05); 00062 glVertex3f(0.02,0.0,-0.1); 00063 glVertex3f(0.02,0.0,-0.1); 00064 glVertex3f(0.02,finger,length); 00065 00066 glVertex3f(-0.01,0.0,-0.05); 00067 glVertex3f(-0.01,0.0,-0.1); 00068 glVertex3f(-0.01,0.0,-0.1); 00069 glVertex3f(-0.01,finger,length); 00070 00071 glVertex3f(-0.05,0.0,-0.05); 00072 glVertex3f(-0.07,0.0,-0.05); 00073 glVertex3f(-0.07,0.0,-0.05); 00074 glVertex3f(-0.07,-0.05,-0.02); 00075 00076 glEnd(); 00077 } 00078 00079 00080 00082 00087 void DrawMatrix(float size, float number) 00088 { 00089 float x,y,z; 00090 float step; 00091 00092 step = size/number; 00093 00094 y = 0.0; 00095 00096 GLfloat m_matrixA[] = { 0.593, 0.726, 0.961, 1.0 }; 00097 GLfloat m_matrixB[] = { 0.277, 0.347, 0.496, 1.0 }; 00098 00099 glMaterialfv(GL_FRONT,GL_DIFFUSE,m_matrixA); 00100 00101 for ( x=0.0; x <= size; x += step) 00102 { 00103 glBegin(GL_LINES); 00104 glNormal3f(0.0,1.0,0.0); 00105 glVertex3f(size-x*2,y,-size); 00106 glVertex3f(size-x*2,y,size); 00107 glEnd(); 00108 } 00109 00110 for ( z=0.0; z <= size; z += step) 00111 { 00112 glBegin(GL_LINES); 00113 glNormal3f(0.0,1.0,0.0); 00114 glVertex3f(-size,y,size-z*2); 00115 glVertex3f(size,y,size-z*2); 00116 glEnd(); 00117 } 00118 00119 step = size/(number*3.0); 00120 00121 glMaterialfv(GL_FRONT,GL_DIFFUSE,m_matrixB); 00122 00123 for ( x=0.0; x <= size; x += step) 00124 { 00125 glBegin(GL_LINES); 00126 glNormal3f(0.0,1.0,0.0); 00127 glVertex3f(size-x*2,y,-size); 00128 glVertex3f(size-x*2,y,size); 00129 glEnd(); 00130 } 00131 00132 00133 for ( z=0.0; z <= size; z += step) 00134 { 00135 glBegin(GL_LINES); 00136 glNormal3f(0.0,1.0,0.0); 00137 glVertex3f(-size,y,size-z*2); 00138 glVertex3f(size,y,size-z*2); 00139 glEnd(); 00140 } 00141 00142 } 00143 00144 00146 00151 void IntToString(int x, char text[]) 00152 { 00153 int i=0,j=10; 00154 00155 if ( x == 0) 00156 { 00157 text[0] = '0'; 00158 text[1] = '\0'; 00159 } 00160 else 00161 { 00162 i = 0; 00163 if ( x < 0 ) 00164 { 00165 text[0] = '-'; 00166 x = x * -1; 00167 i++; 00168 } 00169 00170 for ( j = x; j > 0; j = j / 10, i++); 00171 00172 i--; 00173 text[i+1] = '\0'; 00174 00175 for ( ; x > 0; x = x / 10, i--) 00176 { 00177 text[i] = (char) ( x % 10 + '0'); 00178 } 00179 } 00180 } 00181 00182 00184 00189 void printstring(void *font, char *string) 00190 { 00191 int len,i; 00192 00193 len = (int) strlen(string); 00194 00195 for( i = 0; i < len; i++) 00196 glutBitmapCharacter(font,string[i]); 00197 } 00198 00200 00204 void DrawStat(void) 00205 { 00206 char text[40]; 00207 00208 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, m_hud ); 00209 00210 glRasterPos2i(1,WINDOWY-40); 00211 printstring(GLUT_BITMAP_TIMES_ROMAN_24,"The Matrix"); 00212 00213 glRasterPos2i(1,1); 00214 printstring(GLUT_BITMAP_TIMES_ROMAN_24,"Matrix:"); 00215 00216 IntToString ( 0, text ); 00217 glRasterPos2i(80,1); 00218 printstring(GLUT_BITMAP_TIMES_ROMAN_24,text); 00219 IntToString ( 0, text ); 00220 glRasterPos2i(110,1); 00221 printstring(GLUT_BITMAP_TIMES_ROMAN_24,text); 00222 IntToString ( 0, text ); 00223 glRasterPos2i(140,1); 00224 printstring(GLUT_BITMAP_TIMES_ROMAN_24,text); 00225 00226 IntToString ( (int) campos[X], text ); 00227 glRasterPos2i(200,1); 00228 printstring(GLUT_BITMAP_TIMES_ROMAN_24,text); 00229 IntToString ( (int) campos[Y], text ); 00230 glRasterPos2i(255,1); 00231 printstring(GLUT_BITMAP_TIMES_ROMAN_24,text); 00232 IntToString ( (int) campos[Z], text ); 00233 glRasterPos2i(310,1); 00234 printstring(GLUT_BITMAP_TIMES_ROMAN_24,text); 00235 00236 IntToString ( colObject , text ); 00237 glRasterPos2i(420,1); 00238 printstring(GLUT_BITMAP_TIMES_ROMAN_24,text); 00239 00240 IntToString ( myObjectID , text ); 00241 glRasterPos2i(490,1); 00242 printstring(GLUT_BITMAP_TIMES_ROMAN_24,text); 00243 00244 IntToString ( (int)(speednr*10) , text ); 00245 glRasterPos2i(560,1); 00246 printstring(GLUT_BITMAP_TIMES_ROMAN_24,text); 00247 00248 IntToString ( frametime, text ); 00249 glRasterPos2i(WINDOWX-40,WINDOWY-40); 00250 printstring(GLUT_BITMAP_TIMES_ROMAN_24,text); 00251 } 00252 00253