我想使用 openGL 为我的 3D 游戏实现雷达。我一直在尝试以多种方式完成它,但没有一个被批准是正确的。这是我的代码片段如下:
int xi, yi;
GLfloat x,z;
glPushMatrix();
{
glTranslatef(-0.8f, 0.2f, -3.0f);
glColor3f(0.0f, 0.0f, 1.0f);
x = playerTank->givePosX();
z = playerTank->givePosZ();
xi = (int)((x + 1000) / 20) + 5;
yi = (int)(((z + 1000) / 20) + screenHeight - 105);
glPushMatrix();
{
glScalef(xi,yi,1.0f);
glBegin(GL_QUADS);
glVertex2i(xi-5, yi-5);
glVertex2i(xi+5, yi-5);
glVertex2i(xi+5, yi+5);
glVertex2i(xi-5, yi+5);
glEnd();
}
glPopMatrix();
glColor3f(1.0f, 0.0f, 0.0f);
glPushMatrix();
{
glScalef(xi,yi,1.0f);
for (int i = 0; i < tanks.size(); i++)
{
x = tanks[i]->givePosX();
z = tanks[i]->givePosZ();
xi = (int)((x + 1000) / 20) + 5;
yi = (int)(((z + 1000) / 20) + screenHeight - 105);
if (xi > 0 && xi < 110 && yi > (screenHeight - 110) && yi < screenHeight)
{
if (tanks[i] != playerTank)
{
glBegin(GL_TRIANGLES);
glVertex2i(xi, yi-5);
glVertex2i(xi+5, yi+5);
glVertex2i(xi-5, yi+5);
glEnd();
}
}
}
}
glPopMatrix();
glColor3f(0.0f, 1.0f, 0.0f);
glPushMatrix();
{
glScalef(xi,yi,1.0f);
for (int i = 0; i < obstacles.size(); i++)
{
x = obstacles[i]->givePosX();
z = obstacles[i]->givePosZ();
xi = (int)((x + 1000) / 20) + 5;
yi = (int)(((z + 1000) / 20) + screenHeight - 105);
glBegin(GL_LINE_LOOP);
glVertex2i(xi-3, yi-3);
glVertex2i(xi+3, yi-3);
glVertex2i(xi+3, yi+3);
glVertex2i(xi-3, yi+3);
glEnd();
}
}
glPopMatrix();
}
glPopMatrix();
为什么屏幕上什么都没有出现?