begin process at 2010 03 22 11:33:00
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

OpenGL

 > MONDE OPENGL

MONDE OPENGL


 Information sur la source

Note :
10 / 10 - par 1 personne
10,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :OpenGL Classé sous :opengl, planete, monde, gravité Niveau :Débutant Date de création :03/08/2004 Date de mise à jour :26/12/2005 10:48:08 Vu :6 707

Auteur : MiTcH37

Ecrire un message privé
Site perso
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
Génération d'un système solaire en opengl 3D
avec glut et glui, gère le son et les textures, etc...
La gravité...quelle force ! et pourtant,  ce n'est que la plus faible !!!!!!

Source

  • /********************************************************************************
  • * *
  • * MoNdE *
  • * *
  • * MoNdE is a planets generator, with a the gravity force. *
  • * *
  • * Copyright (C) 2004-2005 Julien MICHOT *
  • * *
  • * Contact : m.i.t.c.h@free.fr - http://www.webfractales.com *
  • * *
  • * This program is free software; you can redistribute it and/or *
  • * modify it under the terms of the GNU General Public License *
  • * as published by the Free Software Foundation; either version 2 *
  • * of the License, or (at your option) any later version. *
  • * *
  • * This program is distributed in the hope that it will be useful, *
  • * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  • * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  • * GNU General Public License for more details. *
  • * *
  • * You should have received a copy of the GNU General Public License *
  • * along with this program; if not, write to the Free Software *
  • * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  • * *
  • * *
  • * You can have the GLUT library here : *
  • * http://www.opengl.org/resources/libraries/glut.html *
  • * *
  • * You can have the GLUI library here : *
  • * http://www.cs.unc.edu/~rademach/glui/ *
  • * *
  • ********************************************************************************/
  • // Headers utilisés *********************************************************
  • #include <string.h>
  • #include <windows.h> //pour le son...
  • #include "glut.h"
  • #include "tube.h"
  • #include "glui.h"
  • #include "math.h"
  • #include "time.h"
  • //***************************************************************************
  • #define MAX(a,b) (((a)>(b))?(a):(b))
  • #define PI 3.1415926535897932384626433832
  • #define MAXPLANETE 100
  • #define TAILLEESPACE 3.0
  • #define DENSITE 0.0001
  • float CERCLEMAX=6.0;
  • float Vitesse=1.3;
  • double G=6.67*pow((double)10,(double)-11)*100.0;//*0.000000001//-11
  • int nbplanete= 70;
  • int Destruction=1;
  • int SonActif=0;
  • float xy_aspect;
  • int last_x, last_y;
  • float rotationX = 0.0, rotationY = 0.0;
  • int sens=1,arret=1;
  • float RapportVts=2.0,tmpvts=0.0018;
  • bool Pause=0;
  • bool SuivreTerre=0;
  • // Variables passées à GLUI *************************************************
  • int main_window;
  • float scale = 0.3;
  • int ColonneInit= 4;
  • int obj_type = 2;
  • float obj_pos[] = { 0.0, 0.0, 0.0 };
  • float view_rotate[16] = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
  • //***************************************************************************
  • int lar=256;
  • unsigned char t[256*256*3];
  • unsigned char t2[256*256*3];
  • int numTexture=1;
  • // Pointeurs se rapportant a GLUI *******************************************
  • GLUI *glui, *glui2, *glui3;
  • GLUI_Spinner *NbLigne, *NbColonne, *destruction,*NbVitesse;
  • GLUI_Button *test;
  • GLUI_RadioGroup *radio;
  • //***************************************************************************
  • // Id utilisés pour les callback ********************************************
  • #define LANCER_ID 2
  • #define PAUSE_ID 3
  • #define NOUVEAU_ID 4
  • //***************************************************************************
  • // Divers variables globales ************************************************
  • /*
  • GLfloat light0_ambient[] = {0.6f, 0.1f, 0.3f, 1.0f};
  • GLfloat light0_diffuse[] = {.9f, .6f, 0.0f, 1.0f};
  • GLfloat light0_position[] = {0.0f, .0f, 0.0f, 1.0f};
  • */
  • GLfloat light0_ambient[] = {0.9f, 0.9f, 0.9f, 1.0f};
  • GLfloat light0_diffuse[] = {.9f, .9f, 0.9f, 1.0f};
  • GLfloat light0_position[] = {0.0f, .0f, 0.0f, 1.0f};
  • GLfloat light1_ambient[] = {0.9f, 0.9f, 0.9f, 1.0f};
  • GLfloat light1_diffuse[] = {.9f, .9f, 0.9f, 1.0f};
  • GLfloat light1_position[] = {1.0f, 1.0f, 0.0f, 1.0f};
  • GLfloat lights_rotation[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
  • //***************************************************************************
  • bool matrice[5][5][5];
  • void Luz(int num);
  • void addPlanete(void);
  • class planet
  • {
  • public:
  • int num;
  • float angle1,dangle1;
  • float size;
  • float rayon1,rayon2;
  • float X,Y,Z;
  • float tmpX,tmpY,tmpZ;
  • float depX_av,depY_av,depZ_av;
  • int numParent;
  • double masse;
  • float vtsinit;
  • bool detruit;
  • bool anneaux;
  • float AxeRotX,AxeRotY,AxeRotZ;//rotation
  • float angle_dep,AxeRotX_dep,AxeRotY_dep,AxeRotZ_dep;//rotation de départ
  • // pour les textures
  • bool ActiverTexture;
  • int Texture;
  • unsigned char t[256*256*3];
  • GLfloat l_ambient[4];
  • GLfloat l_diffuse[4];
  • GLfloat l_position[4];
  • planet();
  • ~planet();
  • void init(void);
  • void dessiner(void);
  • void refresh(void);
  • void deplacer(void);
  • void setposis(float x, float y, float z);
  • void setvts(float x, float y, float z);
  • void tueepar(int i);
  • void setmasse(float m);
  • void setLA(float a, float b, float c, float d);
  • void setLD(float a, float b, float c, float d);
  • void setLP(float a, float b, float c, float d);
  • void setRot(float da, float x, float y, float z);
  • void setRotDepart(float a, float x, float y, float z);
  • void setTexture(void);
  • }planete[MAXPLANETE];
  • planet::planet()
  • {
  • init();
  • }
  • planet::~planet()
  • {
  • }
  • void planet::init(void)
  • {
  • X=(float)(rand()%((int)TAILLEESPACE*20)-(TAILLEESPACE*10))/10.0;
  • Y=(float)(rand()%((int)TAILLEESPACE*20)-(TAILLEESPACE*10))/10.0;
  • Z=(float)(rand()%((int)TAILLEESPACE*20)-(TAILLEESPACE*10))/10.0;
  • depX_av=(rand()%20-10)/1000.0;
  • depY_av=(rand()%20-10)/1000.0;
  • depZ_av=(rand()%20-10)/1000.0;
  • angle1=0;
  • size=0.1;
  • numParent=0;
  • dangle1=(rand()%40-40.0)/100.0;
  • rayon1=1;
  • rayon2=rayon1;
  • masse = rand()%1000;
  • size=DENSITE*masse;//20.0/masse;
  • vtsinit=1;
  • setLA(0.9f, 0.9f, 0.9f, 1.0f);
  • setLD(.9f, .8f, 0.0f, 1.0f);
  • // setLA((rand()%100)/100.0, (rand()%100)/100.0,(rand()%100)/100.0, 1.0f);
  • // setLD((rand()%100)/100.0, (rand()%100)/100.0,(rand()%100)/100.0, 1.0f);
  • setLP(0.0f, .0f, 0.0f, 1.0f);
  • if(masse>500) anneaux=(!(rand()%5));
  • else anneaux=0;
  • Texture=0;
  • ActiverTexture=0;
  • AxeRotX=(rand()%10)/10.0;
  • AxeRotY=(rand()%10)/10.0;
  • AxeRotZ=(rand()%10)/10.0;
  • angle_dep=rand()%360;
  • AxeRotX_dep=(rand()%10)/10.0;
  • AxeRotY_dep=(rand()%10)/10.0;
  • AxeRotZ_dep=(rand()%10)/10.0;
  • detruit=0;
  • }
  • void planet::setLA(float a, float b, float c, float d)
  • {
  • l_ambient[0]=a;
  • l_ambient[1]=b;
  • l_ambient[2]=c;
  • l_ambient[3]=d;
  • }
  • void planet::setLD(float a, float b, float c, float d)
  • {
  • l_diffuse[0]=a;
  • l_diffuse[1]=b;
  • l_diffuse[2]=c;
  • l_diffuse[3]=d;
  • }
  • void planet::setLP(float a, float b, float c, float d)
  • {
  • l_position[0]=a;
  • l_position[1]=b;
  • l_position[2]=c;
  • l_position[3]=d;
  • for(int i=0;i<4;i++)
  • {
  • light0_ambient[i]=l_ambient[i];
  • light0_diffuse[i]=l_diffuse[i];
  • light0_position[i]=l_position[i];
  • }
  • }
  • void planet::setmasse(float m)
  • {
  • masse=m;
  • size=DENSITE*masse;
  • }
  • void planet::dessiner(void)
  • {
  • float tx,ty,tz;
  • if(!detruit)
  • {
  • tx=X;
  • ty=Y;
  • tz=Z;
  • if(sqrt(pow(X,2)+pow(Y,2)+pow(Z,2))<CERCLEMAX||CERCLEMAX==0)
  • {
  • X+=((tmpX-X)/masse*(Vitesse)+depX_av)*(Vitesse);
  • Y+=((tmpY-Y)/masse*(Vitesse)+depY_av)*(Vitesse);
  • Z+=((tmpZ-Z)/masse*(Vitesse)+depZ_av)*(Vitesse);
  • }else{
  • X-=((tmpX-X)/masse*(Vitesse)+depX_av)*(Vitesse);
  • Y-=((tmpY-Y)/masse*(Vitesse)+depY_av)*(Vitesse);
  • Z-=((tmpZ-Z)/masse*(Vitesse)+depZ_av)*(Vitesse);
  • if(sqrt(pow(X,2)+pow(Y,2)+pow(Z,2))>CERCLEMAX)
  • {
  • X=tx;
  • Y=ty;
  • Z=tz;
  • }
  • }
  • if(abs(Vitesse)>0.01)
  • {
  • depX_av=-(tx-X)/(Vitesse);
  • depY_av=-(ty-Y)/(Vitesse);
  • depZ_av=-(tz-Z)/(Vitesse);
  • }
  • angle1+=dangle1*Vitesse;
  • refresh();
  • }else {
  • this->detruit=1;
  • }
  • }
  • void planet::refresh(void)
  • {
  • if(!detruit)
  • {
  • Luz(num);
  • glPushMatrix();
  • glTranslatef(X,Y,Z);
  • glRotatef( angle_dep, AxeRotX_dep,AxeRotY_dep,AxeRotZ_dep);
  • glRotatef( angle1, AxeRotX,AxeRotY,AxeRotZ);
  • /*
  • glutSolidSphere(size,3+50*size,3+50*size);
  • if(anneaux) glutSolidTorus(size/2,3.0*size,2,20);
  • glBegin(GL_LINES);
  • glVertex3f(0,0,0);
  • glVertex3f(20.0*depX_av,20.0*depY_av,20.0*depZ_av);
  • glEnd();*/
  • // glMatrixMode (GL_MODELVIEW);
  • GLUquadricObj *pQObj;
  • pQObj = gluNewQuadric();
  • glEnable(GL_DEPTH_TEST);
  • glEnable(GL_TEXTURE_2D);
  • if(ActiverTexture) glBindTexture(GL_TEXTURE_2D, Texture);
  • gluQuadricTexture(pQObj, true);
  • glColor3f(1,1,1);
  • gluQuadricDrawStyle(pQObj, GLU_FILL);
  • gluSphere(pQObj, size,10+50*size,10+50*size);
  • if(anneaux) glutSolidTorus(size/2,3.0*size,2,20);
  • glDisable(GL_TEXTURE_2D);
  • glDisable(GL_DEPTH_TEST);
  • gluDeleteQuadric(pQObj);
  • glPopMatrix();
  • }
  • }
  • void planet::deplacer(void)
  • {
  • double t,d;
  • tmpX=X,tmpY=Y,tmpZ=Z;
  • if(!detruit)
  • {
  • for(int i=0;i<(nbplanete);i++)
  • {
  • if(i!=num && !planete[i].detruit)
  • {
  • d=sqrt(pow(X-planete[i].X,2)+pow(Y-planete[i].Y,2)+pow(Z-planete[i].Z,2));
  • if(d>planete[i].size&& d>size )//d>=1.000001)
  • {
  • t=(G*planete[i].masse*masse)/(d*d);
  • tmpX+=t*(planete[i].X-X)/d;
  • tmpY+=t*(planete[i].Y-Y)/d;
  • tmpZ+=t*(planete[i].Z-Z)/d;
  • }else{
  • tueepar(i);
  • }
  • }
  • }
  • }
  • }
  • void planet::setposis(float x, float y, float z)
  • {
  • this->X=x;
  • this->Y=y;
  • this->Z=z;
  • }
  • void planet::setRotDepart(float a, float x, float y, float z)
  • {
  • angle_dep=a;
  • AxeRotX_dep=x;
  • AxeRotY_dep=y;
  • AxeRotZ_dep=z;
  • }
  • void planet::setRot(float da, float x, float y, float z)
  • {
  • dangle1=da;
  • AxeRotX=x;
  • AxeRotY=y;
  • AxeRotZ=z;
  • }
  • void planet::setvts(float x, float y, float z)
  • {
  • this->depX_av=x;
  • this->depY_av=y;
  • this->depZ_av=z;
  • }
  • void planet::tueepar(int i)
  • {
  • float j;
  • int x=60,y=50;
  • float PV=0;
  • double d1,d2,d3;
  • if(Destruction)
  • {
  • if(planete[i].masse>masse)
  • {
  • planete[i].depX_av+=depX_av*(masse/(planete[i].masse));
  • planete[i].depY_av+=depY_av*(masse/(planete[i].masse));
  • planete[i].depZ_av+=depZ_av*(masse/(planete[i].masse));
  • planete[i].masse+=masse;
  • planete[i].size=pow((double)pow(planete[i].size,3)+pow(size,3),1.0/3.0);
  • planete[i].size+=0.005;
  • detruit=1;
  • }else{
  • depX_av+=planete[i].depX_av*(planete[i].masse/(masse));
  • depY_av+=planete[i].depY_av*(planete[i].masse/(masse));
  • depZ_av+=planete[i].depZ_av*(planete[i].masse/(masse));
  • masse+=planete[i].masse;
  • size=pow((double)pow(planete[i].size,3)+pow(size,3),1.0/3.0);
  • size+=0.005;
  • planete[i].detruit=1;
  • }
  • if(SonActif)PlaySound("sons/crash.wav", NULL, NULL);
  • }else{
  • /*
  • ptmilX=planete[i].X-(masse*X-planete[i].masse*planete[i].X)/(planete[i].masse+masse);
  • ptmilY=planete[i].Y-(masse*Y-planete[i].masse*planete[i].Y)/(planete[i].masse+masse);
  • ptmilZ=planete[i].Z-(masse*Z-planete[i].masse*planete[i].Z)/(planete[i].masse+masse);
  • ptmilX2=planete[i].X-X;
  • ptmilY2=planete[i].Y-Y;
  • ptmilZ2=planete[i].Z-Z;
  • PV=ptmilX*ptmilX2+ptmilY*ptmilY2+ptmilZ*ptmilZ2;
  • // X-=1*(tmpX-X)+0.999*depX_av;
  • // Y-=1*(tmpY-Y)+0.999*depY_av;
  • // Z-=1*(tmpZ-Z)+0.999*depZ_av;
  • tmpX+=(planete[i].depX_av*PV)/masse*100;
  • tmpY+=(planete[i].depY_av*PV)/masse*100;
  • tmpZ+=(planete[i].depZ_av*PV)/masse*100;
  • */
  • /*
  • d1=planete[i].depX_av;
  • d2=planete[i].depY_av;
  • d3=planete[i].depZ_av;
  • planete[i].depX_av+=0.1*depX_av*(masse/(planete[i].masse));
  • planete[i].depY_av+=0.1*depY_av*(masse/(planete[i].masse));
  • planete[i].depZ_av+=0.1*depZ_av*(masse/(planete[i].masse));
  • depX_av+=0.1*d1*(planete[i].masse/(masse));
  • depY_av+=0.1*d2*(planete[i].masse/(masse));
  • depZ_av+=0.1*d3*(planete[i].masse/(masse));
  • */
  • }
  • }
  • void planet::setTexture(void)
  • {
  • FILE *f;
  • f = fopen("earth3.raw", "rb");
  • if (f){
  • fread(t, lar*lar*3, 1, f);
  • fclose(f);
  • }
  • glEnable(GL_TEXTURE_2D);
  • glBindTexture(GL_TEXTURE_2D,numTexture); //on travail sur la texture portant le numéro du selector
  • glTexImage2D(GL_TEXTURE_2D, 0,3, lar,lar, 0, GL_RGB, GL_UNSIGNED_BYTE, t);
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //on utilise l'application linéaire
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //de prés et de loin
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); //si on sort du carré [0,1]*[0,1] qui représente
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); //la texture, on la répéte le point (-1.7,2.8) équivaut a (0.3,2.8)
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY,1);
  • glDisable(GL_TEXTURE_2D);
  • Texture=1;
  • }
  • void CreerMonde(bool PremiereFois)
  • {
  • int i;
  • for(i=0;i<(MAXPLANETE);i++)
  • {
  • planete[i].num=i;
  • if(!PremiereFois)planete[i].init();
  • planete[i].Texture=i;
  • planete[i].ActiverTexture=1;
  • planete[i].setRotDepart(-80,1,0,0);
  • }
  • planete[0].masse = rand()%1000+50000;
  • planete[0].size =0.2;
  • planete[0].setvts(0,0,0);
  • planete[0].setposis(0,0,0);
  • planete[1].masse =5000;
  • planete[1].size =0.15;
  • planete[1].setvts(-0.01,0.007,0.005);
  • planete[1].setposis(1,1,1);
  • planete[1].setRotDepart(-90,1,0,0);
  • planete[1].setRot(0.3,0,0,1);
  • }
  • // Fonction control_cb ******************************************************
  • void control_cb( int controle )
  • {
  • switch (controle)
  • {
  • case NOUVEAU_ID :
  • CreerMonde(0);
  • break;
  • case PAUSE_ID :
  • if(Pause) Pause=0; else Pause=1;
  • break;
  • }
  • }//**************************************************************************
  • void
  • display(void)
  • {
  • glClear(GL_COLOR_BUFFER_BIT);
  • glutSwapBuffers();
  • }
  • // Definition de la fonction myGlutKeyboard() *******************************
  • void myGlutKeyboard(unsigned char Key, int x, int y)
  • {
  • switch(Key)
  • {
  • case ' ':
  • obj_pos[0] = 0.0;
  • obj_pos[1] = 0.0;
  • obj_pos[2] = 0.0;
  • //view_rotate = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
  • CreerMonde(0);
  • break;
  • case 's':
  • if(!SuivreTerre) SuivreTerre=1;
  • else SuivreTerre=0;
  • break;
  • case 'S':
  • obj_pos[0] = 0.0;
  • obj_pos[1] = 0.0;
  • obj_pos[2] = 0.0;
  • // glPrint(0,0, "white",1,"Fleches 'Haut' / 'Bas' pour selectionner une option...");
  • break;
  • case 'P':
  • case 'p':
  • if(Pause) Pause=0;
  • else Pause=1;
  • addPlanete();
  • if(SonActif)PlaySound("sons/pause.wav", NULL, NULL);
  • case 'D':
  • case 'd':
  • if(Destruction) Destruction=0;
  • else Destruction=1;
  • break;
  • case 27:
  • case 'q':
  • exit(0);
  • break;
  • };
  • glutPostRedisplay();
  • }
  • //***************************************************************************
  • // Definition de la fonction myGlutMenu() ***********************************
  • void myGlutMenu( int value )
  • {
  • myGlutKeyboard( value, 0, 0 );
  • }
  • //***************************************************************************
  • // Definition de la fonction myGlutIdle() ***********************************
  • void myGlutIdle( void )
  • {
  • /* According to the GLUT specification, the current window is
  • undefined during an idle callback. So we need to explicitly change
  • it if necessary */
  • if ( glutGetWindow() != main_window )
  • glutSetWindow(main_window);
  • glutPostRedisplay();
  • }
  • //***************************************************************************
  • // Definition de la fonction myGlutMouse() **********************************
  • void myGlutMouse(int button, int button_state, int x, int y )
  • {
  • if ( button == GLUT_LEFT_BUTTON && button_state == GLUT_DOWN )
  • {
  • last_x = x;
  • last_y = y; // planete[0].X = x/100.0; planete[0].Y = y/100.0;
  • }
  • if ( button == GLUT_MIDDLE_BUTTON )
  • {
  • obj_pos[2]-=0.05;
  • }
  • }
  • //***************************************************************************
  • // Definition de la fonction myGlutMotion() *********************************
  • void myGlutMotion(int x, int y )
  • {
  • glutPostRedisplay();
  • }
  • //***************************************************************************
  • // Definition de la fonction myGlutReshape() ********************************
  • void myGlutReshape( int x, int y )
  • {
  • int tx, ty, tw, th;
  • GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
  • glViewport( tx, ty, tw, th );
  • xy_aspect = (float)tw / (float)th;
  • glutPostRedisplay();
  • }
  • //***************************************************************************
  • void Luz(int num)
  • {
  • if(num!=0)
  • {
  • planete[num].setLP(planete[0].X,planete[0].Y,planete[0].Z,1.0);
  • glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
  • glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
  • glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
  • }else{
  • planete[num].setLP(1,1,0,1.0);
  • glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
  • glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
  • glLightfv(GL_LIGHTING, GL_POSITION, light0_position);
  • }
  • glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
  • glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
  • glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
  • }
  • // Definition de la fonction myGlutDisplay() ********************************
  • void myGlutDisplay( void )
  • {
  • //glClearColor( .9f, .9f, .9f, .9f ); // Couleur RGB du fond de la fenêtre
  • glClearColor( .0f, .0f, .0f, .0f );
  • glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  • glMatrixMode( GL_PROJECTION );
  • glLoadIdentity();
  • glFrustum( -xy_aspect*.04, xy_aspect*.04, -.04, .04, .1, 15.0 );
  • glMatrixMode( GL_MODELVIEW );
  • glLoadIdentity();
  • glMultMatrixf( lights_rotation );
  • glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
  • glLoadIdentity();
  • glTranslatef( 0.0, 0.0, -2.6f );
  • glTranslatef( obj_pos[0], obj_pos[1], -obj_pos[2] );
  • glMultMatrixf( view_rotate );
  • glScalef( scale, scale, scale );
  • int k;
  • //G=6.67*pow((double)10,(double)-11)*pow((double)10,(double)1);
  • if(!Pause)
  • {
  • if(SuivreTerre)
  • {
  • obj_pos[0] =-0.3*planete[1].X;
  • obj_pos[1] =-0.3*planete[1].Y;
  • obj_pos[2] =-0.3*planete[1].Z;
  • }
  • for(k=0;k<nbplanete;k++)
  • {
  • //if(k)
  • planete[k].deplacer();
  • }
  • for(k=0;k<nbplanete;k++)
  • {
  • planete[k].dessiner();
  • }
  • }else{
  • for(k=0;k<nbplanete;k++)
  • {
  • planete[k].refresh();
  • }
  • }
  • if(NbVitesse->get_float_val()!=Vitesse)
  • NbVitesse->set_float_val(Vitesse);
  • /*
  • GLUquadricObj *pQObj;
  • pQObj = gluNewQuadric();
  • glEnable(GL_DEPTH_TEST);
  • glEnable(GL_TEXTURE_2D);
  • glBindTexture(GL_TEXTURE_2D, MAXPLANETE);
  • gluQuadricTexture(pQObj, true);
  • glColor3f(1,1,1);
  • gluQuadricDrawStyle(pQObj, GLU_FILL);
  • gluSphere(pQObj,9,30,30);
  • glDisable(GL_TEXTURE_2D);
  • glDisable(GL_DEPTH_TEST);
  • gluDeleteQuadric(pQObj);
  • glPopMatrix();
  • */
  • glDisable( GL_LIGHTING );
  • glEnable( GL_LIGHTING ); // réctivation du jeu de lumière apres creation
  • glutSwapBuffers(); // swap sur le buffer
  • }
  • //***************************************************************************
  • // Definition de la fonction principale *************************************
  • void main(int argc, char* argv[])
  • {
  • /****************************************************/
  • /* Initialisation GLUT & creation de la fenêtre */
  • /****************************************************/
  • CreerMonde(1);
  • glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  • glutInitWindowPosition( 50, 50 );
  • glutInitWindowSize( 600, 600 );
  • main_window = glutCreateWindow( "__ MoNdE : Fenêtre 3D __" );
  • glutDisplayFunc( myGlutDisplay );
  • GLUI_Master.set_glutReshapeFunc( myGlutReshape );
  • GLUI_Master.set_glutKeyboardFunc( myGlutKeyboard );
  • GLUI_Master.set_glutSpecialFunc( NULL );
  • GLUI_Master.set_glutMouseFunc( myGlutMouse );
  • glutMotionFunc( myGlutMotion );
  • /********************************************************/
  • /* Initialisation OpenGL pour les effets de lumière */
  • /********************************************************/
  • //
  • glEnable(GL_LIGHTING);
  • glEnable( GL_NORMALIZE );
  • glEnable(GL_LIGHT0);
  • glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
  • glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
  • glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
  • glEnable(GL_LIGHT1);
  • glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
  • glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
  • glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
  • /*********************************/
  • /* Activation du z-buferring */
  • /*********************************/
  • glEnable(GL_DEPTH_TEST);
  • /******************************************/
  • /* Creation de la fenêtre de commande */
  • /******************************************/
  • printf( "__ MoNdE __\n");
  • printf( "\n GLUI version: %3.2f\n\n", GLUI_Master.get_version() );
  • printf( "Julien Michot - m.i.t.c.h@free.fr - www.fractals.fr.fm\n");
  • printf( "\nCommandes :\n");
  • printf( "\' \' -> nouveau monde\n");
  • printf( "s -> suivre la terre\n");
  • printf( "p -> pause\n");
  • printf( "d -> destruction des planetes\n");
  • printf( "q -> quitter\n");
  • /*** Creation de fenêtre glui ***/
  • glui = GLUI_Master.create_glui( "Monde : Remote Control",
  • 0, 700, 50 );
  • GLUI_Panel *cadre = glui->add_panel( "" );
  • GLUI_Panel *panel1 = glui->add_panel_to_panel(cadre, "Parametres :");
  • NbLigne = glui->add_spinner_to_panel( panel1, "Nombre de planetes:",
  • GLUI_SPINNER_INT, &nbplanete);
  • NbLigne->set_int_limits( 1, MAXPLANETE );
  • NbLigne->set_alignment( GLUI_ALIGN_RIGHT );
  • NbColonne = glui->add_spinner_to_panel( panel1, "cercle :",
  • GLUI_SPINNER_FLOAT, &CERCLEMAX);
  • NbColonne->set_float_limits( 0, 600 );
  • NbColonne->set_alignment( GLUI_ALIGN_RIGHT );
  • NbVitesse = glui->add_spinner_to_panel( panel1, "vitesse :",
  • GLUI_SPINNER_FLOAT, &Vitesse);
  • NbVitesse->set_float_limits( -10, 20 );
  • NbVitesse->set_alignment( GLUI_ALIGN_RIGHT );
  • glui->add_checkbox_to_panel(panel1,"Destruction", &Destruction );
  • glui->add_checkbox_to_panel(panel1,"Activer le son", &SonActif );
  • GLUI_Translation *trans_v =
  • glui->add_translation_to_panel(panel1, "vitesse", GLUI_TRANSLATION_X, &Vitesse);
  • trans_v->set_speed( .05 );
  • GLUI_Panel *panel4 = glui->add_panel_to_panel (cadre, "Traitement :");
  • glui->add_button_to_panel(panel4,"Lancer",LANCER_ID,control_cb);
  • glui->add_separator_to_panel( panel4 );
  • glui->add_button_to_panel(panel4,"Pause",PAUSE_ID,control_cb);
  • glui->add_column_to_panel(panel4, false );
  • glui->add_button_to_panel(panel4,"Nouveau monde",NOUVEAU_ID,control_cb);
  • glui->add_separator_to_panel( panel4 );
  • glui->add_button_to_panel(panel4,"Quitter", 0,(GLUI_Update_CB)exit );
  • /************************************/
  • /*** Creation de fenêtre glui ***/
  • glui3 = GLUI_Master.create_glui( "Monde : Remote Control",
  • 0, 700, 50 );
  • /************************************/
  • glui3->hide();
  • /*** Creation de la sous-fenêtre glui2 ***/
  • glui2 = GLUI_Master.create_glui_subwindow( main_window,
  • GLUI_SUBWINDOW_BOTTOM );
  • glui2->set_main_gfx_window( main_window );
  • //glutGameModeString("640x480:16@60");
  • glui2->add_statictext(" ");
  • glui2->add_statictext(" COMMANDE DE VISUALISATION ");
  • glui2->add_statictext(" SUR LA FENETRE PRINCIPALE :");
  • glui2->add_column( false );
  • GLUI_Rotation *view_rot = glui2->add_rotation( "Objects", view_rotate );
  • view_rot->set_spin( 1.0 );
  • glui2->add_column( false );
  • GLUI_Translation *trans_xy =
  • glui2->add_translation( "Objects XY", GLUI_TRANSLATION_XY, obj_pos );
  • trans_xy->set_speed( .005 );
  • glui2->add_column( false );
  • GLUI_Translation *trans_x =
  • glui2->add_translation( "Objects X", GLUI_TRANSLATION_X, obj_pos );
  • trans_x->set_speed( .005 );
  • glui2->add_column( false );
  • GLUI_Translation *trans_y =
  • glui2->add_translation( "Objects Y", GLUI_TRANSLATION_Y, &obj_pos[1] );
  • trans_y->set_speed( .005 );
  • glui2->add_column( false );
  • GLUI_Translation *trans_z =
  • glui2->add_translation( "Objects Z", GLUI_TRANSLATION_Z, &obj_pos[2] );
  • trans_z->set_speed( .005 );
  • /*********************************************/
  • /**** Enregistremznt des idle callback pour GLUI ****/
  • GLUI_Master.set_glutIdleFunc( myGlutIdle );
  • int i,j,x,y,nb_crat,x_mil,y_mil,rayon_crat;
  • float theta=0,rapp;
  • FILE *f;
  • // f = fopen("soleil.raw", "wb");
  • for(j=0;j<MAXPLANETE;j++)
  • {
  • for(i=0;i<256*256*3;i+=3)
  • {
  • if(j)
  • {
  • planete[j].t[i]=200+rand()%50;
  • planete[j].t[i+1]=130+rand()%20;
  • planete[j].t[i+2]=15+rand()%10;
  • if(i<20*256*3|| i> 230*3*256)
  • {
  • planete[j].t[i]+=5;
  • planete[j].t[i+1]+=20;
  • planete[j].t[i+2]+=70;
  • }
  • }else{//soleil
  • planete[j].t[i]=200+rand()%50;
  • planete[j].t[i+1]=180+rand()%50;
  • planete[j].t[i+2]=15+rand()%10;
  • // fwrite(&planete[j].t[i], 1, 1, f);
  • // fwrite(&planete[j].t[i+1], 1, 1, f);
  • // fwrite(&planete[j].t[i+2], 1, 1, f);
  • }
  • }
  • // création des cratères
  • for(nb_crat=100;nb_crat>0&&j!=0;nb_crat--)
  • {
  • x_mil=rand()%255+1;
  • y_mil=rand()%255+1;
  • rapp=2*(128+y_mil)/256.0;
  • if(y_mil>128) rapp=2*(128.0+256.0-y_mil)/256.0;
  • rayon_crat=rand()%20+4;
  • for(theta=0;theta<(2*PI);theta+=0.1)
  • {
  • x=x_mil+rayon_crat*cos(theta);
  • y=y_mil+(int)(rayon_crat*rapp*sin(theta));
  • if(x>=256) x-=x_mil;
  • if(y>=256)
  • {
  • y=y_mil-(int)((rapp)*rayon_crat*sin(theta));
  • x=256-x;
  • }
  • planete[j].t[(int)(x*3+y*256*3)]-=20;
  • planete[j].t[(int)(x*3+y*256*3)+1]-=20;
  • //planete[j].t[(int)(x*3+y*256*3)+2]-=20;
  • }
  • }
  • glEnable(GL_TEXTURE_2D);
  • glBindTexture(GL_TEXTURE_2D,j); //on travail sur la texture portant le numéro du selector
  • glTexImage2D(GL_TEXTURE_2D, 0,3, lar,lar, 0, GL_RGB, GL_UNSIGNED_BYTE, planete[j].t);
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //on utilise l'application linéaire
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //de prés et de loin
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); //si on sort du carré [0,1]*[0,1] qui représente
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); //la texture, on la répéte le point (-1.7,2.8) équivaut a (0.3,2.8)
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY,1);
  • glDisable(GL_TEXTURE_2D);
  • }
  • // fclose(f);
  • //terre
  • f = fopen("textures/earth3.raw", "rb");
  • if (f){
  • fread(planete[1].t, 256*256*3, 1, f);
  • fclose(f);
  • }
  • glEnable(GL_TEXTURE_2D);
  • glBindTexture(GL_TEXTURE_2D,1); //on travail sur la texture portant le numéro du selector
  • glTexImage2D(GL_TEXTURE_2D, 0,3, 256,256, 0, GL_RGB, GL_UNSIGNED_BYTE, planete[1].t);
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //on utilise l'application linéaire
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //de prés et de loin
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); //si on sort du carré [0,1]*[0,1] qui représente
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); //la texture, on la répéte le point (-1.7,2.8) équivaut a (0.3,2.8)
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY,1);
  • glDisable(GL_TEXTURE_2D);
  • /*
  • f = fopen("ciel.raw", "rb");
  • if (f){
  • fread(t, lar*lar*3, 1, f);
  • fclose(f);
  • }
  • for(i=3;i<256*256*3;i+=3)
  • {
  • if(rand()%50)
  • {
  • t[i]=t[0];
  • t[i+1]=t[1];
  • t[i+2]=t[2];
  • }else{
  • t[i]=255;
  • t[i+1]=255;
  • t[i+2]=255;
  • }
  • }
  • glEnable(GL_TEXTURE_2D);
  • glBindTexture(GL_TEXTURE_2D,MAXPLANETE); //on travail sur la texture portant le numéro du selector
  • glTexImage2D(GL_TEXTURE_2D, 0,3, lar,lar, 0, GL_RGB, GL_UNSIGNED_BYTE, t);
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //on utilise l'application linéaire
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //de prés et de loin
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); //si on sort du carré [0,1]*[0,1] qui représente
  • glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); //la texture, on la répéte le point (-1.7,2.8) équivaut a (0.3,2.8)
  • // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY,1);
  • glDisable(GL_TEXTURE_2D);
  • */
  • glutMainLoop();
  • }
  • //***************************************************************************
  • void addPlanete(void)
  • {
  • // glui3->show();
  • }
