www.pudn.com > gear.rar > gear.cpp


#include  
#include  
#include  
 
#if defined(Q_CC_MSVC) 
#pragma warning(disable:4305) // init: truncation from const double to float 
#endif 
 
static void gear( GLfloat inner_radius, GLfloat outer_radius, GLfloat width, 
		  GLint teeth, GLfloat tooth_depth ) 
{ 
    GLint i; 
    GLfloat r0, r1, r2; 
    GLfloat angle, da; 
    GLfloat u, v, len; 
 
    r0 = inner_radius; 
    r1 = outer_radius - tooth_depth/2.0; 
    r2 = outer_radius + tooth_depth/2.0; 
 
    const double pi = 3.14159264; 
    da = 2.0*pi / teeth / 4.0; 
 
    glShadeModel( GL_FLAT ); 
 
    glNormal3f( 0.0, 0.0, 1.0 ); 
 
    /* draw front face */ 
    glBegin( GL_QUAD_STRIP ); 
    for (i=0;i<=teeth;i++) { 
	angle = i * 2.0*pi / teeth; 
	glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 ); 
	glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 ); 
	glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 ); 
	glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 ); 
    } 
    glEnd(); 
 
    /* draw front sides of teeth */ 
    glBegin( GL_QUADS ); 
    da = 2.0*pi / teeth / 4.0; 
    for (i=0;i= 2 ) { 
	bool ok = TRUE; 
	timer_interval = QString::fromLatin1( argv[1] ).toInt( &ok ); 
	if ( !ok ) 
	    timer_interval = 10; 
    } 
 
    GearWidget w; 
    a.setMainWidget( &w ); 
    w.show(); 
    return a.exec(); 
}