begin process at 2012 02 09 07:28:15
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

OpenGL

 > ANIMATION D'UN CERCLE AVEC TOUCHES + FILM[2D][DEVC++4][GLUT]

ANIMATION D'UN CERCLE AVEC TOUCHES + FILM[2D][DEVC++4][GLUT]


 Information sur la source

Note :
Aucune note
Catégorie :OpenGL Niveau :Débutant Date de création :30/12/2002 Date de mise à jour :30/12/2002 20:21:32 Vu / téléchargé :5 141 / 212

Auteur : mastave

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

 Description

haut: o
bas : l
gauche : k
droite : m

agrandir : h
rétrécir : b

Quitter : q
Animer : c

Fait par Matthias RENAULT avec Dev C++4
matthias.renault@voila.fr
Nécessite GLUT
Glut.dll fourni

Source

  • //Les librairies
  • #include <gl/glut.h>
  • #include <math.h>
  • //on déclare les procédures
  • void display(void);
  • void init(void);
  • void film();
  • void indispensable();
  • //on déclare la fonction pour le cercle
  • void cercles(int x, int y, int rayon2);
  • //On déclare les variables
  • bool choix = false; //boolenne
  • int rayon[100];
  • int xa[100]; //entière avec tableau : la 1ere "case" de xa vaut 50
  • int ya[100];
  • int i = 1; //i détermine combien de fois on a appuyé sur une touche
  • float linex = 0.5; //à virgule flottante
  • float liney = 0.5;
  • float theta = 0.0f;
  • void display (void)
  • {
  • glClear(GL_COLOR_BUFFER_BIT);
  • if (!choix)
  • {
  • glBegin(GL_LINES);
  • glColor3f (1.0, 0.0, 0.0);
  • glVertex2f (linex - 0.01, liney);
  • glVertex2f (linex + 0.01, liney);
  • glVertex2f (linex, liney + 0.01);
  • glVertex2f (linex, liney - 0.01);
  • glEnd();
  • cercles (xa[i], ya[i], rayon[i]); //on trace le cercle
  • }
  • if (choix == true)
  • {
  • cercles (xa[i], ya[i], rayon[i]); //on trace le cercle
  • }
  • glFlush();
  • //On a deja fait le cercle
  • choix = true;
  • }
  • //Toute la gestion alphanumérique
  • void keyboard(unsigned char key, int x, int y)
  • {
  • switch (key)
  • {
  • case 'q': //quitter
  • exit(0);
  • break;
  • case 'h': //cercle + grand
  • rayon[i]++;
  • indispensable();
  • glutPostRedisplay();
  • break;
  • case 'b': //cercle + petit
  • rayon[i]--;
  • indispensable();
  • glutPostRedisplay();
  • break;
  • case 'o': //on monte
  • ya[i]--;
  • indispensable();
  • glutPostRedisplay();
  • break;
  • //on descend
  • case 'l':
  • ya[i]++;
  • indispensable();
  • glutPostRedisplay();
  • break;
  • case 'k': //à gauche
  • xa[i]--;
  • indispensable();
  • glutPostRedisplay();
  • break;
  • case 'm': //à droite...
  • xa[i]++;
  • indispensable();
  • glutPostRedisplay();
  • break;
  • //on lance le "film"!
  • case 'c':
  • film();
  • break;
  • default: //si rien, on retourne au début!
  • break;
  • }
  • }
  • void film()
  • {
  • int a; //le compteur
  • for (a = 1; a <= i; a++)
  • {
  • glClear(GL_COLOR_BUFFER_BIT);
  • cercles (xa[a], ya[a], rayon[a]);
  • }
  • }
  • void indispensable()
  • {
  • xa[i+1] = xa[i];
  • ya[i+1] = ya[i];
  • rayon[i+1] = rayon[i];
  • i++;
  • }
  • //initiation perso...
  • void init(void)
  • {
  • //on initialise les variables
  • rayon[1] = 10;
  • xa[1] = 50;
  • ya[1] = 50;
  • glClearColor(0.0, 0.0, 0.0, 0.0);
  • glMatrixMode(GL_PROJECTION);
  • glLoadIdentity();
  • glOrtho(0, 100, 100, 0, -100, 100);
  • }
  • //Histoire d'initier...
  • int main (int argc, char** argv)
  • {
  • glutInit(&argc, argv);
  • glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  • glutInitWindowSize(600,600);
  • glutInitWindowPosition(100, 100);
  • glutCreateWindow("Cercles");
  • init();
  • glutDisplayFunc(display);
  • glutKeyboardFunc(keyboard);
  • glutMainLoop();
  • return 0;
  • }
  • //La fonction du cercle KITU!!!
  • void cercles (int x, int y, int rayon2)
  • {
  • int theta = 0;
  • glBegin(GL_POINTS);
  • while (theta <= 360)
  • {
  • glVertex2f (x + rayon2 * (cos(theta)), y + rayon2 * (sin(theta))); //la fonction du cercle
  • theta++;
  • }
  • glEnd();
  • }
//Les librairies
#include <gl/glut.h>
#include <math.h>

//on déclare les procédures
void display(void);
void init(void);
void film();
void indispensable();