/********************************************************************************
*                                                                               *
*                                     MoNdE                                     *
* 																				*
* MoNdE is a planets generator, with a the gravity force.						*
* 																				*
* Copyright (C) 2004-2005  Julien MICHOT										*
* 																				*
* Contact : m.i.t.c.h@free.fr - http://www.webfractales.com					*
* 																				*
* This program is free software; you can redistribute it and/or					*
* modify it under the terms of the GNU General Public License					*
* as published by the Free Software Foundation; either version 2				*
* of the License, or (at your option) any later version.						*
* 																				*
* This program is distributed in the hope that it will be useful,				*
* but WITHOUT ANY WARRANTY; without even the implied warranty of				*
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the					*
* GNU General Public License for more details.									*
* 																				*
* You should have received a copy of the GNU General Public License				*
* along with this program; if not, write to the Free Software					*
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.	*
* 																				*
* 																				*
* 	You can have the GLUT library here :				 						*
*    http://www.opengl.org/resources/libraries/glut.html    					*
* 																				*
* 	You can have the GLUI library here :				 						*
*    http://www.cs.unc.edu/~rademach/glui/				    					*
* 																				*
********************************************************************************/

// Headers utilisés *********************************************************
#include <string.h>
#include <windows.h> //pour le son...
#include "glut.h"
#include "tube.h"
#include "glui.h"
#include "math.h"
#include "time.h"

