void RadarRenderer::render(SceneRenderer& renderer, bool blank) { const int ox = renderer.getWindow().getOriginX(); const int oy = renderer.getWindow().getOriginY(); float opacity = renderer.getPanelOpacity(); if ((opacity < 1.0f) && (opacity > 0.0f)) { glScissor(ox + x - 2, oy + y - 2, w + 4, h + 4); glColor4f(0.0f, 0.0f, 0.0f, opacity); glRectf((float) x, (float) y, (float)(x + w), (float)(y + h)); } glScissor(ox + x, oy + y, w, h); LocalPlayer *myTank = LocalPlayer::getMyTank(); if (opacity == 1.0f) { // glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // glClear(GL_COLOR_BUFFER_BIT); } if (blank) return; // prepare transforms float worldSize = BZDB.eval(StateDatabase::BZDB_WORLDSIZE); float range = BZDB.eval("displayRadarRange") * worldSize; // when burrowed, limit radar range if (myTank && (myTank->getFlag() == Flags::Burrow) && (myTank->getPosition()[2] < 0.0f)) { #ifdef _MSC_VER range = min(range, worldSize / 4.0f); #else range = std::min(range, worldSize / 4.0f); #endif } glMatrixMode(GL_PROJECTION); glLoadIdentity(); const int xSize = renderer.getWindow().getWidth(); const int ySize = renderer.getWindow().getHeight(); const double xCenter = double(x) + 0.5 * double(w); const double yCenter = double(y) + 0.5 * double(h); const double xUnit = 2.0 * range / double(w); const double yUnit = 2.0 * range / double(h); glOrtho(-xCenter * xUnit, (xSize - xCenter) * xUnit, -yCenter * yUnit, (ySize - yCenter) * yUnit, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); OpenGLGState::resetState(); TextureManager &tm = TextureManager::instance(); int noiseTexture = tm.getTextureID( "noise" ); // if jammed then draw white noise. occasionally draw a good frame. if (jammed && bzfrand() > decay) { glColor3f(1.0,1.0,1.0); if (noiseTexture >= 0 && renderer.useQuality() > 0) { const int sequences = 10; static float np[] = { 0, 0, 1, 1, 1, 1, 0, 0, 0.5f, 0.5f, 1.5f, 1.5f, 1.5f, 1.5f, 0.5f, 0.5f, 0.25f, 0.25f, 1.25f, 1.25f, 1.25f, 1.25f, 0.25f, 0.25f, 0, 0.5f, 1, 1.5f, 1, 1.5f, 0, 0.5f, 0.5f, 0, 1.5f, 1, 1.4f, 1, 0.5f, 0, 0.75f, 0.75f, 1.75f, 1.75f, 1.75f, 1.75f, 0.75f, 0.75f, }; int noisePattern = 4 * int(floor(sequences * bzfrand())); glEnable(GL_TEXTURE_2D); tm.bind(noiseTexture); glBegin(GL_QUADS); glTexCoord2f(np[noisePattern+0],np[noisePattern+1]); glVertex2f(-range,-range); glTexCoord2f(np[noisePattern+2],np[noisePattern+1]); glVertex2f( range,-range); glTexCoord2f(np[noisePattern+2],np[noisePattern+3]); glVertex2f( range, range); glTexCoord2f(np[noisePattern+0],np[noisePattern+3]); glVertex2f(-range, range); glEnd(); glDisable(GL_TEXTURE_2D); } else if (noiseTexture >= 0 && BZDBCache::texture && renderer.useQuality() == 0) { glEnable(GL_TEXTURE_2D); tm.bind(noiseTexture); glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex2f(-range,-range); glTexCoord2f(1,0); glVertex2f( range,-range); glTexCoord2f(1,1); glVertex2f( range, range); glTexCoord2f(0,1); glVertex2f(-range, range); glEnd(); glDisable(GL_TEXTURE_2D); } if (decay > 0.015f) decay *= 0.5f; } else if (myTank) // only draw if there's a local player { // if decay is sufficiently small then boost it so it's more // likely a jammed radar will get a few good frames closely // spaced in time. value of 1 guarantees at least two good // frames in a row. if (decay <= 0.015f) decay = 1.0f; else decay *= 0.5f; // get size of pixel in model space (assumes radar is square) ps = 2.0f * range / GLfloat(w); // relative to my tank const LocalPlayer* myTank = LocalPlayer::getMyTank(); const float* pos = myTank->getPosition(); float angle = myTank->getAngle(); // draw the view angle blewow stuff // view frustum edges glColor3f(1.0f, 0.625f, 0.125f); const float fovx = renderer.getViewFrustum().getFOVx(); const float viewWidth = range * tanf(0.5f * fovx); glBegin(GL_LINE_STRIP); glVertex2f(-viewWidth, range); glVertex2f(0.0f, 0.0f); glVertex2f(viewWidth, range); glEnd(); glPushMatrix(); glRotatef(90.0f - angle * 180.0f / M_PI, 0.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(-pos[0], -pos[1], 0.0f); // Redraw buildings makeList( renderer); // draw my shots int maxShots = world.getMaxShots(); int i; float muzzleHeight = BZDB.eval(StateDatabase::BZDB_MUZZLEHEIGHT); for (i = 0; i < maxShots; i++) { const ShotPath* shot = myTank->getShot(i); if (shot) { const float cs = colorScale(shot->getPosition()[2], muzzleHeight, BZDBCache::enhancedRadar); glColor3f(1.0f * cs, 1.0f * cs, 1.0f * cs); shot->radarRender(); } } //draw world weapon shots WorldPlayer *worldWeapons = World::getWorld()->getWorldWeapons(); maxShots = worldWeapons->getMaxShots(); for (i = 0; i < maxShots; i++) { const ShotPath* shot = worldWeapons->getShot(i); if (shot) { const float cs = colorScale(shot->getPosition()[2], muzzleHeight, BZDBCache::enhancedRadar); glColor3f(1.0f * cs, 1.0f * cs, 1.0f * cs); shot->radarRender(); } } // draw other tanks (and any flags on them) // note about flag drawing. each line segment is drawn twice // (once in each direction); this degrades the antialiasing // but on systems that don't do correct filtering of endpoints // not doing it makes (half) the endpoints jump wildly. const int curMaxPlayers = world.getCurMaxPlayers(); for (i = 0; i < curMaxPlayers; i++) { RemotePlayer* player = world.getPlayer(i); if (!player || !player->isAlive() || ((player->getFlag() == Flags::Stealth) && (myTank->getFlag() != Flags::Seer))) continue; GLfloat x = player->getPosition()[0]; GLfloat y = player->getPosition()[1]; GLfloat z = player->getPosition()[2]; if (player->getFlag() != Flags::Null) { glColor3fv(player->getFlag()->getColor()); drawFlagOnTank(x, y, z); } if (player->isPaused() || player->isNotResponding()) { const float dimfactor = 0.4f; const float *color = Team::getRadarColor(myTank->getFlag() == Flags::Colorblindness ? RogueTeam : player->getTeam()); float dimmedcolor[3]; dimmedcolor[0] = color[0] * dimfactor; dimmedcolor[1] = color[1] * dimfactor; dimmedcolor[2] = color[2] * dimfactor; glColor3fv(dimmedcolor); } else { glColor3fv(Team::getRadarColor(myTank->getFlag() == Flags::Colorblindness ? RogueTeam : player->getTeam())); } // If this tank is hunted flash it on the radar if (player->isHunted() && myTank->getFlag() != Flags::Colorblindness) { if (flashTank.isOn()) { if (!toggleTank) { float flashcolor[3]; flashcolor[0] = 0.0f; flashcolor[1] = 0.8f; flashcolor[2] = 0.9f; glColor3fv(flashcolor); } } else { toggleTank = !toggleTank; flashTank.setClock(0.2f); } } drawTank(x, y, z); } bool coloredShot = BZDB.isTrue("coloredradarshots"); // draw other tanks' shells maxShots = World::getWorld()->getMaxShots(); for (i = 0; i < curMaxPlayers; i++) { RemotePlayer* player = world.getPlayer(i); if (!player) continue; for (int j = 0; j < maxShots; j++) { const ShotPath* shot = player->getShot(j); if (shot && shot->getFlag() != Flags::InvisibleBullet) { const float *shotcolor; if (coloredShot) { if (myTank->getFlag() == Flags::Colorblindness) shotcolor = Team::getRadarColor(RogueTeam); else shotcolor = Team::getRadarColor(player->getTeam()); const float cs = colorScale(shot->getPosition()[2], muzzleHeight, BZDBCache::enhancedRadar); glColor3f(shotcolor[0] * cs, shotcolor[1] * cs, shotcolor[2] * cs); } else { glColor3f(1.0f, 1.0f, 1.0f); } shot->radarRender(); } } } // draw flags not on tanks. const int maxFlags = world.getMaxFlags(); const bool drawNormalFlags = BZDB.isTrue("displayRadarFlags"); for (i = 0; i < maxFlags; i++) { const Flag& flag = world.getFlag(i); // don't draw flags that don't exist or are on a tank if (flag.status == FlagNoExist || flag.status == FlagOnTank) continue; // don't draw normal flags if we aren't supposed to if (flag.type->flagTeam == NoTeam && !drawNormalFlags) continue; // Flags change color by height const float cs = colorScale(flag.position[2], muzzleHeight, BZDBCache::enhancedRadar); const float *flagcolor = flag.type->getColor(); glColor3f(flagcolor[0] * cs, flagcolor[1] * cs, flagcolor[2] * cs); drawFlag(flag.position[0], flag.position[1], flag.position[2]); } // draw antidote flag const float* antidotePos = LocalPlayer::getMyTank()->getAntidoteLocation(); if (antidotePos) { glColor3f(1.0f, 1.0f, 0.0f); drawFlag(antidotePos[0], antidotePos[1], antidotePos[2]); } // draw these markers above all others always centered glPopMatrix(); // north marker GLfloat ns = 0.05f * range, ny = 0.9f * range; glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_LINE_STRIP); glVertex2f(-ns, ny - ns); glVertex2f(-ns, ny + ns); glVertex2f(ns, ny - ns); glVertex2f(ns, ny + ns); glEnd(); // always up glPopMatrix(); // get size of pixel in model space (assumes radar is square) GLfloat ps = 2.0f * range / GLfloat(w); // forward tick glBegin(GL_LINES); glVertex2f(0.0f, range - ps); glVertex2f(0.0f, range - 4.0f * ps); glEnd(); // my tank glColor3f(1.0f, 1.0f, 1.0f); drawTank(0.0f, 0.0f, myTank->getPosition()[2]); // my flag if (myTank->getFlag() != Flags::Null) { glColor3fv(myTank->getFlag()->getColor()); drawFlagOnTank(0.0f, 0.0f, myTank->getPosition()[2]); } } // restore GL state glPopMatrix(); }