Now I'm very confused. In the first code you posted you have a function called draw_ship that has all the draw calls in it. There is nothing about this function in the most recent code that you posted.
In the recent code there are no Push and Pop function calls to isolate the matrix math. And in the draw_ship function you have all the draw calls together.
The following is how you would isolate model transformations and then move them around.
//-------------------------------------------------------------------------
To move ship_01 to the right you could do the following
if(keyPressed_right_arrow) //I'm using pseudo code here since I don't use GLUT and I'll confuse the issue if I write the syntax I use
{
ship_01_POSITION_X += 0.01f;
}
//-------------------------------------------------------------------------
To move ship_02 right you could do the following
if(keyPressed_D)
{
ship_02_POSITION_X += 0.01f;
}
//-------------------------------------------------------------------------
//==================================================================
glPushMatrix()
glTranslatef(ship_01_POSITION_X, ship_01_POSITION_Y, 0.0);
glRotatef(ship_01_ANGLE, 0.0f, 0.0f, 1.0f);
glColor3f(0.0f,1.0f,0.0f); glBegin(GL_LINE_LOOP); glVertex3f(-1.5f,-0.25f,0.0f); //if both ships are the same then they should also both have the same vertex info.
glVertex3f(-1.75f,-0.5f,0.0f); //Use glTranslatef to move the models to their respective positions glVertex3f(-2.0f,-0.5f,0.0f); glVertex3f(-1.5f,0.5f,0.0f); glVertex3f(-1.0f,-0.5f,0.0f); glVertex3f(-1.25f,-0.5f,0.0f); glVertex3f(-1.5f,-0.25f,0.0f); glEnd();
glPopMatrix()
//==================================================================
glPushMatrix()
glTranslatef(ship_02_POSITION_X, ship_02_POSITION_Y, 0.0);
glRotatef(ship_02_ANGLE, 0.0f, 0.0f, 1.0f);
glColor3f(0.0f, 1.0f, 0.0f); glBegin(GL_LINE_LOOP); glVertex3f(-1.5f,-0.25f,0.0f); glVertex3f(-1.75f,-0.5f,0.0f); glVertex3f(-2.0f,-0.5f,0.0f); glVertex3f(-1.5f,0.5f,0.0f); glVertex3f(-1.0f,-0.5f,0.0f); glVertex3f(-1.25f,-0.5f,0.0f); glVertex3f(-1.5f,-0.25f,0.0f); glEnd();
glPopMatrix()
//-------------------------------
Bullets should be outside of the ships' Push and Pop calls but started from the ships' position at the time they are fired.
//######################################################################################################################
If you wanted both models to move as a fleet but still have the ability to move them with respect to each other then you could do the following.
//=============================================================================================================
glPushMatrix(); //The purple Push and Pops isolate other model transformations that come after the fleet transforms but allow both ships to be moved as a group
glTranslatef(moveFleet_POSITION_X, moveFleet_POSITION_Y, 0.0);
glRotatef(fleet_ANGLE, 0.0f, 0.0f, 1.0f);
glPushMatrix();
glTranslatef(ship_01_POSITION_X, ship_01_POSITION_Y, 0.0);
glRotatef(ship_01_ANGLE, 0.0f, 0.0f, 1.0f);
glColor3f(0.0f,1.0f,0.0f); glBegin(GL_LINE_LOOP); glVertex3f(-1.5f,-0.25f,0.0f);
glVertex3f(-1.75f,-0.5f,0.0f); glVertex3f(-2.0f,-0.5f,0.0f); glVertex3f(-1.5f,0.5f,0.0f); glVertex3f(-1.0f,-0.5f,0.0f); glVertex3f(-1.25f,-0.5f,0.0f); glVertex3f(-1.5f,-0.25f,0.0f); glEnd();
glPopMatrix();
//==================================================
glPushMatrix();
glTranslatef(ship_02_POSITION_X, ship_02_POSITION_Y, 0.0);
glRotatef(ship_02_ANGLE, 0.0f, 0.0f, 1.0f);
glColor3f(0.0f, 1.0f, 0.0f); glBegin(GL_LINE_LOOP); glVertex3f(-1.5f,-0.25f,0.0f); glVertex3f(-1.75f,-0.5f,0.0f); glVertex3f(-2.0f,-0.5f,0.0f); glVertex3f(-1.5f,0.5f,0.0f); glVertex3f(-1.0f,-0.5f,0.0f); glVertex3f(-1.25f,-0.5f,0.0f); glVertex3f(-1.5f,-0.25f,0.0f); glEnd();
glPopMatrix();
glPopMatrix();
//=============================================================================================
Caution! treat glPushMatrix and glPopMatrix like awful bugs waiting to happen.
Always check and recheck that an equal number of Pops always follow the same number of Pushes. If you have 10 Pushes every frame, make sure you have 10 Pops every frame. If you miss this you will most certainly regret it when errors start to add up in consecutive frames.