//***************************************************************************

#define MAX(a,b) (((a)>(b))?(a):(b))


#define PI 3.1415926535897932384626433832
#define MAXPLANETE 100
#define TAILLEESPACE 3.0
#define DENSITE 0.0001


float		CERCLEMAX=6.0;
float		Vitesse=1.3;
double      G=6.67*pow((double)10,(double)-11)*100.0;//*0.000000001//-11

int      	nbplanete= 70;
int			Destruction=1;
int			SonActif=0;
float		xy_aspect;
int			last_x, last_y;
float		rotationX = 0.0, rotationY = 0.0;
int			sens=1,arret=1;
float		RapportVts=2.0,tmpvts=0.0018;
bool		Pause=0;
bool		SuivreTerre=0;

// Variables passées à GLUI *************************************************
int		main_window;
float	scale = 0.3;
int	    ColonneInit= 4;
int		obj_type = 2;
float   obj_pos[] = { 0.0, 0.0, 0.0 };
float   view_rotate[16] = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
//***************************************************************************


	int lar=256;
	unsigned char t[256*256*3];
	unsigned char t2[256*256*3];
	int numTexture=1;

// Pointeurs se rapportant a GLUI *******************************************
GLUI            *glui, *glui2, *glui3;
GLUI_Spinner    *NbLigne, *NbColonne, *destruction,*NbVitesse;
GLUI_Button     *test;
GLUI_RadioGroup *radio;
//***************************************************************************


