princesslou
Messages postés2Date d'inscriptionlundi 12 novembre 2007StatutMembreDernière intervention 7 décembre 2007
-
6 déc. 2007 à 23:18
cs_Bidou
Messages postés5487Date d'inscriptiondimanche 4 août 2002StatutMembreDernière intervention20 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 ...
// 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);
// 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[][]'.
WhiteHippo
Messages postés1154Date d'inscriptionsamedi 14 août 2004StatutMembreDernière intervention 5 avril 20123 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