/* Copyright (c) Mark J. Kilgard,1994. */ /** * (c) Copyright 1993,1994,Silicon Graphics,Inc. * ALL RIGHTS RESERVED * Permission to use,copy,modify,and distribute this software for * any purpose and without fee is hereby granted,provided that the above * copyright notice appear in all copies and that both the copyright notice * and this permission notice appear in supporting documentation,and that * the name of Silicon Graphics,Inc. not be used in advertising * or publicity pertaining to distribution of the software without specific, * written prior permission. * * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" * AND WITHOUT WARRANTY OF ANY KIND,EXPRESS,IMPLIED OR OTHERWISE, * INCLUDING WITHOUT LIMITATION,ANY WARRANTY OF MERCHANTABILITY OR * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON * GRAPHICS,INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, * SPECIAL,INCIDENTAL,INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY * KIND,OR ANY DAMAGES WHATSOEVER,INCLUDING WITHOUT LIMITATION, * LOSS OF PROFIT,LOSS OF USE,SAVINGS OR REVENUE,OR THE CLAIMS OF * THIRD PARTIES,WHETHER OR NOT SILICON GRAPHICS,INC. HAS BEEN * ADVISED OF THE POSSIBILITY OF SUCH LOSS,HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY,ARISING OUT OF OR IN CONNECTION WITH THE * POSSESSION,USE OR PERFORMANCE OF THIS SOFTWARE. * * US Government Users Restricted Rights * Use,duplication,or disclosure by the Government is subject to * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph * (c)(1)(ii) of the Rights in Technical Data and Computer Software * clause at DFARS 252.227-7013 and/or in similar or successor * clauses in the FAR or the DOD or NASA FAR Supplement. * Unpublished-- rights reserved under the copyright laws of the * United States. Contractor/manufacturer is Silicon Graphics, * Inc.,2011 N. Shoreline Blvd.,Mountain View,CA 94039-7311. * * OpenGL(TM) is a trademark of Silicon Graphics,Inc. */ #include #include #include #include #include #include #include #include #include "ModuleCouleurs.h" #include "ModuleManipulateur.h" #include "ModuleMenus.h" #include "ModuleReshape.h" #ifndef RAND_MAX # define RAND_MAX 32767 #endif #define XSIZE 100 #define YSIZE 75 #define RINGS 5 #define BLUERING 0 #define BLACKRING 1 #define REDRING 2 #define YELLOWRING 3 #define GREENRING 4 #define BACKGROUND 8 enum { BLACK = 0, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE }; unsigned char rgb_colors[RINGS][3]; int mapped_colors[RINGS]; float dests[RINGS][3]; float offsets[RINGS][3]; float angs[RINGS]; float rotAxis[RINGS][3]; int iters[RINGS]; GLuint theTorus; void FillTorus(float rc,int numc,float rt,int numt) { int i,j,k; double s,t; double x,y,z; double pi,twopi; pi = 3.14159265358979323846; twopi= 2 * pi; for (i = 0; i < numc; i++) { glBegin(GL_QUAD_STRIP); for (j = 0; j <= numt; j++) { for (k = 1; k >= 0; k--) { s = (i + k) % numc + 0.5; t = j % numt; x = cos(t*twopi/numt) * cos(s*twopi/numc); y = sin(t*twopi/numt) * cos(s*twopi/numc); z = sin(s*twopi/numc); glNormal3f((float) x,(float) y,(float) z); x = (rt + rc * cos(s*twopi/numc)) * cos(t*twopi/numt); y = (rt + rc * cos(s*twopi/numc)) * sin(t*twopi/numt); z = rc * sin(s*twopi/numc); glVertex3f((float) x,(float) y,(float) z); } } glEnd(); } } float Clamp(int iters_left,float t) { if (iters_left < 3) return 0.0; return (iters_left-2)*t/iters_left; } void display(void) { int i,j; GLboolean goIdle; goIdle = GL_TRUE; for ( i = 0 ; i < RINGS ; i++ ) { if ( iters[i] ) { for ( j = 0 ; j < 3 ; j++ ) offsets[i][j] = Clamp(iters[i],offsets[i][j]); angs[i] = Clamp(iters[i],angs[i]); iters[i]--; goIdle = GL_FALSE; } } if (goIdle) glutIdleFunc(NULL); glPushMatrix(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); gluLookAt(0,0,10,0,0,0,0,1,0); manipulateurSouris(); manipulateurClavier(); for ( i = 0 ; i < RINGS ; i++ ) { glColor3ubv(rgb_colors[i]); glPushMatrix(); glTranslatef(dests[i][0]+offsets[i][0],dests[i][1]+offsets[i][1],dests[i][2]+offsets[i][2]); glRotatef(angs[i],rotAxis[i][0],rotAxis[i][1],rotAxis[i][2]); glCallList(theTorus); glPopMatrix(); } glPopMatrix(); glFlush(); glutSwapBuffers(); } float MyRand(void) { return 10.0F * ( (float) rand() / (float) RAND_MAX - 0.5F ); } void ReInit(void) { int i; float deviation; deviation = MyRand() / 2; deviation = deviation * deviation; for (i = 0; i < RINGS; i++) { offsets[i][0] = MyRand(); offsets[i][1] = MyRand(); offsets[i][2] = MyRand(); angs[i] = 260.0F * MyRand(); rotAxis[i][0] = MyRand(); rotAxis[i][1] = MyRand(); rotAxis[i][2] = MyRand(); iters[i] =(int) ( deviation * MyRand() + 60.0F); } glutIdleFunc(display); } void myinit(void) { float base,height; float aspect,x,y; int i; float sc = 10; float top_y = 1.0F; float bottom_y = 0.0F; float top_z = 0.15F; float bottom_z = 0.69F; float spacing = 2.5F; static float lmodel_twoside[] = {GL_FALSE}; static float lmodel_local[] = {GL_FALSE}; static float light0_position[] = {0.8660254F,0.5F,1.0F,0.0F}; static float bevel_mat_ambient[] = {0.0F,0.0F,0.0F,1.0F}; static float bevel_mat_shininess[] = {40.0F}; static float bevel_mat_specular[] = {1.0F,1.0F,1.0F,0.0F}; static float bevel_mat_diffuse[] = {1.0F,0.0F,0.0F,0.0F}; ReInit(); for (i = 0; i < RINGS; i++) rgb_colors[i][0] = rgb_colors[i][1] = rgb_colors[i][2] = 0; rgb_colors[BLUERING][2] = 255; rgb_colors[REDRING][0] = 255; rgb_colors[GREENRING][1] = 255; rgb_colors[YELLOWRING][0] = 255; rgb_colors[YELLOWRING][1] = 255; mapped_colors[BLUERING] = BLUE; mapped_colors[REDRING] = RED; mapped_colors[GREENRING] = GREEN; mapped_colors[YELLOWRING] = YELLOW; mapped_colors[BLACKRING] = BLACK; dests[BLUERING][0] = -spacing; dests[BLUERING][1] = top_y; dests[BLUERING][2] = top_z; dests[BLACKRING][0] = 0.0; dests[BLACKRING][1] = top_y; dests[BLACKRING][2] = top_z; dests[REDRING][0] = spacing; dests[REDRING][1] = top_y; dests[REDRING][2] = top_z; dests[YELLOWRING][0] = -spacing / 2.0F; dests[YELLOWRING][1] = bottom_y; dests[YELLOWRING][2] = bottom_z; dests[GREENRING][0] = spacing / 2.0F; dests[GREENRING][1] = bottom_y; dests[GREENRING][2] = bottom_z; base = 2.0; height = 2.0; theTorus = glGenLists(1); glNewList(theTorus,GL_COMPILE); FillTorus(0.1F,8,1.0F,25); glEndList(); x = (float)XSIZE; y = (float)YSIZE; aspect = x / y; glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); glClearDepth(1.0F); glClearColor(0.5F,0.5F,0.5F,0.0F); glLightfv(GL_LIGHT0,GL_AMBIENT,couleurGrisTresFonce()); glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBlanc()); glLightfv(GL_LIGHT0,GL_SPECULAR,couleurBlanc()); glLightfv(GL_LIGHT0,GL_POSITION,light0_position); glEnable(GL_LIGHT0); glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER,lmodel_local); glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE,lmodel_twoside); glLightModelfv(GL_LIGHT_MODEL_AMBIENT,couleurNoir()); glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT,GL_AMBIENT,bevel_mat_ambient); glMaterialfv(GL_FRONT,GL_SHININESS,bevel_mat_shininess); glMaterialfv(GL_FRONT,GL_SPECULAR,bevel_mat_specular); glMaterialfv(GL_FRONT,GL_DIFFUSE,bevel_mat_diffuse); glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glShadeModel(GL_SMOOTH); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); } int main(int argc,char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); glutInitWindowSize(400,300); glutInitWindowPosition(50,50); glutCreateWindow("Les anneaux olympiques"); myinit(); creationMenuBasique(); setParametresPerspectiveBasique(45.0F,1.333F,0.1F,100.0F,0.0F,0.0F,0.0F); setManipulateurDistance(9.5F); glutReshapeFunc(reshapePerspectiveBasique); glutKeyboardFunc(keyBasique); glutSpecialFunc(specialBasique); glutMotionFunc(motionBasique); glutMouseFunc(sourisBasique); glutDisplayFunc(display); glutMainLoop(); return(0); }