Goldfish

08-23-2012, 01:35 PM

Hi I'm having trouble with moving some parts of my Model individually.

http://www.bilder-upload.eu/thumb/953fb4-1345750356.png (http://www.bilder-upload.eu/show.php?file=953fb4-1345750356.png)

This shall represent a rubiks cube. And I want to rotate the sides individually. But if I try the whole cube rotates around the origin.

I tried to do it like that.

void drawCube(float size)

{

glPushMatrix();

for(int z = 0; z < cubesize; z++)

{

glPushMatrix();

glRotatef(angle,0,0,1);

for(int x = 0; x < cubesize; x++)

{

for(int y = 0; y < cubesize; y++)

{

float xPos = -(size+0.4)*cubesize/2+(size+0.4)*x;

float yPos = -(size+0.4)*cubesize/2+(size+0.4)*y;

float zPos = (size+0.4)*cubesize/2+(size+0.4)*-z;;

StoneFromCube(x,y,z, xPos,yPos,zPos, size);

}

}

glPopMatrix();

}

glPopMatrix();

}

The method StoneFromCube draws a single Stone of the cube.

I'm still a newbie and don't know how to solve problems like that would be great if anyone can help.

Thanks in advance^^

http://www.bilder-upload.eu/thumb/953fb4-1345750356.png (http://www.bilder-upload.eu/show.php?file=953fb4-1345750356.png)

This shall represent a rubiks cube. And I want to rotate the sides individually. But if I try the whole cube rotates around the origin.

I tried to do it like that.

void drawCube(float size)

{

glPushMatrix();

for(int z = 0; z < cubesize; z++)

{

glPushMatrix();

glRotatef(angle,0,0,1);

for(int x = 0; x < cubesize; x++)

{

for(int y = 0; y < cubesize; y++)

{

float xPos = -(size+0.4)*cubesize/2+(size+0.4)*x;

float yPos = -(size+0.4)*cubesize/2+(size+0.4)*y;

float zPos = (size+0.4)*cubesize/2+(size+0.4)*-z;;

StoneFromCube(x,y,z, xPos,yPos,zPos, size);

}

}

glPopMatrix();

}

glPopMatrix();

}

The method StoneFromCube draws a single Stone of the cube.

I'm still a newbie and don't know how to solve problems like that would be great if anyone can help.

Thanks in advance^^