Using C++ I want to run a piece of code that draws two tanks (represented as squares). The work asks us to do that using a for loop. I managed to get that to work but now the tanks are the same color. I want to use the if statement to check which tank it is and give it the correct color. I currently have the two tanks in a dynamic array called tankpointer. so my non working code looks like this:
void draw(game *mygame)
{
for (int i = 0; i < 2; i++)
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glMatrixMode(GL_MODELVIEW);
// draw player 1...
glVertexPointer(3, GL_FLOAT, 0, tankVertices);
glColorPointer(4, GL_FLOAT, 0, tank1VertexColors);
glLoadIdentity();
// replace the 0 and 1 of the dynamic array with i to get it to repeat:
glTranslatef(mygame->tankpointer[i].tankx, mygame->tankpointer[i].tanky, -5.0);
glRotatef(mygame->tankpointer[i].rotation, 0.0, 0.0, 1.0);
// 6 instead of the previous 3 to make a square:
glDrawArrays(GL_TRIANGLES, 0, 6);
if (tankpointer[0])
{
float tank1VertexColors[24] =
{
0.4f, 0.4f, 0.4f, 1.0f,
0.4f, 0.4f, 0.4f, 1.0f,
0.4f, 0.4f, 0.4f, 1.0f,
0.4f, 0.4f, 0.4f, 1.0f,
0.4f, 0.4f, 0.4f, 1.0f,
0.4f, 0.4f, 0.4f, 1.0f
};
}
else
{
float tank2VertexColors[24] =
{
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f,
0.8f, 0.8f, 0.8f, 1.0f
};
}
};
It says if (tankpointer[0]) is undefined. Any help/advice would be useful.
if (mygame->tankpointer[0])?tankpointerdefined? Did you meant the if statement to readif (mygame->tankpointer[0])?if (i == 0) { ... first tank ... } else { ... second tank ... }?