g0rush

12-11-2016, 07:01 PM

I'm trying to make a very, very simple scene in openGL. I'm stuck at a very basic point. I'm attempting to make the wheels of a toy car rotate on its axis. The highlighted portion does not behave like it should after translation. Basically I want it to behave like a wheel but i cannot find the correct coordinates for rotation. I have the following:

void display() {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

eyeX = .5 + radius*cos(phi)*sin(theta);

eyeY = .5 + radius*sin(phi)*sin(theta);

eyeZ = .5 + radius*cos(theta);

//assuming modelview matrix mode is set

gluLookAt(eyeX, eyeY, eyeZ, 0, 0, 0, 0.0, 1.0, 0.0);

//rest of stuff ...

glPushMatrix();

glPushMatrix();

glScalef(2, .5, 1);

glutSolidCube(.5);

glPopMatrix();

glPushMatrix();

glPushMatrix();

glRotated(t, -.4, -.2, .30);

glTranslatef(-.4, -.2, .30);

glutSolidTorus(.06, .12, 8, 8);

glPopMatrix();

glPushMatrix();

glTranslatef(.7, 0, 0);

glTranslatef(-.4, -.2, .30);

glutSolidTorus(.06, .12, 8, 8);

glPopMatrix();

glPopMatrix();

glPopMatrix();

glutSwapBuffers();

}

void idle(void){

if (t >= 360) axis = (axis + 1) % 4;

t = (t < 360) ? t + dt : dt;

glutPostRedisplay();

}

void display() {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

eyeX = .5 + radius*cos(phi)*sin(theta);

eyeY = .5 + radius*sin(phi)*sin(theta);

eyeZ = .5 + radius*cos(theta);

//assuming modelview matrix mode is set

gluLookAt(eyeX, eyeY, eyeZ, 0, 0, 0, 0.0, 1.0, 0.0);

//rest of stuff ...

glPushMatrix();

glPushMatrix();

glScalef(2, .5, 1);

glutSolidCube(.5);

glPopMatrix();

glPushMatrix();

glPushMatrix();

glRotated(t, -.4, -.2, .30);

glTranslatef(-.4, -.2, .30);

glutSolidTorus(.06, .12, 8, 8);

glPopMatrix();

glPushMatrix();

glTranslatef(.7, 0, 0);

glTranslatef(-.4, -.2, .30);

glutSolidTorus(.06, .12, 8, 8);

glPopMatrix();

glPopMatrix();

glPopMatrix();

glutSwapBuffers();

}

void idle(void){

if (t >= 360) axis = (axis + 1) % 4;

t = (t < 360) ? t + dt : dt;

glutPostRedisplay();

}