// Id utilisés pour les callback ********************************************
#define LANCER_ID   2
#define PAUSE_ID    3
#define NOUVEAU_ID  4
//***************************************************************************


// Divers variables globales ************************************************
/*
GLfloat light0_ambient[] =  {0.6f, 0.1f, 0.3f, 1.0f};
GLfloat light0_diffuse[] =  {.9f, .6f, 0.0f, 1.0f};
GLfloat light0_position[] = {0.0f, .0f, 0.0f, 1.0f};
*/


GLfloat light0_ambient[] =  {0.9f, 0.9f, 0.9f, 1.0f};
GLfloat light0_diffuse[] =  {.9f, .9f, 0.9f, 1.0f};
GLfloat light0_position[] = {0.0f, .0f, 0.0f, 1.0f};


GLfloat light1_ambient[] =  {0.9f, 0.9f, 0.9f, 1.0f};
GLfloat light1_diffuse[] =  {.9f, .9f, 0.9f, 1.0f};
GLfloat light1_position[] = {1.0f, 1.0f, 0.0f, 1.0f};

GLfloat lights_rotation[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
//***************************************************************************

bool	matrice[5][5][5];

void Luz(int num);
void addPlanete(void);


class planet
{
public:
	int		num;
	float	angle1,dangle1;
	float	size;
	float	rayon1,rayon2;
	float	X,Y,Z;
	float	tmpX,tmpY,tmpZ;	
	float	depX_av,depY_av,depZ_av;
	int		numParent;
	double	masse;
	float	vtsinit;
	bool	detruit;
	bool	anneaux;
	float	AxeRotX,AxeRotY,AxeRotZ;//rotation

	float	angle_dep,AxeRotX_dep,AxeRotY_dep,AxeRotZ_dep;//rotation de départ
	// pour les textures
	bool	ActiverTexture;
	int  	Texture;
	unsigned char t[256*256*3];
	
	
	GLfloat l_ambient[4];
	GLfloat l_diffuse[4];
	GLfloat l_position[4];

	planet();
	~planet();
	void init(void);
	void dessiner(void);
	void refresh(void);
	void deplacer(void);
	void setposis(float x, float y, float z);
	void setvts(float x, float y, float z);
	void tueepar(int i);
	void setmasse(float m);
	void setLA(float a, float b, float c, float d);
	void setLD(float a, float b, float c, float d);
	void setLP(float a, float b, float c, float d);
	void setRot(float da, float x, float y, float z);
	void setRotDepart(float a, float x, float y, float z);
	void setTexture(void);
}planete[MAXPLANETE];

planet::planet()
{
	init(); 
}

planet::~planet()
{

}

void planet::init(void)
{

	X=(float)(rand()%((int)TAILLEESPACE*20)-(TAILLEESPACE*10))/10.0;
	Y=(float)(rand()%((int)TAILLEESPACE*20)-(TAILLEESPACE*10))/10.0;
	Z=(float)(rand()%((int)TAILLEESPACE*20)-(TAILLEESPACE*10))/10.0;
	depX_av=(rand()%20-10)/1000.0;
	depY_av=(rand()%20-10)/1000.0;
	depZ_av=(rand()%20-10)/1000.0;
	angle1=0;
	size=0.1;
	numParent=0;
	dangle1=(rand()%40-40.0)/100.0;
	rayon1=1;
	rayon2=rayon1;
	masse = rand()%1000;
	size=DENSITE*masse;//20.0/masse;
	vtsinit=1;
	setLA(0.9f, 0.9f, 0.9f, 1.0f);
	setLD(.9f, .8f, 0.0f, 1.0f);
//	setLA((rand()%100)/100.0, (rand()%100)/100.0,(rand()%100)/100.0, 1.0f);
//	setLD((rand()%100)/100.0, (rand()%100)/100.0,(rand()%100)/100.0, 1.0f);
	setLP(0.0f, .0f, 0.0f, 1.0f);
	if(masse>500) anneaux=(!(rand()%5));
	else anneaux=0;
	Texture=0;
	ActiverTexture=0;
	AxeRotX=(rand()%10)/10.0;
	AxeRotY=(rand()%10)/10.0;
	AxeRotZ=(rand()%10)/10.0;
	angle_dep=rand()%360;
	AxeRotX_dep=(rand()%10)/10.0;
	AxeRotY_dep=(rand()%10)/10.0;
	AxeRotZ_dep=(rand()%10)/10.0;

	detruit=0;
}	


void planet::setLA(float a, float b, float c, float d)
{
	l_ambient[0]=a;
	l_ambient[1]=b;
	l_ambient[2]=c;
	l_ambient[3]=d;
}
void planet::setLD(float a, float b, float c, float d)
{
	l_diffuse[0]=a;
	l_diffuse[1]=b;
	l_diffuse[2]=c;
	l_diffuse[3]=d;
}
void planet::setLP(float a, float b, float c, float d)
{
	l_position[0]=a;
	l_position[1]=b;
	l_position[2]=c;
	l_position[3]=d;
	for(int i=0;i<4;i++)
	{
		light0_ambient[i]=l_ambient[i];
		light0_diffuse[i]=l_diffuse[i];
		light0_position[i]=l_position[i];
	}
}


void planet::setmasse(float m)
{
	masse=m;
	size=DENSITE*masse;

}

void planet::dessiner(void)
{
	float tx,ty,tz;


		if(!detruit)
		{
			tx=X;
			ty=Y;
			tz=Z;
		
		if(sqrt(pow(X,2)+pow(Y,2)+pow(Z,2))<CERCLEMAX||CERCLEMAX==0)
			{
				X+=((tmpX-X)/masse*(Vitesse)+depX_av)*(Vitesse);
				Y+=((tmpY-Y)/masse*(Vitesse)+depY_av)*(Vitesse);
				Z+=((tmpZ-Z)/masse*(Vitesse)+depZ_av)*(Vitesse);
			}else{
				X-=((tmpX-X)/masse*(Vitesse)+depX_av)*(Vitesse);
				Y-=((tmpY-Y)/masse*(Vitesse)+depY_av)*(Vitesse);
				Z-=((tmpZ-Z)/masse*(Vitesse)+depZ_av)*(Vitesse);
				if(sqrt(pow(X,2)+pow(Y,2)+pow(Z,2))>CERCLEMAX)
				{
					X=tx;
					Y=ty;
					Z=tz;
				}
			}

			if(abs(Vitesse)>0.01)
			{
			depX_av=-(tx-X)/(Vitesse);
			depY_av=-(ty-Y)/(Vitesse);
			depZ_av=-(tz-Z)/(Vitesse);
			}
			angle1+=dangle1*Vitesse;
			
			refresh();

		}else {
			this->detruit=1;

		}

}

void planet::refresh(void)
{
		if(!detruit)
		{
			Luz(num);
			glPushMatrix();
			glTranslatef(X,Y,Z);
			glRotatef( angle_dep, AxeRotX_dep,AxeRotY_dep,AxeRotZ_dep);
			glRotatef( angle1, AxeRotX,AxeRotY,AxeRotZ);
			/*
			glutSolidSphere(size,3+50*size,3+50*size);
			if(anneaux) glutSolidTorus(size/2,3.0*size,2,20);
			glBegin(GL_LINES);
			glVertex3f(0,0,0);
			glVertex3f(20.0*depX_av,20.0*depY_av,20.0*depZ_av);
			glEnd();*/
			 


	//		glMatrixMode (GL_MODELVIEW); 
	
			GLUquadricObj *pQObj;
			pQObj = gluNewQuadric();
			glEnable(GL_DEPTH_TEST);
			glEnable(GL_TEXTURE_2D);
			if(ActiverTexture) glBindTexture(GL_TEXTURE_2D, Texture);
			gluQuadricTexture(pQObj, true);
			glColor3f(1,1,1);
			gluQuadricDrawStyle(pQObj, GLU_FILL);
			gluSphere(pQObj, size,10+50*size,10+50*size); 
			if(anneaux) glutSolidTorus(size/2,3.0*size,2,20);
			glDisable(GL_TEXTURE_2D);
			glDisable(GL_DEPTH_TEST);
			gluDeleteQuadric(pQObj);
			glPopMatrix();

		}
}

void planet::deplacer(void)
{
	double t,d;
	tmpX=X,tmpY=Y,tmpZ=Z;

	if(!detruit)
	{
		for(int i=0;i<(nbplanete);i++)
		{
			if(i!=num && !planete[i].detruit)
			{
				d=sqrt(pow(X-planete[i].X,2)+pow(Y-planete[i].Y,2)+pow(Z-planete[i].Z,2));
				if(d>planete[i].size&& d>size )//d>=1.000001) 
				{
					t=(G*planete[i].masse*masse)/(d*d);
					tmpX+=t*(planete[i].X-X)/d;
					tmpY+=t*(planete[i].Y-Y)/d;
					tmpZ+=t*(planete[i].Z-Z)/d;
				}else{
					tueepar(i);
				}
			}
		}

	}
}

void planet::setposis(float x, float y, float z)
{
	this->X=x;
	this->Y=y;
	this->Z=z;
}
	
void planet::setRotDepart(float a, float x, float y, float z)
{
	angle_dep=a;
	AxeRotX_dep=x;
	AxeRotY_dep=y;
	AxeRotZ_dep=z;
}
	
void planet::setRot(float da, float x, float y, float z)
{
	dangle1=da;
	AxeRotX=x;
	AxeRotY=y;
	AxeRotZ=z;
}
void planet::setvts(float x, float y, float z)
{
	this->depX_av=x;
	this->depY_av=y;
	this->depZ_av=z;
}

void planet::tueepar(int i)
{
	float j;
	int x=60,y=50;
	float PV=0;
	double d1,d2,d3;
	if(Destruction) 
	{
		if(planete[i].masse>masse)
		{
			planete[i].depX_av+=depX_av*(masse/(planete[i].masse));
			planete[i].depY_av+=depY_av*(masse/(planete[i].masse));
			planete[i].depZ_av+=depZ_av*(masse/(planete[i].masse));
			planete[i].masse+=masse;
			planete[i].size=pow((double)pow(planete[i].size,3)+pow(size,3),1.0/3.0);
			planete[i].size+=0.005;
			detruit=1;
		}else{

			depX_av+=planete[i].depX_av*(planete[i].masse/(masse));
			depY_av+=planete[i].depY_av*(planete[i].masse/(masse));
			depZ_av+=planete[i].depZ_av*(planete[i].masse/(masse));
			masse+=planete[i].masse;
			size=pow((double)pow(planete[i].size,3)+pow(size,3),1.0/3.0);
			size+=0.005;
			planete[i].detruit=1;
		}
		if(SonActif)PlaySound("sons/crash.wav", NULL, NULL);

	}else{
		/*
	 ptmilX=planete[i].X-(masse*X-planete[i].masse*planete[i].X)/(planete[i].masse+masse);
	 ptmilY=planete[i].Y-(masse*Y-planete[i].masse*planete[i].Y)/(planete[i].masse+masse);
	 ptmilZ=planete[i].Z-(masse*Z-planete[i].masse*planete[i].Z)/(planete[i].masse+masse);
	 ptmilX2=planete[i].X-X;
	 ptmilY2=planete[i].Y-Y;
	 ptmilZ2=planete[i].Z-Z;
	 PV=ptmilX*ptmilX2+ptmilY*ptmilY2+ptmilZ*ptmilZ2;
			//	X-=1*(tmpX-X)+0.999*depX_av;
			//	Y-=1*(tmpY-Y)+0.999*depY_av;
			//	Z-=1*(tmpZ-Z)+0.999*depZ_av;
					tmpX+=(planete[i].depX_av*PV)/masse*100;
					tmpY+=(planete[i].depY_av*PV)/masse*100;
					tmpZ+=(planete[i].depZ_av*PV)/masse*100;
					*/
		/*
		d1=planete[i].depX_av;
		d2=planete[i].depY_av;
		d3=planete[i].depZ_av;
			planete[i].depX_av+=0.1*depX_av*(masse/(planete[i].masse));
			planete[i].depY_av+=0.1*depY_av*(masse/(planete[i].masse));
			planete[i].depZ_av+=0.1*depZ_av*(masse/(planete[i].masse));
			depX_av+=0.1*d1*(planete[i].masse/(masse));
			depY_av+=0.1*d2*(planete[i].masse/(masse));
			depZ_av+=0.1*d3*(planete[i].masse/(masse));
			*/
	}
}

void planet::setTexture(void)
{
	 FILE *f;
     f = fopen("earth3.raw", "rb");
     if (f){
          fread(t, lar*lar*3, 1, f);
          fclose(f);
          }
     glEnable(GL_TEXTURE_2D);
     glBindTexture(GL_TEXTURE_2D,numTexture);                                    //on travail sur la texture portant le numéro du selector
     glTexImage2D(GL_TEXTURE_2D, 0,3, lar,lar, 0, GL_RGB, GL_UNSIGNED_BYTE, t);
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);          //on utilise l'application linéaire
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);          //de prés et de loin
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );             //si on sort du carré [0,1]*[0,1] qui représente
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );             //la texture, on la répéte le point (-1.7,2.8) équivaut a (0.3,2.8)
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY,1);
	glDisable(GL_TEXTURE_2D);
	Texture=1;

}

