Anyways, the desired effect I am looking for is the rectangle to spin according to m_orientation in two dimensions. It works fine when the rectangle is at position 0,0,0 but when I move the rectangle away from the origin (wasd keys move the rectangle) the rotation gets messed up. I think it has something to do with where my camera is, or I am not understanding where I need to move it. My draw function is this (it is called every frame):
Code: Select all
void Engine::draw(Rect * rectangle)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f, 0.0f, -8.0f); // Move everything 8 units into the screen
drawRectangle(rectangle, &rectangle->m_colors);
//drawSpriteOnRectangle(Vertex(100, 100, 0), Vertex(228, 100, 0), Vertex(228, 228, 0), Vertex(100, 228, 0));
}
Code: Select all
void Engine::drawRectangle(Rect * rectangle, vector<Vertex>* color_vector)
{
glPushMatrix();
glRotatef(rectangle->m_orientation, rectangle->getPosition()->x, rectangle->getPosition()->y, 1);
//m_RotationAngle += .1f; // increase rotation angle
rectangle->m_orientation += .1f;
if(rectangle->m_orientation > 360.0) //prevent from having an angle greater than a float value can store ^^
{
rectangle->m_orientation -= 360.0;
}
glBegin(GL_QUADS);
glColor3f(rectangle->m_colors[TOP_LEFT].x, rectangle->m_colors[TOP_LEFT].y,rectangle->m_colors[TOP_LEFT].z);
glVertex3f(rectangle->m_vertices[TOP_LEFT].x, rectangle->m_vertices[TOP_LEFT].y, rectangle->m_vertices[TOP_LEFT].z);
glColor3f(rectangle->m_colors[TOP_RIGHT].x, rectangle->m_colors[TOP_RIGHT].y,rectangle->m_colors[TOP_RIGHT].z);
glVertex3f(rectangle->m_vertices[TOP_RIGHT].x, rectangle->m_vertices[TOP_RIGHT].y, rectangle->m_vertices[TOP_RIGHT].z);
glColor3f(rectangle->m_colors[BOTTOM_RIGHT].x, rectangle->m_colors[BOTTOM_RIGHT].y,rectangle->m_colors[BOTTOM_RIGHT].z);
glVertex3f(rectangle->m_vertices[BOTTOM_RIGHT].x, rectangle->m_vertices[BOTTOM_RIGHT].y, rectangle->m_vertices[BOTTOM_RIGHT].z);
glColor3f(rectangle->m_colors[BOTTOM_LEFT].x, rectangle->m_colors[BOTTOM_LEFT].y,rectangle->m_colors[BOTTOM_LEFT].z);
glVertex3f(rectangle->m_vertices[BOTTOM_LEFT].x, rectangle->m_vertices[BOTTOM_LEFT].y, rectangle->m_vertices[BOTTOM_LEFT].z);
glEnd();
glPopMatrix();
}