I am having problem rotating a cube along its own axis and not some arbitrary position. The cube is a collection of other 27 cubes and I have succesfully managed to rotate the group of cubes but not in correct way. I mean when I rotated the cube in x-axis, it makes an orbit around the enter (0,0,0) and not in its own axis. How can i make the cube rotate about its own axis?
public void onDrawFrame(GL10 gl)
{
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glScalef(0.8f, 0.8f, 0.8f);
int k=0;
gl.glPushMatrix();
gl.glRotatef(cubeRotX, 0.0f, 0.0f , 1.0f);
gl.glRotatef(cubeRotY, 0.0f, 1.0f , 0.0f);
for(int l=0; l<3; l++)
{
if(l == 2) //To rotate only the first front polygon in 1.7f angle
{
gl.glPushMatrix();
gl.glRotatef(rot, 0.0f, 0.0f, 1.0f);
}
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
gl.glPushMatrix();
gl.glTranslatef(-2.1f+(2.1f*i), -2.1f+(2.1f*j), -23.1f+(2.1f*l));
cube[k++].draw(gl);
gl.glPopMatrix();
}
}
if(l ==2)
{
gl.glPopMatrix();
if(rot >= 90.0f)
rot = 90.0f;
else
rot += 4.0f;
}
}
gl.glPopMatrix();
cubeRotX -= 5.0f;
cubeRotY -= 5.0f;
}