void CreerMonde(bool PremiereFois)
{
	int i;
			for(i=0;i<(MAXPLANETE);i++)
			{
				planete[i].num=i;
				if(!PremiereFois)planete[i].init();
				planete[i].Texture=i;
				planete[i].ActiverTexture=1;
				planete[i].setRotDepart(-80,1,0,0);
			}
				planete[0].masse = rand()%1000+50000;
				planete[0].size =0.2;
				planete[0].setvts(0,0,0);
				planete[0].setposis(0,0,0);	

				planete[1].masse =5000;
				planete[1].size =0.15;
				planete[1].setvts(-0.01,0.007,0.005);
				planete[1].setposis(1,1,1);	
				planete[1].setRotDepart(-90,1,0,0);
				planete[1].setRot(0.3,0,0,1);

}

// Fonction control_cb ******************************************************
void control_cb( int controle )
{
	switch (controle)
	{
		case NOUVEAU_ID :
				CreerMonde(0);		
			 break;
		case PAUSE_ID :
			if(Pause) Pause=0; else Pause=1;			
			 break;
	}
}//**************************************************************************


void
display(void)
{
  glClear(GL_COLOR_BUFFER_BIT);
  glutSwapBuffers();
}


// Definition de la fonction myGlutKeyboard() *******************************
void myGlutKeyboard(unsigned char Key, int x, int y)
{

  switch(Key)
  {
  case ' ':
	obj_pos[0] = 0.0;
	obj_pos[1] = 0.0;
	obj_pos[2] = 0.0;
   //view_rotate = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };

				CreerMonde(0);	
	break;
  case 's':
		if(!SuivreTerre) SuivreTerre=1;
		else SuivreTerre=0;
	break;
  case 'S':
	obj_pos[0] = 0.0;
	obj_pos[1] = 0.0;
	obj_pos[2] = 0.0;
//	glPrint(0,0, "white",1,"Fleches 'Haut' / 'Bas' pour selectionner une option...");
	break;
  case 'P':
  case 'p':
		if(Pause) Pause=0;
		else Pause=1;
		addPlanete();
          if(SonActif)PlaySound("sons/pause.wav", NULL, NULL);

  case 'D':
  case 'd':
		if(Destruction) Destruction=0;
		else Destruction=1;
	break;
  case 27: 
  case 'q':
    exit(0);
    break;
  };
  
  glutPostRedisplay();
}
//***************************************************************************


