#include // For math routines (such as sqrt & trig). #include #include // OpenGL Graphics Utility Library #include "GluCylinders.h" void ani(float , float , float ); void renderCylinder(float x1, float y1, float z1, float x2,float y2, float z2, float radius,int subdivisions,GLUquadricObj *quadric); void renderCylinder_convenient(float x1, float y1, float z1, float x2,float y2, float z2, float radius,int subdivisions); // The next global variable controls the animation's state and speed. float RotateAngle = 0.0f; // Angle in degrees of rotation around y-axis float Azimuth = 0.0; // Rotated up or down by this amount float AngleStepSize = 3.0f; // Step three degrees at a time const float AngleStepMax = 10.0f; const float AngleStepMin = 0.1f; int WireFrameOn = 1; // == 1 for wire frame mode //points float Geometry[9][3] = { { 4,2.0,0}, { 4,2.0,0}, // Point1 {-1.5,0.2,0}, {-2,0.3,0}, {-2.5,0.6,0}, {-3,0.8,0}, {-3.5,1.0,0}, { -5.5,1.8,0},//point 2 { -5.5,1.8,0} }; int x2[5],y2[5],z2[5]; unsigned int LOD=20; // glutKeyboardFunc is called below to set this function to handle // all "normal" key presses. void myKeyboardFunc( unsigned char key, int x, int y ) { switch ( key ) { case 'w': WireFrameOn = 1-WireFrameOn; if ( WireFrameOn ) { glPolygonMode ( GL_FRONT_AND_BACK, GL_LINE ); // Just show wireframes } else { glPolygonMode ( GL_FRONT_AND_BACK, GL_FILL ); // Show solid polygons } glutPostRedisplay(); break; case 'R': AngleStepSize *= 1.5; if (AngleStepSize>AngleStepMax ) { AngleStepSize = AngleStepMax; } break; case 'r': AngleStepSize /= 1.5; if (AngleStepSize80.0f ) { Azimuth = 80.0f; } break; case GLUT_KEY_DOWN: Azimuth -= AngleStepSize; if ( Azimuth < -80.0f ) { Azimuth = -80.0f; } break; case GLUT_KEY_LEFT: RotateAngle += AngleStepSize; if ( RotateAngle > 180.0f ) { RotateAngle -= 360.0f; } break; case GLUT_KEY_RIGHT: RotateAngle -= AngleStepSize; if ( RotateAngle < -180.0f ) { RotateAngle += 360.0f; } break; } glutPostRedisplay(); } /* * drawScene() handles the animation and the redrawing of the * graphics window contents. */ void drawScene(void) {int i,j,k=0,m=0; float b0,b1,b2,b3,t,x3,y3,z3,n1,n2,n3; //Clear the rendering window //for( i=0;i<5;i++) //{ //x2[i]=0.5*(G[i+1][0]-G[i-1][0]); //y2[i]=0.5*(G[i+1][1]-G[i-1][1]); //z2[i]=0.5*(G[i+1][2]-G[i-1][2]); //} // Clear the rendering window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Rotate the image glMatrixMode( GL_MODELVIEW ); // Current matrix affects objects positions glLoadIdentity(); // Initialize to the identity glTranslatef( -0.5, 0.0, -35.0 ); // Translate from origin (in front of viewer) glRotatef( RotateAngle, 0.0, 1.0, 0.0 ); // Rotate around y-axis glRotatef( Azimuth, 1.0, 0.0, 0.0 ); // Set Azimuth angle //------------------------------------------------------------ glDisable( GL_CULL_FACE ); glPushMatrix(); glTranslatef( -4.5, 0.5, 0.0 ); glRotatef( -90.0, 1.0, 0.0, 0.0 ); glColor3f( 1.0, 0.2, 0.2 ); // Reddish color x<=4.5 0.5=