Hi there,
I have this cube which i rotate around a centre, I'm attempting to make it register when i move a sphere beyond it's x,y,z position.
However the cubes x,y,z position seems to be it's origin of rotation and not it's actual current position.
I believe this is because i translate & rotate to give the impression of rotation. But am unsure if i can change this without reworking the code.
Here is my code or the rotating cube.
void bat (void) {
glPushMatrix();
glColor3f(1.0,1.0,1.0);
//glTranslatef(0.0,0.0,0.0);
if (Rotateleft == TRUE) //left arrow pressed rotate left.
{
glRotated((GLdouble)spin, batX,batY,batZ+=1.0);
glTranslatef(batX+10,0.0,0.0);
spin+=1;
if (spin>360.0)
spin=spin-360.0;
}
if (Rotateleft == FALSE && Rotateright == FALSE) //left and right arrow not pressed, do nothing.
{
glRotated((GLdouble)spin, batX,batY,batZ);
glTranslatef(batX+10,0.0,0.0);
}
if (Rotateright == TRUE) //right arrow pressed, rotate right
{
glRotated((GLdouble)spin, batX,batY,batZ+=1.0);
glTranslatef(batX+10,0.0,0.0);
spin-=1;
if (spin<1)
spin=spin+360;
}
glBegin(GL_QUADS); //begin the four sided shape
glVertex3f (...) //Creation of cube here
glEnd();
glPopMatrix();
}
Heres the code for a simple test i'm trying to do with the sphere.
void collision(void)
{
if (ballX < batX)
{
glDisable(GL_LIGHTING);
}
else
{
glEnable(GL_LIGHTING);
}
}
Help on this matter would be appreciated.
Thanks!