// Definition de la fonction myGlutMenu() ***********************************
void myGlutMenu( int value )
{
  myGlutKeyboard( value, 0, 0 );
}
//***************************************************************************


// Definition de la fonction myGlutIdle() ***********************************
void myGlutIdle( void )
{
  /* According to the GLUT specification, the current window is 
     undefined during an idle callback.  So we need to explicitly change
     it if necessary */
  if ( glutGetWindow() != main_window ) 
    glutSetWindow(main_window);  


  glutPostRedisplay();
}
//***************************************************************************


// Definition de la fonction myGlutMouse() **********************************
void myGlutMouse(int button, int button_state, int x, int y )
{
	if ( button == GLUT_LEFT_BUTTON && button_state == GLUT_DOWN ) 
	{
		last_x = x;
		last_y = y;	//	planete[0].X = x/100.0;		planete[0].Y = y/100.0;
	}
	if ( button == GLUT_MIDDLE_BUTTON ) 
	{
			obj_pos[2]-=0.05;
	}

}
//***************************************************************************

// Definition de la fonction myGlutMotion() *********************************
void myGlutMotion(int x, int y )
{
  glutPostRedisplay(); 
}
//***************************************************************************


// Definition de la fonction myGlutReshape() ********************************
void myGlutReshape( int x, int y )
{
  int tx, ty, tw, th;
  GLUI_Master.get_viewport_area( &tx, &ty, &tw, &th );
  glViewport( tx, ty, tw, th );

  xy_aspect = (float)tw / (float)th;

  glutPostRedisplay();
}
//***************************************************************************

