- glEnd(); // GL_QUADS
-
- // draw lightning echos
- if( drawLightning ) {
- float col = 3 * symbolSize;
- float row = 4 * symbolSize;
- for(iradarEcho = radarEcho->begin() ; iradarEcho != radarEcho->end() ; iradarEcho++ ) {
- if( iradarEcho->lightning ) {
- float dist = iradarEcho->dist;
- dist = dist * range;
- float angle = (view_heading - iradarEcho->heading);
- if( angle > SG_PI )
- angle -= 2.0*SG_PI;
- if( angle < - SG_PI )
- angle += 2.0*SG_PI;
- angle = angle * fovFactor - SG_PI / 2.0;
- float x = cos( angle ) * dist;
- float y = sin( angle ) * dist;
- glColor3f(1.0f, 1.0f, 1.0f);
- float size = symbolSize * 0.5f;
- glBegin( GL_QUADS );
- glTexCoord2f( col, row);
- glVertex2f( x - size, y - size);
- glTexCoord2f( col+symbolSize, row);
- glVertex2f( x + size, y - size);
- glTexCoord2f( col+symbolSize, row+symbolSize);
- glVertex2f( x + size, y + size);
- glTexCoord2f( col, row+symbolSize);
- glVertex2f( x - size, y + size);
- glEnd();
- }
- }
+ } else {
+ // rose
+ }
+
+ _vertices->clear();
+ _texCoords->clear();
+ _textGeode->removeDrawables(0, _textGeode->getNumDrawables());
+
+
+ update_weather();
+
+
+ osg::DrawArrays *quadPSet
+ = static_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(0));
+ quadPSet->set(osg::PrimitiveSet::QUADS, 0, _vertices->size());
+ quadPSet->dirty();
+
+ // erase what is out of sight of antenna
+ /*
+ |\ /|
+ | \ / |
+ | \ / |
+ ---------
+ | |
+ | |
+ ---------
+ */
+
+ osg::DrawArrays *maskPSet
+ = static_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(1));
+ osg::DrawArrays *trimaskPSet
+ = static_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(2));
+
+ if (_display_mode == ARC) {
+ float xOffset = 256.0f;
+ float yOffset = 200.0f;
+
+ int firstQuadVert = _vertices->size();
+ _texCoords->push_back(osg::Vec2f(0.5f, 0.25f));
+ _vertices->push_back(osg::Vec2f(-xOffset, 0.0 + yOffset));
+ _texCoords->push_back(osg::Vec2f(1.0f, 0.25f));
+ _vertices->push_back(osg::Vec2f(xOffset, 0.0 + yOffset));
+ _texCoords->push_back(osg::Vec2f(1.0f, 0.5f));
+ _vertices->push_back(osg::Vec2f(xOffset, 256.0 + yOffset));
+ _texCoords->push_back(osg::Vec2f(0.5f, 0.5f));
+ _vertices->push_back(osg::Vec2f(-xOffset, 256.0 + yOffset));
+ maskPSet->set(osg::PrimitiveSet::QUADS, firstQuadVert, 4);
+
+ // The triangles aren't supposed to be textured, but there's
+ // no need to set up a different Geometry, switch modes,
+ // etc. I happen to know that there's a white pixel in the
+ // texture at 1.0, 0.0 :)
+ float centerY = tan(30 * SG_DEGREES_TO_RADIANS);
+ _vertices->push_back(osg::Vec2f(0.0, 0.0));
+ _vertices->push_back(osg::Vec2f(-256.0, 0.0));
+ _vertices->push_back(osg::Vec2f(-256.0, 256.0 * centerY));
+
+ _vertices->push_back(osg::Vec2f(0.0, 0.0));
+ _vertices->push_back(osg::Vec2f(256.0, 0.0));
+ _vertices->push_back(osg::Vec2f(256.0, 256.0 * centerY));
+
+ _vertices->push_back(osg::Vec2f(-256, 0.0));
+ _vertices->push_back(osg::Vec2f(256.0, 0.0));
+ _vertices->push_back(osg::Vec2f(-256.0, -256.0));
+
+ _vertices->push_back(osg::Vec2f(256, 0.0));
+ _vertices->push_back(osg::Vec2f(256.0, -256.0));
+ _vertices->push_back(osg::Vec2f(-256.0, -256.0));
+
+ const osg::Vec2f whiteSpot(1.0f, 0.0f);
+ for (int i = 0; i < 3 * 4; i++)
+ _texCoords->push_back(whiteSpot);
+
+ trimaskPSet->set(osg::PrimitiveSet::TRIANGLES, firstQuadVert + 4, 3 * 4);
+
+ } else {
+ maskPSet->set(osg::PrimitiveSet::QUADS, 0, 0);
+ trimaskPSet->set(osg::PrimitiveSet::TRIANGLES, 0, 0);
+ }
+
+ maskPSet->dirty();
+ trimaskPSet->dirty();
+
+ // draw without mask
+ _vertices->clear();
+ _texCoords->clear();
+
+ update_aircraft();
+ update_tacan();
+ update_heading_marker();
+
+ quadPSet->set(osg::PrimitiveSet::QUADS, 0, _vertices->size());
+ quadPSet->dirty();
+ }
+}
+
+
+void
+wxRadarBg::update_weather()
+{
+ string modeButton = _Instrument->getStringValue("mode", "wx");
+ _radarEchoBuffer = *sgEnviro.get_radar_echo();
+
+ // pretend we have a scan angle bigger then the FOV
+ // TODO:check real fov, enlarge if < nn, and do clipping if > mm
+ const float fovFactor = 1.45f;
+ _Instrument->setStringValue("status", modeButton.c_str());
+
+ list_of_SGWxRadarEcho *radarEcho = &_radarEchoBuffer;
+ list_of_SGWxRadarEcho::iterator iradarEcho, end = radarEcho->end();
+ const float LWClevel[] = { 0.1f, 0.5f, 2.1f };
+
+ // draw the cloud radar echo
+ bool drawClouds = _radar_weather_node->getBoolValue();
+ if (drawClouds) {
+
+ // we do that in 3 passes, one for each color level
+ // this is to 'merge' same colors together
+ for (int level = 0; level <= 2; level++) {
+ float col = level * UNIT;
+
+ for (iradarEcho = radarEcho->begin(); iradarEcho != end; ++iradarEcho) {
+ int cloudId = iradarEcho->cloudId;
+ bool upgrade = (cloudId >> 5) & 1;
+ float lwc = iradarEcho->LWC + (upgrade ? 1.0f : 0.0f);
+
+ // skip ns
+ if (iradarEcho->LWC >= 0.5 && iradarEcho->LWC <= 0.6)
+ continue;
+
+ if (iradarEcho->lightning || lwc < LWClevel[level])
+ continue;
+
+ float radius = sgSqrt(iradarEcho->dist) * SG_METER_TO_NM * _scale;
+ float size = iradarEcho->radius * 2.0 * SG_METER_TO_NM * _scale;
+
+ if (radius - size > 180)
+ continue;
+
+ float angle = (iradarEcho->heading - _angle_offset) //* fovFactor
+ + 0.5 * SG_PI;
+
+ // Rotate echo into position, and rotate echo to have
+ // a constant orientation towards the
+ // airplane. Compass headings increase in clockwise
+ // direction, while graphics rotations follow
+ // right-hand (counter-clockwise) rule.
+ const osg::Vec2f texBase(col, (UNIT * (float) (4 + (cloudId & 3))));
+
+ osg::Matrixf m(osg::Matrixf::scale(size, size, 1.0f)
+ * osg::Matrixf::translate(0.0f, radius, 0.0f)
+ * wxRotate(angle) * _centerTrans);
+ addQuad(_vertices, _texCoords, m, texBase);
+
+ //SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: drawing clouds"
+ // << " ID=" << cloudId
+ // << " x=" << x
+ // << " y="<< y
+ // << " radius=" << radius
+ // << " view_heading=" << _view_heading * SG_RADIANS_TO_DEGREES
+ // << " heading=" << iradarEcho->heading * SG_RADIANS_TO_DEGREES
+ // << " angle=" << angle * SG_RADIANS_TO_DEGREES);