PDA

View Full Version : moving rectangle



pbivens
10-29-2017, 04:13 PM
well I am able to rotate my rectangle but I want to move it up or down after I rotate it and have it follow the nose of the rectangles. I want to move my rectangles like asteroids.


void draw_tank_one()
{
glColor3f(1.0f, 0.0f, 0.0f);

glRectf(220.0f+move, 15.0f+up, 250.0f+move, 5.0f+up); //draw top block
glRectf(220.0f+move, -10.0f+up, 250.0f+move, -20.0f+up); //draw bottom block
glRectf(225.0f+move, 5.0f+up, 240.0f+move, -10.0f+up); //draw center block
glRectf(210.0f+move, 0.0f+up, 225.0f+move, -5.0f+up); //draw turret block
}

void draw_tank_two()
{
glColor3f(0.0f, 1.0f, 0.0f);

glRectf(-250.0f, 15.0f, -220.0f, 5.0f); //draw top block
glRectf(-250.0f, -10.0f, -220.0f, -20.0f); //draw bottom block
glRectf(-240.0f, 5.0f, -225.0f, -10.0f); //draw center block
glRectf(-225.0f, 0.0f, -210.0f, -5.0f); //draw turret block
}

///////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glPushMatrix();
glTranslatef(232.5f, 0.0f, 0.0f);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glTranslatef(-232.5f, 0.0f, 0.0f);
draw_tank_one();
glPopMatrix();

draw_tank_two();

// Flush drawing commands
glutSwapBuffers();
}