void Luz(int num)
{
	if(num!=0)
	{
	planete[num].setLP(planete[0].X,planete[0].Y,planete[0].Z,1.0);
	glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
	glLightfv(GL_LIGHT0, GL_POSITION,  light0_position);
	}else{

	planete[num].setLP(1,1,0,1.0);
	glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
	glLightfv(GL_LIGHTING, GL_POSITION, light0_position);
	}
	glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
	glLightfv(GL_LIGHT1, GL_POSITION,  light1_position);
	
}
// Definition de la fonction myGlutDisplay() ********************************
void myGlutDisplay( void )
{

  //glClearColor( .9f, .9f, .9f, .9f ); // Couleur RGB du fond de la fenêtre
  glClearColor( .0f, .0f, .0f, .0f );
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

  glMatrixMode( GL_PROJECTION );
  glLoadIdentity();
  glFrustum( -xy_aspect*.04, xy_aspect*.04, -.04, .04, .1, 15.0 );

  glMatrixMode( GL_MODELVIEW );

  glLoadIdentity();
  glMultMatrixf( lights_rotation );
  glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
  
  glLoadIdentity();
  glTranslatef( 0.0, 0.0, -2.6f );
  glTranslatef( obj_pos[0], obj_pos[1], -obj_pos[2] ); 
  glMultMatrixf( view_rotate );

  glScalef( scale, scale, scale );
	int k;

	//G=6.67*pow((double)10,(double)-11)*pow((double)10,(double)1);

	if(!Pause)
	{
		if(SuivreTerre)
		{
			obj_pos[0] =-0.3*planete[1].X;
			obj_pos[1] =-0.3*planete[1].Y;
			obj_pos[2] =-0.3*planete[1].Z;
		}
		for(k=0;k<nbplanete;k++)
		{
			//if(k)

			planete[k].deplacer();
		}
		for(k=0;k<nbplanete;k++)
		{
			planete[k].dessiner();
		}
	}else{
		for(k=0;k<nbplanete;k++)
		{
			planete[k].refresh();
		}
	}

	if(NbVitesse->get_float_val()!=Vitesse)
	NbVitesse->set_float_val(Vitesse);
	
/*
	GLUquadricObj *pQObj;
			pQObj = gluNewQuadric();
			glEnable(GL_DEPTH_TEST);
			glEnable(GL_TEXTURE_2D);
			 glBindTexture(GL_TEXTURE_2D, MAXPLANETE);
			gluQuadricTexture(pQObj, true);
			glColor3f(1,1,1);
			gluQuadricDrawStyle(pQObj, GLU_FILL);
			gluSphere(pQObj,9,30,30); 
			glDisable(GL_TEXTURE_2D);
			glDisable(GL_DEPTH_TEST);
			gluDeleteQuadric(pQObj);
			glPopMatrix();
*/
  glDisable( GL_LIGHTING );   
  glEnable( GL_LIGHTING );      // réctivation du jeu de lumière apres creation
  glutSwapBuffers();			// swap sur le buffer
}
//***************************************************************************


// Definition de la fonction principale *************************************
void main(int argc, char* argv[])
{
  /****************************************************/
  /*   Initialisation GLUT & creation de la fenêtre   */
  /****************************************************/
  CreerMonde(1);
  glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  glutInitWindowPosition( 50, 50 );
  glutInitWindowSize( 600, 600 );
 
  main_window = glutCreateWindow( "__ MoNdE : Fenêtre 3D __" );
  glutDisplayFunc( myGlutDisplay );
  GLUI_Master.set_glutReshapeFunc( myGlutReshape );  
  GLUI_Master.set_glutKeyboardFunc( myGlutKeyboard );
  GLUI_Master.set_glutSpecialFunc( NULL );
  GLUI_Master.set_glutMouseFunc( myGlutMouse );
  glutMotionFunc( myGlutMotion );

  /********************************************************/
  /*   Initialisation OpenGL pour les effets de lumière   */
  /********************************************************/

  //
  glEnable(GL_LIGHTING);
  glEnable( GL_NORMALIZE );

  glEnable(GL_LIGHT0);
  glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
  glLightfv(GL_LIGHT0, GL_POSITION, light0_position);

  glEnable(GL_LIGHT1);
  glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
  glLightfv(GL_LIGHT1, GL_POSITION, light1_position);

  /*********************************/
  /*   Activation du z-buferring   */
  /*********************************/

  glEnable(GL_DEPTH_TEST);

  /******************************************/
  /*   Creation de la fenêtre de commande   */
  /******************************************/

  printf( "__ MoNdE __\n");
  printf( "\n GLUI version: %3.2f\n\n", GLUI_Master.get_version() );
  printf( "Julien Michot - m.i.t.c.h@free.fr - www.fractals.fr.fm\n");
  printf( "\nCommandes :\n");
  printf( "\' \' -> nouveau monde\n");
  printf( "s -> suivre la terre\n");
  printf( "p -> pause\n");
  printf( "d -> destruction des planetes\n");
  printf( "q -> quitter\n");
  /***   Creation de fenêtre glui   ***/
  glui = GLUI_Master.create_glui( "Monde : Remote Control",
						   0, 700, 50 );
  GLUI_Panel *cadre  = glui->add_panel( "" );
  GLUI_Panel *panel1 = glui->add_panel_to_panel(cadre, "Parametres :");
  NbLigne  = glui->add_spinner_to_panel( panel1, "Nombre de planetes:",
					 GLUI_SPINNER_INT, &nbplanete);
  NbLigne->set_int_limits( 1, MAXPLANETE );
  NbLigne->set_alignment( GLUI_ALIGN_RIGHT );

  NbColonne  = glui->add_spinner_to_panel( panel1, "cercle :",
					 GLUI_SPINNER_FLOAT, &CERCLEMAX);
  NbColonne->set_float_limits( 0, 600 );
  NbColonne->set_alignment( GLUI_ALIGN_RIGHT );

  NbVitesse  = glui->add_spinner_to_panel( panel1, "vitesse :",
					 GLUI_SPINNER_FLOAT, &Vitesse);
  NbVitesse->set_float_limits( -10, 20 );
  NbVitesse->set_alignment( GLUI_ALIGN_RIGHT );

  glui->add_checkbox_to_panel(panel1,"Destruction", &Destruction );
  glui->add_checkbox_to_panel(panel1,"Activer le son", &SonActif );
  GLUI_Translation *trans_v = 
	  glui->add_translation_to_panel(panel1, "vitesse", GLUI_TRANSLATION_X, &Vitesse);
  trans_v->set_speed( .05 );
  GLUI_Panel *panel4 = glui->add_panel_to_panel (cadre, "Traitement :");
  

    glui->add_button_to_panel(panel4,"Lancer",LANCER_ID,control_cb);
  glui->add_separator_to_panel( panel4 );
  glui->add_button_to_panel(panel4,"Pause",PAUSE_ID,control_cb);
  glui->add_column_to_panel(panel4, false );
  glui->add_button_to_panel(panel4,"Nouveau monde",NOUVEAU_ID,control_cb);
  glui->add_separator_to_panel( panel4 );
  glui->add_button_to_panel(panel4,"Quitter", 0,(GLUI_Update_CB)exit );

  /************************************/
 /***   Creation de fenêtre glui   ***/
  glui3 = GLUI_Master.create_glui( "Monde : Remote Control",
						   0, 700, 50 );

  /************************************/
  glui3->hide();

  /***   Creation de la sous-fenêtre glui2   ***/
  glui2 = GLUI_Master.create_glui_subwindow( main_window, 
					     GLUI_SUBWINDOW_BOTTOM );
  glui2->set_main_gfx_window( main_window );

    //glutGameModeString("640x480:16@60");

  glui2->add_statictext(" ");
  glui2->add_statictext(" COMMANDE DE VISUALISATION ");
  glui2->add_statictext(" SUR LA FENETRE PRINCIPALE  :");
  glui2->add_column( false );
  GLUI_Rotation *view_rot = glui2->add_rotation( "Objects", view_rotate );
  view_rot->set_spin( 1.0 );
  glui2->add_column( false );
  GLUI_Translation *trans_xy = 
    glui2->add_translation( "Objects XY", GLUI_TRANSLATION_XY, obj_pos );
  trans_xy->set_speed( .005 );
  glui2->add_column( false );
  GLUI_Translation *trans_x = 
    glui2->add_translation( "Objects X", GLUI_TRANSLATION_X, obj_pos );
  trans_x->set_speed( .005 );
  glui2->add_column( false );
  GLUI_Translation *trans_y = 
    glui2->add_translation( "Objects Y", GLUI_TRANSLATION_Y, &obj_pos[1] );
  trans_y->set_speed( .005 );
  glui2->add_column( false );
  GLUI_Translation *trans_z = 
    glui2->add_translation( "Objects Z", GLUI_TRANSLATION_Z, &obj_pos[2] );
  trans_z->set_speed( .005 );
  /*********************************************/

  /****   Enregistremznt des idle callback pour GLUI   ****/
  GLUI_Master.set_glutIdleFunc( myGlutIdle );

		int i,j,x,y,nb_crat,x_mil,y_mil,rayon_crat;
		float theta=0,rapp;
	 FILE *f;
//	      f = fopen("soleil.raw", "wb");

		for(j=0;j<MAXPLANETE;j++)
		{
			for(i=0;i<256*256*3;i+=3)
			{
				if(j)
				{
					planete[j].t[i]=200+rand()%50;
					planete[j].t[i+1]=130+rand()%20;
					planete[j].t[i+2]=15+rand()%10;
					if(i<20*256*3|| i> 230*3*256) 
					{
						planete[j].t[i]+=5;
						planete[j].t[i+1]+=20;
						planete[j].t[i+2]+=70;
					}

				}else{//soleil
					planete[j].t[i]=200+rand()%50;
					planete[j].t[i+1]=180+rand()%50;
					planete[j].t[i+2]=15+rand()%10;
//				fwrite(&planete[j].t[i], 1, 1, f);
//				fwrite(&planete[j].t[i+1], 1, 1, f);
//				fwrite(&planete[j].t[i+2], 1, 1, f);
				}
			}
// création des cratères
	for(nb_crat=100;nb_crat>0&&j!=0;nb_crat--)
	{

		x_mil=rand()%255+1;
		y_mil=rand()%255+1;
		rapp=2*(128+y_mil)/256.0;
		if(y_mil>128) rapp=2*(128.0+256.0-y_mil)/256.0; 
		rayon_crat=rand()%20+4;
		for(theta=0;theta<(2*PI);theta+=0.1)
		{
			x=x_mil+rayon_crat*cos(theta);
			y=y_mil+(int)(rayon_crat*rapp*sin(theta));
			if(x>=256) x-=x_mil;
			if(y>=256) 
			{
				y=y_mil-(int)((rapp)*rayon_crat*sin(theta));
				x=256-x;
			}

			planete[j].t[(int)(x*3+y*256*3)]-=20;
			planete[j].t[(int)(x*3+y*256*3)+1]-=20;
			//planete[j].t[(int)(x*3+y*256*3)+2]-=20;
		}
	}
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D,j);                                    //on travail sur la texture portant le numéro du selector
			glTexImage2D(GL_TEXTURE_2D, 0,3, lar,lar, 0, GL_RGB, GL_UNSIGNED_BYTE, planete[j].t);
			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);          //on utilise l'application linéaire
			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);          //de prés et de loin
			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );             //si on sort du carré [0,1]*[0,1] qui représente
			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );             //la texture, on la répéte le point (-1.7,2.8) équivaut a (0.3,2.8)
			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY,1);
			glDisable(GL_TEXTURE_2D);

		}
