Ho il seguente problema.
Devo disegnare un cubo sospeso in aria che ruota su se stesso.
Se lo disegno in questo modo, inserendo le seguenti righe nella mia funzione di disegno:
codice:
...
rotazione+=0.05;
glPushMatrix();
glColor3f(0.0f, 0.0f, 1.0f);
glTranslatef(posizioneCuboRotante[X], posizioneCuboRotante[Y], posizioneCuboRotante[Z]);
glRotatef(rotazione, 0, 1, 1);
glutSolidCube(0.5);
glPopMatrix();
...
va tutto bene.
Mentre se lo disegno in quest'altro modo:
codice:
...
rotazione+=0.05;
disegnaCuboRotante(posizioneCuboRotante[X], posizioneCuboRotante[Y], posizioneCuboRotante[Z]);
...
dove la funzione disegnaCuboRotante è la seguente:
codice:
void disegnaCuboRotante(GLfloat x, GLfloat y, GLfloat z)
{
GLfloat dim=pavimento.cell_size/2;
GLfloat x1=x-dim;
GLfloat y1=y+dim;
GLfloat x2=x+dim;
GLfloat y2=y+dim;
GLfloat x3=x+dim;
GLfloat y3=y-dim;
GLfloat x4=x-dim;
GLfloat y4=y-dim;
glPushMatrix();
glRotatef(rotazione, 0.0f, 0.0f, 1.0f);
glColor3f(1,0,0);
glNormal3f(0.0, 0.0, 1.0);
//SOTTO
glBegin(GL_QUADS);
glVertex3f(x1, y1, z);
glVertex3f(x2, y2, z);
glVertex3f(x3, y3, z);
glVertex3f(x4, y4, z);
glEnd();
//DI FRONTE
glBegin(GL_QUADS);
glVertex3f(x1, y1, z);
glVertex3f(x1, y1, z+1);
glVertex3f(x2, y2, z+1);
glVertex3f(x2, y2, z);
glEnd();
//DIETRO
glBegin(GL_QUADS);
glVertex3f(x4, y4, z);
glVertex3f(x4, y4, z+1);
glVertex3f(x3, y3, z+1);
glVertex3f(x3, y3, z);
glEnd();
//SINISTRA
glBegin(GL_QUADS);
glVertex3f(x1, y1, z);
glVertex3f(x1, y1, z+1);
glVertex3f(x4, y4, z+1);
glVertex3f(x4, y4, z);
glEnd();
//DESTRA
glBegin(GL_QUADS);
glVertex3f(x2, y2, z);
glVertex3f(x2, y2, z+1);
glVertex3f(x3, y3, z+1);
glVertex3f(x3, y3, z);
glEnd();
//SOPRA
glBegin(GL_QUADS);
glVertex3f(x1, y1, z+1);
glVertex3f(x2, y2, z+1);
glVertex3f(x3, y3, z+1);
glVertex3f(x4, y4, z+1);
glEnd();
glPopMatrix();
}
mi succede che il cubo si sposta e se ne va.
Come potrei risolvere questo problema?