Pyramide de parallélogramme en OpenGL

princesslou Messages postés 2 Date d'inscription lundi 12 novembre 2007 Statut Membre Dernière intervention 7 décembre 2007 - 6 déc. 2007 à 23:18
cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 - 7 déc. 2007 à 21:33
Bonjour,

je suis en train d'essayer de faire une pyramide de polygones.... en gros je suis partie d'un cube et je voudrais les empiler en faisant une boucle genre 'for (i = 4 ; i > 0 ; i=-0.5){}'
Grace à celle-ci je voudrais agir sur :
GLfloat vertices[][3] = { {-x,y,-z}, {x,y,-z}, {x,y+1.0,-z}, {-x,y+1.0,-z}, {-x,y,z}, {x,y,z}, {x,y+1.0,z}, {-x,y+1.0,z} };

Voilà mon problème est exposé!

Donc voilà mon code pour le moment sans la boucle ...

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <GL/glut.h>

// Vertices of the cube, centered at the origin.
GLfloat vertices[][3] = { {-1.0,0.0,-1.0}, {1.0,0.0,-1.0}, {1.0,1.0,-1.0},
    {-1.0,1.0,-1.0}, {-1.0,0.0,1.0}, {1.0,0.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0} };
   
//GLfloat vertices[][3] = { {-x,y,-z}, {x,y,-z}, {x,y+1.0,-z},
//{-x,y+1.0,-z}, {-x,y,z}, {x,y,z}, {x,y+1.0,z}, {-x,y+1.0,z} };
   
// Colors of the vertices.
GLfloat colors[][3] = { {0.0,0.0,0.0}, {0.7529,0.7529,0.7529}, {0.0,0.0,0.0}, {0.5020,0.5020,0.4118},
{0.0,0.0,0.0}, {0.5020,0.5020,0.4118}, {0.0,0.0,0.0}, {0.7529,0.7529,0.7529} };

// Indices of the vertices to make up the six faces of the cube.
GLubyte cubeIndices[24] = {0,3,2,1,  //Face 0
                           2,3,7,6,  //Face 1
                           0,4,7,3,  //Face 2
                           1,2,6,5,  //Face 3
                           4,5,6,7,  //Face 4
                           0,1,5,4}; //Face 5

// Angles of rotation.

GLfloat theta[] = {0.0, 0.0, 0.0};

// Current axis of rotation.
GLint axis = 1;

int spinning = 0;
void colorcube(void);
void display(void);
void spinCube(void);
void keyFunc (unsigned char key, int x, int y);

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(700, 700);
    glutInitWindowPosition(150, 50);
    glutCreateWindow("Rotating");
    glutDisplayFunc(display);
    glutIdleFunc(spinCube);
    glutKeyboardFunc(keyFunc);
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_FLAT);
    colorcube();
    glutMainLoop();
    return 0;
}

// This function sets up the vertex arrays for the color cube and the projection matrix.
void colorcube(void)
{
    glEnableClientState (GL_COLOR_ARRAY);
    glEnableClientState (GL_VERTEX_ARRAY);
    glVertexPointer (3, GL_FLOAT, 0, vertices);
    glColorPointer (3, GL_FLOAT, 0, colors);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0);
    glClearColor (1.0, 1.0, 1.0, 0.0); /* Make the background white. */
}

// This is the display callback function.
void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glRotatef(theta[1], 0.0, 1.0, 0.0);
    glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, cubeIndices);
    glutSwapBuffers();
}

// This function spins the cube around the current axis by incrementing the angle of
// rotation by X degrees with X is like the acceleration when it turn.
void spinCube(void)
{
    if (spinning)
    {
       theta[axis] += 2.0;
       if( theta[axis] > 360.0 ) theta[axis] -= 360.0;
       glutPostRedisplay();
    }
}

// This is the keyboard callback function. It starts-stops spinning and quit the program.
void keyFunc (unsigned char key, int x, int y)
{    if (key 's') spinning !spinning;
    else if (key == 'q') exit(0);
}

ET DONC je voulais créer une fonction genre :

void drawPyr(GLenum mode){
   glNewList (1, GL_COMPILE_AND_EXECUTE);
      glBegin (GL_POLYGON);    
         GLfloat i, x, y, z;  
         for (i =4; i>1; i=-0.5)
         {
             GLfloat vertices[][3] = { {-x,y,-z}, {x,y,-z}, {x,y+1.0,-z},
             {-x,y+1.0,-z}, {-x,y,z}, {x,y,z}, {x,y+1.0,z}, {-x,y+1.0,z} };
         }
      glEnd();
   glEndList();
}

MAIS</gras> première chose je ne sais pas pourquoi je rentre pas dans la boucle, ni comment je dois réellement noter 'GLfloat vertices[][3] = ...' et enfin si je dois chaque fois rappeler mon 'colors[][]
' et mon 'cubeIndice[][]'.

Hum voilà... si quelqu'un a une idée
Merciiiii

4 réponses

WhiteHippo Messages postés 1154 Date d'inscription samedi 14 août 2004 Statut Membre Dernière intervention 5 avril 2012 3
7 déc. 2007 à 20:45
Bonsoir

"for (i=4; i>1; i=-0.5)" : Attention "i=-0.5"correspond à une affectation de -0.5 à la variable i.
Il faudrait plutôt écrire "for (i=4; i>1; i-=0.5)" pour décrementer la variable.

Cordialement.
<hr />"L'imagination est plus importante que le savoir." Albert Einstein
0
princesslou Messages postés 2 Date d'inscription lundi 12 novembre 2007 Statut Membre Dernière intervention 7 décembre 2007
7 déc. 2007 à 21:05
Merci pour le i!!
Euh par contre jai rien compris au site :s donc jsais pas du tout où on choisit de poster...
Comment on fait???
Mci
0
WhiteHippo Messages postés 1154 Date d'inscription samedi 14 août 2004 Statut Membre Dernière intervention 5 avril 2012 3
7 déc. 2007 à 21:19
Tu vas sur le site concerné http://www.cppfrance.com/ et tu postes à partir de là bas.

P.S. Merci de valider "réponse acceptée", si ton problème a été solutionné, cela indiquera aux autres membres que ce post est désormais clos.
 
Cordialement.
<hr />"L'imagination est plus importante que le savoir." Albert Einstein
0
cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 61
7 déc. 2007 à 21:33
Déplacé sur cppfrance










<hr />
-My Blog-
0
Rejoignez-nous