Hey guys, I'm new here. I'm trying to rotate a cube that is selected around it's local origin, 180 degrees so that the bottom face is on top. i want the cube's position to remain the same (rotation in place) so to speak. I've tried several different things, but i can't seem to figure this out.
any help would be greatly appreciated!
below is my draw scene code:
glRotatef(rotateX, 1, 0, 0); //Mouse rotation around X-Axis
glRotatef(rotateY, 0, 1, 0); //Mouse rotation around Y-Axis
int numDraw = 0;
if (iGame->started) {
for ( vector<Match *>::iterator it = Match::matches.begin(); it != Match::matches.end(); it++) {
if (numDraw < iGame->iLevel)
{
(*it)->drawMatch();
numDraw++;
}
}
}
this is my draw cube code:
void Match::drawMatch(void)
{
if (!visible) return;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (!texture)
glDisable(GL_TEXTURE_2D);
if (!selected)
glColor3f(1.0f, 1.0f, 1.0f);
else
glColor3f(0.2f, 0.1f, 1.0f);
glBindTexture(GL_TEXTURE_2D, texture->texID);
if (selected)
{
glPushMatrix();
glTranslatef( 0.0, h * 3, 0); //not sure why but h * 3 seems to put the square at the right height
glRotatef(180, 0, 0, 1);
}
glPushName( (int)this);
glNormal3f(0, -1, 0);
glBegin(GL_QUADS);
//top face
glTexCoord2f(1, 1);
glVertex3d( x + w, y + h, z );
glTexCoord2f(1, 0);
glVertex3d( x + w, y + h, z + w);
glTexCoord2f(0, 0);
glVertex3d( x, y + h, z + w);
glTexCoord2f(0, 1);
glVertex3d( x, y + h, z);
glEnd();
glBindTexture(GL_TEXTURE_2D, baseText->texID);
glBegin(GL_QUADS);
//front face
glTexCoord2f(1, 1);
glVertex3d( x + w, y, z + w);
glTexCoord2f(1, 0);
glVertex3d( x, y, z + w);
glTexCoord2f(0, 0);
glVertex3d( x, y + h, z + w);
glTexCoord2f(0, 1);
glVertex3d( x + w, y + h, z + w);
//botttom face
glTexCoord2f(1, 1);
glVertex3d( x + w, y, z );
glTexCoord2f(1, 0);
glVertex3d( x + w, y, z + w);
glTexCoord2f(0, 0);
glVertex3d( x, y, z + w);
glTexCoord2f(0, 1);
glVertex3d( x, y, z);
//right face
glTexCoord2f(0, 1);
glVertex3d( x + w, y + h, z );
glTexCoord2f(1, 1);
glVertex3d( x + w, y, z);
glTexCoord2f(1, 0);
glVertex3d( x + w, y, z + w);
glTexCoord2f(0, 0);
glVertex3d( x + w, y + h, z + w);
//left face
glTexCoord2f(0, 1);
glVertex3d( x, y + h, z );
glTexCoord2f(1, 1);
glVertex3d( x, y, z);
glTexCoord2f(1, 0);
glVertex3d( x, y, z + w);
glTexCoord2f(0, 0);
glVertex3d( x, y + h, z + w);
glEnd();
glPopName();
if (selected) {
glPopMatrix();
}
}
this is how the cube's x,y,z positions are set
void Match::updatePositions(void) {
int level = iGame->iLevel; //iGame->iLevel can be 16, 36 or 64 (16 = 8x8 squares, etc.)
int sqrtLvl = sqrt((double)level);
int xoffset = -((sqrtLvl * w + offsetX) / 2);
int zoffset = -((sqrtLvl * w + offsetZ) / 2);
int x = 0;
for (int i = 0; i < level; i++) {
Match::matches->setPos(xoffset, h, zoffset);
Match::matches->setVisible(true);
Match::matches->setSelected(false);
xoffset += w + offsetX;
x++;
if (x == sqrtLvl) {
xoffset = -((sqrtLvl * w + offsetX / 2) / 2);
zoffset += h + offsetZ;
x = 0;
}
}
}
notice how the blue cube is on the opposite side of where the "Hole" is plus an offset.
[Edited by - SilentSounD on September 25, 2007 3:24:47 AM]