#include #include #include #include #include #include "image3d.cpp" #include #include #define ELEMENTS 11 float rx=-.6, ry=0.53, rz=-M_PI/4, theta=0.241660973, stepvalue = 0.037850513, multradstar = 3.0, multradball = 2.0, ballsize=0.25, zzspi, rotated_star_coords_x, rotated_star_coords_y, phase, ballsizereset, offset = 0.0, lengthstar, lengthsphere, lengthvortex; GLfloat star_coords[2][ELEMENTS]= { {0.0, 0.0, -0.07,-0.18505,-0.1375,-0.1805,-0.07, 0.0, 0.035, 0.1375, 0.035} , {0.0, 0.18, 0.09, 0.105, 0.0, -0.105, -0.09, -0.18, -0.0575, 0.0, 0.0575} }; GLfloat colors[6][3] = { {0.3, 0.15, 0.68}, {0.7, 0.19, 0.1}, {0.1, 0.55, 0.83}, {0.6, 0.65, 0.75}, {0.7, 0.69, 0.3}, {0.1, 0.55, 0.83} }; int indicator=0, color1 = 0, color2 = 1, color3 = 2, color4 = 3, color_diddle = color1^color2, color_diddle2 = color3^color4, front; float coordx( float radius ) { return ( cos(radius * 10.0) * radius ); } float coordy( float radius ) { return ( sin(radius * 10.0) * radius ); } void matricize_vortex( void ) { matrix( rx, ry, rz, 0); } void matricize_star( void ) { matrix( rx, ry, (6.5*rz), 1); } void matricize_sphere( void) { matrix( rx, ry, (-3.5*rz), 2); } /*creat z component and setup the trasform for the plane */ void findzee_vortex(float xa, float ya) { GLfloat za, store; lengthvortex = (lengthvortex - xa*ya*za); store = 0.3575/(xa*xa+ya*ya); za = -store + 0.35 * sin( 3.0* sqrt(store ) + phase ) ; coordinate( xa, ya, za, 0.750, -0.45, -3.5, 0); } void findzee_star( float xa, float ya) { float za, store; store = 0.3575/(xa*xa+ya*ya); if( indicator != 1) { za = -store + 0.35 * sin(3.0* sqrt( store ) + phase ) ; if( za < -120.0 ) { zzspi = za; indicator = 1; } lengthstar = ( lengthstar - xa*ya*za ); coordinate( xa, ya, za, 0.75, -0.45, -3.5, 1); return; } if( indicator == 1) { coordinate( 0.0, 0.0, zzspi, 0.75, -0.45, -3.5, 1); return; } } void findzee_sphere(float xa, float ya) { float nn, storeheight, height, za, storenew, drv, ind; nn = 0.3575 /(xa*xa + ya*ya); drv =(xa+ya) * ( (0.715/(nn*nn))-1.05*cos(3.0*sqrt(nn)+phase)/sqrt(nn) ); storenew = atan(drv); ind = fabs( sin( storenew ) ); storeheight= 2.0 - ind; if( indicator != 2 ) { za = - nn + 0.3575 * sin( 3.0 * sqrt(nn) + phase ) + ballsize*storeheight; if( za < -120.0 ) { zzspi = za; indicator = 2; } lengthsphere = ( lengthsphere - xa*ya*za ); ballsizereset = ballsize * ratio; coordinate( xa, ya, za, 0.75, -0.45, -3.5, 2 ); return; } if( indicator == 2 ) { coordinate( 0.0, 0.0, zzspi, 0.750, -0.45, -3.5, 2); return; } } void rotate_star( int n) { rotated_star_coords_x = cos(-rz)*star_coords[0][n] - sin(-rz)*star_coords[1][n]; rotated_star_coords_y = sin(-rz)*star_coords[0][n] + cos(-rz)*star_coords[1][n]; } /*The rotation technique that is used to create the cross hatch pattern on the ball that is used from polar co-ordinates.*/ void ballset(float rxb, float ryb) { matrix( ryb, rxb, 0.0 , 4); real_coordinate( 0.0, 0.0, -ballsizereset, 4); } void rz_spiral_idle( void ) { /* the star's trajectory and plotting */ offset += stepvalue; phase += 0.0015707963; rz += 0.031415926; multradstar -= 0.00125; multradball -= 0.00325; if( offset >= (2.0*theta) ) offset = 0.0; if( rz > ( 4.0e9 * M_PI ) ) rz = 0.0; if( phase > ( 2.0 * M_PI ) ) lengthstar = lengthsphere = lengthvortex = phase = 0.0; if( indicator != 0) { if( (zzspi < -120.0) ) { zzspi += 9.5125; } else if( (zzspi < -96.5 ) && ( zzspi > -125.5) ) { zzspi += 6.3175; } else if( (zzspi < -22.5 ) && ( zzspi > -96.5) ) { zzspi += 1.72575; ballsize += 0.00715; } else if( (zzspi < -1.0 ) && ( zzspi > -22.5 ) ) { ballsize += 0.05725; zzspi += 1.5125; } else if( zzspi > -1.0 ) { ballsize += 0.1255 ; zzspi += 0.8125; } if( ballsize > 8.25 ) { indicator = 0; /* create the size of the new rotating ball and spiralling sequence's multiply ratio*/ if( multradstar < 0.00125) multradstar = ( float ) ( ( random( 300) ) / 100.0 ) + 0.75; if( multradball < 0.00124) multradball = ( float ) ( ( random( 400) ) / 100.0 ) + 0.75; ballsize = (float)( ( random( 200 ) /600.0 )) + 0.15; } } glutPostRedisplay ( ); } void draw_vortex( void ) { float xx, yy; matricize_vortex ( ); for(xx=-1.0875; xx<1.0875; xx+=0.075) { color1 ^= color_diddle; for(yy=-1.0875; yy<1.0875; yy+=0.075) { glColor3f( colors[color1][0], colors[color1][1], colors[color1][2] ); glBegin( GL_POLYGON ); findzee_vortex(xx, yy); glVertex2f( xp, yp ); findzee_vortex(xx, yy+0.05 ); glVertex2f( xp, yp ); findzee_vortex(xx+0.05, yy+0.05 ); glVertex2f( xp, yp ); findzee_vortex(xx+0.05, yy ); glVertex2f( xp, yp ); glEnd(); color1 ^= color_diddle; } } } void draw_star( void ) { int n; float xstar, ystar; matricize_star ( ); glColor3f( colors[4][0], colors[4][1], colors[4][2] ); glBegin( GL_TRIANGLE_FAN ); for(n=0; n < ELEMENTS; n++) { xstar = coordx( multradstar ) + rotated_star_coords_x; ystar = coordy( multradstar ) + rotated_star_coords_y; rotate_star( n ); findzee_star(xstar, ystar); glVertex2f( xp, yp ); } glEnd(); } void draw_sphere( float ryb) { int n; float cy1, cy2, cx1, cx2, drv, rxb; GLfloat randcolorr, randcolorg, randcolorb; matricize_sphere( ); cy1 = ryb; cy2 = ryb + theta; randomize(); for( rxb=-M_PI/2.0; rxb lengthsphere ) draw_star(); else draw_sphere_rotation(); draw_vortex(); glPopMatrix ( ); glutSwapBuffers ( ); } void reshape(int w, int h) /* Allow user to resize the window on the fly */ { glViewport ( 0, 0, (GLint) w, (GLint) h ); glMatrixMode ( GL_PROJECTION ); glLoadIdentity ( ); if ( w <= h ) glOrtho ( -1.0* w / h, 1.0 * w / h, -1.0, 1.0, 1.0, -1.0 ); else glOrtho ( -1.0, 1.0, -1.0 * h / w, 1.0 * h / w, 1.0, -1.0 ); glMatrixMode ( GL_MODELVIEW ); glLoadIdentity ( ); } #pragma argsused void keyboard ( unsigned char key, int x, int y ) { switch ( key ) { case 27: /* Escape key */ exit ( 0 ); break; case 'f': glutFullScreen ( ); break; case 'w': glutReshapeWindow ( 250,250 ); break; default: break; } } /* Main Loop * Open window with initial window size, title bar, * RGBA display mode, and handle input events. */ int main ( int argc, char** argv ) { glutInit ( &argc, argv ); glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE ); glutInitWindowSize ( 750, 750 ); glutCreateWindow ( argv[0] ); glutReshapeFunc ( reshape ); glutKeyboardFunc ( keyboard ); glutDisplayFunc ( display ); glutIdleFunc (rz_spiral_idle ); init ( ); glutMainLoop ( ); return 0; }