Im working on a 3D platformer where theres a large platform and a character made up of multiple cubes.
However when I try rotating the Y axis of the characters cubes it doesn't rotate them at their centerpoint. They just orbit as a whole around the platform in a huge circle. I'm guessing my glRotatef
's are in the wrong order but I cant seem to figure out what order they should be to make the group of cubes rotate only around their center point.
My code for drawing them is:
for (int i = 0; i < Models.size(); i++){ // theres only one model this has to go through that stores the group of cubes for the character
glPushMatrix(); // set rotation for the whole group (I would expect...)
glRotatef(Models.at(i)->ModelRotation.X,1,0,0);
glRotatef(Models.at(i)->ModelRotation.Y,0,1,0);
glRotatef(Models.at(i)->ModelRotation.Z,0,0,1);
for (int j = 0; j < Models.at(i)->Parts.size(); j++) // For each cube in the character,
Models.at(i)->Parts.at(j)->Render(); // draw the cube
glPopMatrix();
}
Model is a struct that just has a vector3 called "ModelRotation" and a normal vector called "Parts" which stores all the cubes for the character.
My function for rendering the cube in the cube class is:
void Render(){
glPushMatrix();
glTranslatef( Position.X,
Position.Y,
Position.Z
);
glColor3f( Color.R,
Color.G,
Color.B
);
glScalef( Size.X,
Size.Y,
Size.Z
);
// Render the front quad
//glBindTexture(GL_TEXTURE_2D, Faces[0]);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f( 1.0f, -1.0f, -1.0f );
glTexCoord2f(1, 0); glVertex3f( -1.0f, -1.0f, -1.0f );
glTexCoord2f(1, 1); glVertex3f( -1.0f, 1.0f, -1.0f );
glTexCoord2f(0, 1); glVertex3f( 1.0f, 1.0f, -1.0f );
glEnd();
// Render the left quad
//glBindTexture(GL_TEXTURE_2D, Faces[1]);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f( 1.0f, -1.0f, 1.0f );
glTexCoord2f(1, 0); glVertex3f( 1.0f, -1.0f, -1.0f );
glTexCoord2f(1, 1); glVertex3f( 1.0f, 1.0f, -1.0f );
glTexCoord2f(0, 1); glVertex3f( 1.0f, 1.0f, 1.0f );
glEnd();
// Render the back quad
//glBindTexture(GL_TEXTURE_2D, Faces[2]);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f( -1.0f, -1.0f, 1.0f );
glTexCoord2f(1, 0); glVertex3f( 1.0f, -1.0f, 1.0f );
glTexCoord2f(1, 1); glVertex3f( 1.0f, 1.0f, 1.0f );
glTexCoord2f(0, 1); glVertex3f( -1.0f, 1.0f, 1.0f );
glEnd();
// Render the right quad
//glBindTexture(GL_TEXTURE_2D, Faces[3]);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f( -1.0f, -1.0f, -1.0f );
glTexCoord2f(1, 0); glVertex3f( -1.0f, -1.0f, 1.0f );
glTexCoord2f(1, 1); glVertex3f( -1.0f, 1.0f, 1.0f );
glTexCoord2f(0, 1); glVertex3f( -1.0f, 1.0f, -1.0f );
glEnd();
// Render the top quad
//glBindTexture(GL_TEXTURE_2D, Faces[4]);
glBegin(GL_QUADS);
glTexCoord2f(0, 1); glVertex3f( -1.0f, 1.0f, -1.0f );
glTexCoord2f(0, 0); glVertex3f( -1.0f, 1.0f, 1.0f );
glTexCoord2f(1, 0); glVertex3f( 1.0f, 1.0f, 1.0f );
glTexCoord2f(1, 1); glVertex3f( 1.0f, 1.0f, -1.0f );
glEnd();
// Render the bottom quad
//glBindTexture(GL_TEXTURE_2D, Faces[5]);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f( -1.0f, -1.0f, -1.0f );
glTexCoord2f(0, 1); glVertex3f( -1.0f, -1.0f, 1.0f );
glTexCoord2f(1, 1); glVertex3f( 1.0f, -1.0f, 1.0f );
glTexCoord2f(1, 0); glVertex3f( 1.0f, -1.0f, -1.0f );
glEnd();
glPopMatrix();
};
Any help would be very much appreciated. I'm guessing it's just a simple mistake I can't put together. I'll show more code if it's needed.