//     fclose(f);
		//terre

     f = fopen("textures/earth3.raw", "rb");
     if (f){
          fread(planete[1].t, 256*256*3, 1, f);
          fclose(f);
          }
     glEnable(GL_TEXTURE_2D);
     glBindTexture(GL_TEXTURE_2D,1);                                    //on travail sur la texture portant le numéro du selector
     glTexImage2D(GL_TEXTURE_2D, 0,3, 256,256, 0, GL_RGB, GL_UNSIGNED_BYTE, planete[1].t);
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);          //on utilise l'application linéaire
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);          //de prés et de loin
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );             //si on sort du carré [0,1]*[0,1] qui représente
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );             //la texture, on la répéte le point (-1.7,2.8) équivaut a (0.3,2.8)
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY,1);
	glDisable(GL_TEXTURE_2D);
/*

     f = fopen("ciel.raw", "rb");
     if (f){
          fread(t, lar*lar*3, 1, f);
          fclose(f);
          }
			for(i=3;i<256*256*3;i+=3)
			{
				if(rand()%50)
				{
					t[i]=t[0];
					t[i+1]=t[1];
					t[i+2]=t[2];
				}else{
					t[i]=255;
					t[i+1]=255;
					t[i+2]=255;

				}
	
			}
     glEnable(GL_TEXTURE_2D);
     glBindTexture(GL_TEXTURE_2D,MAXPLANETE);                                    //on travail sur la texture portant le numéro du selector
     glTexImage2D(GL_TEXTURE_2D, 0,3, lar,lar, 0, GL_RGB, GL_UNSIGNED_BYTE, t);
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);          //on utilise l'application linéaire
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);          //de prés et de loin
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );             //si on sort du carré [0,1]*[0,1] qui représente
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );             //la texture, on la répéte le point (-1.7,2.8) équivaut a (0.3,2.8)
  //   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY,1);
	glDisable(GL_TEXTURE_2D);
*/



  glutMainLoop();

}
//***************************************************************************

void addPlanete(void)
{
//	glui3->show();
}

 Conclusion

Pour les bugs et autres améliorations,
l'exécutable et le zip , tout est sur le
http://www.webfractales.com/rapport.php
MiTcH - Julien Michot


 Historique

09 août 2004 15:50:20 :
pb d'affichage avec cppfrance (le retour à la ligne)
06 février 2005 11:56:36 :
23 septembre 2005 20:39:22 :
correction de bugs
26 décembre 2005 10:48:09 :
popotte

 Sources du même auteur

Source avec une capture FRACTAL
Source avec Zip Source avec une capture DOSCARD (LECTEUR DE CARTE À PUCE)
Source avec Zip Source avec une capture ---- PACMAN ----
Source avec Zip Source avec une capture FRACTALEDOS

 Sources de la même categorie

Source avec Zip Source avec une capture LEÇON MDL HALF-LIFE OPENGL VISUAL C++ par bobby03
Source avec Zip Source avec une capture SCREENSAVER OPENGL DEV C++ par bobby03
Source avec Zip Source avec une capture LEÇON 13 NEHE EN FRANÇAIS OPENGL DEV C++ par bobby03
Source avec Zip JEU DE DAMES 3D par vbclaude
Source avec Zip CHARGEMENT DES TEXTURES EN OPENGL par Jackyzgood

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture LEÇON MDL HALF-LIFE OPENGL VISUAL C++ par bobby03
Source avec Zip Source avec une capture SCREENSAVER OPENGL DEV C++ par bobby03
Source avec Zip Source avec une capture LEÇON 13 NEHE EN FRANÇAIS OPENGL DEV C++ par bobby03
Source avec Zip Source avec une capture MOTEUR 3D : CASTOR3D par dragonjoker59
Source avec Zip JEU DE DAMES 3D par vbclaude

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

system coordonne opengl/glut [ par gimli123 ] Salut tout le monde je suis en train de faire un petit jeu(tout du moins j'essai) et donc pour le menu je fais des boutons. Mais lorsque j'essai de fa C++ et Excel ? Affichage de Graphes ? [ par bubbless ] Bonjour &#224; tous !Je r&#233;alise actuellement un logiciel dans lequel je souhaiterais faire apparaitre des statistiques... Et pour cel&#224;, le p Opengl glut debutant menu graphique [ par gravel ] Bonjour, j'aimerais savoir comment on fais en opengl/glut pour faire afichier un image fixe. Je veux dire que si j'ai un screen en 800x600 et que j'm' Eclairage en OpenGL ? IMPORTANT ! [ par bubbless ] Bonjour &#224; tous ! Je r&#233;alise actuellement un programme avec une interface en OpenGL, et, j'ai un probl&#232;me ! Je voudrais mettre des image Fond d'écran en OpenGl (entre autres...) [ par bubbless ] Bonjour &#224; tous ! Je r&#233;alise actuellement un programme avec une interface en OpenGL, et, j'ai un probl&#232;me ! Je voudrais mettre des image QT OpenGL FPS [ par xabila ] bonjour, voil&#224; j'ai pass&#233; un de mes codes glut OpenGL sous QT et en fait je n'arrive pass &#224; convetir mon calcule des fps qui &#233;tai Nommer les axes en opengl [ par klidou ] est ce possible d'inserer une zone texte dans un espace opengl?(pour nommer les axes de coordonnees x,y).merci pour vos reponses. Transparence en OpenGL [ par yayayvon ] Bonjour,J'arrive &#224; afficher des objets&nbsp;textur&#233;s transparents (utilisation du blending et gldepthMask), mais seulement en les affichant Problème de Transparence Opengl [ par yayayvon ] Bonjour,J'arrive &#224; afficher des objets&nbsp;textur&#233;s transparents (utilisation du blending et gldepthMask), mais seulement en les affichant problème police openGl [ par vodkapomme43 ] Bonjour,J'utilise le code suivant pour cr&#233;er une police avec OPenGL:GLvoid BuildFont(GLvoid)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Bu


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mars 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,186 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales