#include #include #include #include #include #ifndef M_PI #define M_PI 3.141592 #endif // M_PI #define sphere 1 #define cylinder 2 int na = 32; int nb = 16; std::queue < float* > pts; std::queue < float* > lines; std::queue < float* > triangles; bool running() { return( !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam( GLFW_OPENED) ); } void init() { int width, height; glfwInit(); if( !glfwOpenWindow( 640, 480, 0, 0, 0, 0, 8, 0, GLFW_WINDOW ) ) return; glfwGetWindowSize( &width, &height ); height = height > 0 ? height : 1; glViewport( 0, 0, width, height ); glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 65.0f, (GLfloat)width/(GLfloat)height, 1.0f, 100.0f ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt(0.0f, -10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ); } void finit() { glfwTerminate(); } void drawOxyz() { // Рисуване на лъчите glBegin( GL_LINES ); // OX glVertex3f( 0.0, 0.0, 0.0 ); glVertex3f( 5.0, 0.0, 0.0 ); // OY glVertex3f( 0.0, 5.0, 0.0 ); glVertex3f( 0.0, 0.0, 0.0 ); // OZ glVertex3f( 0.0, 0.0, 5.0 ); glVertex3f( 0.0, 0.0, 0.0 ); glEnd(); // Рисуване на стрелките glBegin( GL_TRIANGLES ); // OX glVertex3f( 5.0, 0.0, 0.0 ); glVertex3f( 4.5, 0.2, 0.0 ); glVertex3f( 4.5,-0.2, 0.0 ); // OY glVertex3f( 0.0, 5.0, 0.0 ); glVertex3f( 0.2, 4.5, 0.0 ); glVertex3f(-0.2, 4.5, 0.0 ); // OZ glVertex3f( 0.0, 0.0, 5.0 ); glVertex3f(+0.14,-0.14, 4.5 ); glVertex3f(-0.14,+0.14, 4.5 ); glEnd(); } struct OKG_POINT { float x; float y; float z; } ; OKG_POINT point( float x, float y, float z) { OKG_POINT p; p.x = x; p.y = y; p.z = z; return( p ); } void drawSolidCylinder ( float x, float y, float z, float r, float h ) { float alpha = 0.0; float dalpha = 2*M_PI/na; for( int i=0; i temp = pts; float tmp[3]; float* t = tmp; glColor3ub(0,0,255); while(!temp.empty()){ t = temp.front(); __drawPoint(t[0],t[1],t[2]); temp.pop(); } } void __drawAllLines(){ std::queue < float* > temp = lines; float tmp[6]; float* t = tmp; glColor3ub(255,255,0); while(!temp.empty()){ t = temp.front(); __drawLine(t[0],t[1],t[2],t[3],t[4],t[5]); temp.pop(); } } void __drawAllTriangles(){ std::queue < float* > temp = triangles; float tmp[9]; float* t = tmp; glColor4f(1.0f,0.6f,0.6f,0.8f); while(!temp.empty()){ t = temp.front(); __drawTriangle(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8]); temp.pop(); } glColor4f(1.0f,0.0f,0.0f,1.0f); } void run(){ init(); glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glEnable( GL_COLOR_MATERIAL ); glEnable(GL_BLEND); //Enable blending. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //Set blending function. glEnable(GL_SMOOTH); glShadeModel(GL_SMOOTH); float t = 0; prepareUnits(); while( running() ) { glClear( GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT ); t=t+0.001; glLoadIdentity(); gluLookAt(10*cos(t),10*sin(t),15, 0,0,0, 0,0,1 ); glColor3ub(0,0,0); drawOxyz(); glEnable( GL_LIGHTING ); __drawAllPoints(); __drawAllLines(); __drawAllTriangles(); glColor4f(0.85f,0.85f,1.0f,0.8f); glPushMatrix(); glScalef(100,100,0); glBegin(GL_POLYGON); glVertex3f(-1,-1,0); glVertex3f(1,-1,0); glVertex3f(1,1,0); glVertex3f(-1,1,0); glEnd(); glPopMatrix(); glDisable( GL_LIGHTING ); glfwSwapBuffers(); } finit(); }