#
# A teeth wheel:
#						Gershon Elber, Apr 89
#

time(true);

save_res = resolution;

# Number of samples per circle:
resolution = 8;

# Note angle must be power of 2 as we multiply it by 2 each iteration, and
# angle_log should hold the base 2 log of the divider in angle: log2 16 = 4.
angle = 360/16;
angle_log = 4; 

C = cylin( vector( 0.6, 0.0, -0.1 ), vector( 0.0, 0.0, 0.3 ), 0.1, 0 );
view( list( C, axes ), true );

for ( i = 1, 1, angle_log,
	C = C + C * rotz( angle ):
	angle = angle * 2:
	view( list( C, axes ), true )
);
free( i );
free( angle );
free( angle_log );

#
# Now lets create the wheel, make a hole in it to make it looks more real,
# and subtract all the teeth from it:
#

resolution = 32;
wheel = cylin( vector( 0.0, 0.0, 0.0 ), vector( 0.0, 0.0, 0.08 ), 0.6, 3 );
beep();

resolution = 16;
H1 = cylin( vector( 0.0, 0.0, -0.1 ), vector( 0.0, 0.0, 0.3 ), 0.1, 3 );
H2 = box( vector( -0.2, -0.05, -0.1 ), 0.4, 0.1, 0.3 );
H = H1 + H2;
free( H1 );
free( H2 );

beep();
view( list( wheel, H ), true );
wheel = wheel - H;
free(H);

wheel = convex( wheel );
beep();
interact( wheel );

wheel = wheel - C;
free( C );
beep();
interact( wheel );

final = convex( wheel );
free( wheel );

time( false ); # In Seconds

final = uvpoly( final, list( 2, 2, .1 ) );
attrib( final, "ptexture", "dummy.gif" );

beep();
interact( final );

save( "wheel", final );
free( final);

resolution = save_res;