//on déclare la fonction pour le cercle
void cercles(int x, int y, int rayon2);

//On déclare les variables
bool choix = false;                //boolenne

int rayon[100];
int xa[100];                    //entière avec tableau : la 1ere "case" de xa vaut 50
int ya[100];

int i = 1;                   //i détermine combien de fois on a appuyé sur une touche

float linex = 0.5;                 //à virgule flottante
float liney = 0.5;
float theta = 0.0f;



void display (void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   if (!choix)
   {
     glBegin(GL_LINES);
     glColor3f (1.0, 0.0, 0.0);
     glVertex2f (linex - 0.01, liney);
     glVertex2f (linex + 0.01, liney);
     glVertex2f (linex, liney + 0.01);
     glVertex2f (linex, liney - 0.01);
     glEnd();
     cercles (xa[i], ya[i], rayon[i]);      //on trace le cercle
   }

   if (choix == true)
   {
     cercles (xa[i], ya[i], rayon[i]);      //on trace le cercle
   }
   glFlush();

   //On a deja fait le cercle
   choix = true;

}


//Toute la gestion alphanumérique
void keyboard(unsigned char key, int x, int y)
{
   switch (key)
   {

     case 'q':                            //quitter
     exit(0);
     break;

     case 'h':                            //cercle + grand
     rayon[i]++;
     indispensable();
     glutPostRedisplay();
     break;

     case 'b':                            //cercle + petit
     rayon[i]--;
     indispensable();
     glutPostRedisplay();
     break;

     case 'o':                            //on monte
     ya[i]--;
     indispensable();
     glutPostRedisplay();
     break;
                                         //on descend
     case 'l':
     ya[i]++;
     indispensable();
     glutPostRedisplay();
     break;

     case 'k':                           //à gauche
     xa[i]--;
     indispensable();
     glutPostRedisplay();
     break;

     case 'm':                           //à droite...
     xa[i]++;
     indispensable();
     glutPostRedisplay();
     break;
                                         //on lance le "film"!
     case 'c':
     film();
     break;

     default:                           //si rien, on retourne au début!
     break;
    }
}

void film()
{
  int a;       //le compteur
  for (a = 1; a <= i; a++)
  {
    glClear(GL_COLOR_BUFFER_BIT);
    cercles (xa[a], ya[a], rayon[a]);
  }
}

void indispensable()
{
  xa[i+1] = xa[i];
  ya[i+1] = ya[i];
  rayon[i+1] = rayon[i];
  i++;
}

//initiation perso...
void init(void)
{
   //on initialise les variables
   rayon[1] = 10;
   xa[1] = 50;
   ya[1] = 50;
   glClearColor(0.0, 0.0, 0.0, 0.0);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0, 100, 100, 0, -100, 100);
}

//Histoire d'initier...
int main (int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize(600,600);
   glutInitWindowPosition(100, 100);
   glutCreateWindow("Cercles");
   init();
   glutDisplayFunc(display);
   glutKeyboardFunc(keyboard);
   glutMainLoop();
   return 0;
}


//La fonction du cercle KITU!!!
void cercles (int x, int y, int rayon2)
{
   int theta = 0;
   glBegin(GL_POINTS);
   while (theta <= 360)
      {
        glVertex2f (x + rayon2 * (cos(theta)), y + rayon2 * (sin(theta)));        //la fonction du cercle
        theta++;
      }
      glEnd();
}


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip Source avec une capture .::MATRIX::. [DEV C++]
FONCTION MENU AVEC FLÈCHES EN MODE TEXTE[DEV C++]
Source avec Zip POLYGONES DIVERSES SANS GLUT[DEV C++...]
(-:FONCTION TABLEAU EN MODE TEXTE![DEV C++]
FONCTION RECTANGLE COULEUR EN MODE TEXTE[DEV C++]

 Sources de la même categorie

Source avec Zip Source avec une capture AFFICHER DES COURBES DE BEZIER par shorzy
Source avec Zip Source avec une capture BASE/MOTEUR 3D EN QT/OPENGL (COMPLET ET FONCTIONNEL!) POUR U... par envi33
Source avec Zip Source avec une capture CLASSE AVEC OPENGL - OBJETS 3D ET ANIMATIONS par rasta63
Source avec Zip Source avec une capture LETTRES 3D AVEC OPENGL ET QT par opossum_farceur
Source avec Zip CUBE 3D GLUT32 VC++ ET DEVC++ par bobby03

Commentaires et avis

Commentaire de cmarsc le 01/01/2003 14:13:20

papi new year 2003 ;-)

pour utiliser exit(0) il ne faudrait pas &lt;stdlib.h&gt; par hasard ?
si void film(); void indispensable(); n'ont pas d'arguments formels un petit void fera l'affaire.
et une valeur de retour void return ; int return (la valeur)
true et false sont-ls définis quelque part dans &lt;gl/glut.h&gt; ?

Commentaire de bobby03 le 19/08/2003 05:17:28

Je viens de recompiler avec Borland C++ 5.02 Très bon ça fonctionne parfaitement exepter pour FILM. Je regarderais plus tard

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
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 : 0,655 sec (3)

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