PDA

View Full Version : My triangles stop rotating



thebigbo
08-31-2014, 01:19 AM
Hi there! I need your help as a beginner.

My whole scene should be rotating around the Z axis when I left-click on it and move the mouse. Instead, only the reference triangle (ref) rotates and the triangles from triArray[] stay still. But when I comment out the part for drawing the bounding sphere and run the app, all the triangles start to rotate again. What could be causing this? Below you can check my code:


void Display() {
//...

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

gluLookAt(3,0,2,0,0,0.1,0,0,1);

glScalef(zoom,zoom,zoom);
glRotatef(angleZ,0,0,1);

// we draw the ref triangle, its plane and its bounding sphere
OpenGLDrawTri(ref,BLUE,"");

// we draw all the triangles in the array
for(i=0;i<numTriangles;i++)
OpenGLDrawTri(triArray[i],c,str);


// force display
glFlush();
}

void OpenGLDrawTri(triangle_t t, color_t c, char* str) {
//...

glBegin(GL_TRIANGLES);
glColor3ub(c.R, c.G, c.B);
glVertex3d(t.p1.x, t.p1.y, t.p1.z);
glVertex3d(t.p2.x, t.p2.y, t.p2.z);
glVertex3d(t.p3.x, t.p3.y, t.p3.z);
glEnd();

//must comment the below code
CreateBoundSphere(&t);
glColor3ub(c.R, c.G, c.B);
glPushMatrix();
glTranslatef(t.center.x, t.center.y, t.center.z);
glutWireSphere(t.rad, 16, 16);
glPopMatrix();
}

Yandersen
08-31-2014, 05:01 AM
Seems strange... Maybe try to change the order of some lines here:

glPushMatrix();
glTranslatef(t.center.x, t.center.y, t.center.z);
CreateBoundSphere(&t);
glColor3ub(c.R, c.G, c.B);
glutWireSphere(t.rad, 16, 16);
glPopMatrix();

It shouldn't matter though, but there are no mistakes I see that could cause the modelview matrix to be set to identity (as the problem seem to be so as I understand it). What is the code of CreateBoundSphere(...) function look like?