void ScanBox::scan( double x, double y, double scale, int zoom, float box[] ) { m_nZoom = zoom; // this does not modify 'box' parameter box = transScale(x, y, scale, zoom, box); // clip result to min/max as steep angles // cause overshooting in x direction. float max = FLT_MIN; float min = FLT_MAX; for (int i = 0; i < 8; i += 2) { float xx = box[i]; if (xx > max) max = xx; if (xx < min) min = xx; } max = (float) ceil(max); min = (float) floor(min); if (min == max) max++; xmin = (int) min; xmax = (int) max; // top-left -> top-right ab.set(box[0], box[1], box[2], box[3]); // top-right -> bottom-right bc.set(box[2], box[3], box[4], box[5]); // bottom-right -> bottom-left ca.set(box[4], box[5], box[0], box[1]); scanTriangle(); // top-left -> bottom-right ab.set(box[0], box[1], box[4], box[5]); // bottom-right -> bottom-left bc.set(box[4], box[5], box[6], box[7]); // bottom-left -> top-left ca.set(box[6], box[7], box[0], box[1]); scanTriangle(); }
void RadarRenderer::makeList( SceneRenderer&) { // draw walls. walls are flat so a line will do. const std::vector<WallObstacle>& walls = world.getWalls(); int count = walls.size(); glColor3f(0.25f, 0.5f, 0.5f); glBegin(GL_LINES); int i; for (i = 0; i < count; i++) { const WallObstacle& wall = walls[i]; const float w = wall.getBreadth(); const float c = w * cosf(wall.getRotation()); const float s = w * sinf(wall.getRotation()); const float* pos = wall.getPosition(); glVertex2f(pos[0] - s, pos[1] + c); glVertex2f(pos[0] + s, pos[1] - c); } glEnd(); // draw box buildings. const std::vector<BoxBuilding>& boxes = world.getBoxes(); count = boxes.size(); glBegin(GL_QUADS); for (i = 0; i < count; i++) { const BoxBuilding& box = boxes[i]; if (box.isInvisible()) continue; const float cs = colorScale(box.getPosition()[2], box.getHeight(), BZDBCache::enhancedRadar); glColor4f(0.25f * cs, 0.5f * cs, 0.5f * cs, transScale(box)); const float c = cosf(box.getRotation()); const float s = sinf(box.getRotation()); const float wx = c * box.getWidth(), wy = s * box.getWidth(); const float hx = -s * box.getBreadth(), hy = c * box.getBreadth(); const float* pos = box.getPosition(); glVertex2f(pos[0] - wx - hx, pos[1] - wy - hy); glVertex2f(pos[0] + wx - hx, pos[1] + wy - hy); glVertex2f(pos[0] + wx + hx, pos[1] + wy + hy); glVertex2f(pos[0] - wx + hx, pos[1] - wy + hy); } glEnd(); // draw pyramid buildings const std::vector<PyramidBuilding>& pyramids = world.getPyramids(); count = pyramids.size(); glBegin(GL_QUADS); for (i = 0; i < count; i++) { const PyramidBuilding& pyr = pyramids[i]; const float cs = colorScale(pyr.getPosition()[2], pyr.getHeight(), BZDBCache::enhancedRadar); glColor4f(0.25f * cs, 0.5f * cs, 0.5f * cs, transScale(pyr)); const float c = cosf(pyr.getRotation()); const float s = sinf(pyr.getRotation()); const float wx = c * pyr.getWidth(), wy = s * pyr.getWidth(); const float hx = -s * pyr.getBreadth(), hy = c * pyr.getBreadth(); const float* pos = pyr.getPosition(); glVertex2f(pos[0] - wx - hx, pos[1] - wy - hy); glVertex2f(pos[0] + wx - hx, pos[1] + wy - hy); glVertex2f(pos[0] + wx + hx, pos[1] + wy + hy); glVertex2f(pos[0] - wx + hx, pos[1] - wy + hy); } glEnd(); // now draw antialiased outlines around the polygons count = boxes.size(); for (i = 0; i < count; i++) { const BoxBuilding& box = boxes[i]; if (box.isInvisible()) continue; const float cs = colorScale(box.getPosition()[2], box.getHeight(), BZDBCache::enhancedRadar); glColor4f(0.25f * cs, 0.5f * cs, 0.5f * cs, transScale(box)); const float c = cosf(box.getRotation()); const float s = sinf(box.getRotation()); const float wx = c * box.getWidth(), wy = s * box.getWidth(); const float hx = -s * box.getBreadth(), hy = c * box.getBreadth(); const float* pos = box.getPosition(); glBegin(GL_LINE_LOOP); glVertex2f(pos[0] - wx - hx, pos[1] - wy - hy); glVertex2f(pos[0] + wx - hx, pos[1] + wy - hy); glVertex2f(pos[0] + wx + hx, pos[1] + wy + hy); glVertex2f(pos[0] - wx + hx, pos[1] - wy + hy); glEnd(); } count = pyramids.size(); for (i = 0; i < count; i++) { const PyramidBuilding& pyr = pyramids[i]; const float cs = colorScale(pyr.getPosition()[2], pyr.getHeight(), BZDBCache::enhancedRadar); glColor4f(0.25f * cs, 0.5f * cs, 0.5f * cs, transScale(pyr)); const float c = cosf(pyr.getRotation()); const float s = sinf(pyr.getRotation()); const float wx = c * pyr.getWidth(), wy = s * pyr.getWidth(); const float hx = -s * pyr.getBreadth(), hy = c * pyr.getBreadth(); const float* pos = pyr.getPosition(); glBegin(GL_LINE_LOOP); glVertex2f(pos[0] - wx - hx, pos[1] - wy - hy); glVertex2f(pos[0] + wx - hx, pos[1] + wy - hy); glVertex2f(pos[0] + wx + hx, pos[1] + wy + hy); glVertex2f(pos[0] - wx + hx, pos[1] - wy + hy); glEnd(); } // draw team bases if(world.allowTeamFlags()) { for(i = 1; i < NumTeams; i++) { for (int j = 0;;j++) { const float *base = world.getBase(i, j); if (base == NULL) break; glColor3fv(Team::getRadarColor(TeamColor(i))); glBegin(GL_LINE_LOOP); const float beta = atan2f(base[5], base[4]); const float r = hypotf(base[4], base[5]); glVertex2f(base[0] + r * cosf(base[3] + beta), base[1] + r * sinf(base[3] + beta)); glVertex2f(base[0] + r * cosf(base[3] - beta + M_PI), base[1] + r * sinf(base[3] - beta + M_PI)); glVertex2f(base[0] + r * cosf(base[3] + beta + M_PI), base[1] + r * sinf(base[3] + beta + M_PI)); glVertex2f(base[0] + r * cosf(base[3] - beta), base[1] + r * sinf(base[3] - beta)); glEnd(); } } } // draw teleporters. teleporters are pretty thin so use lines // (which, if longer than a pixel, are guaranteed to draw something; // not so for a polygon). just in case the system doesn't correctly // filter the ends of line segments, we'll draw the line in each // direction (which degrades the antialiasing). Newport graphics // is one system that doesn't do correct filtering. const std::vector<Teleporter>& teleporters = world.getTeleporters(); count = teleporters.size(); glColor3f(1.0f, 1.0f, 0.25f); glBegin(GL_LINES); for (i = 0; i < count; i++) { const Teleporter& tele = teleporters[i]; const float cs = colorScale(tele.getPosition()[2], tele.getHeight(), BZDBCache::enhancedRadar); glColor4f(1.0f * cs, 1.0f * cs, 0.25f * cs, transScale(tele)); const float w = tele.getBreadth(); const float c = w * cosf(tele.getRotation()); const float s = w * sinf(tele.getRotation()); const float* pos = tele.getPosition(); glVertex2f(pos[0] - s, pos[1] + c); glVertex2f(pos[0] + s, pos[1] - c); glVertex2f(pos[0] + s, pos[1] - c); glVertex2f(pos[0] - s, pos[1] + c); } glEnd(); }